<commit_before># LRML Search

## Overview

LRML Search is a web application for storing, viewing and searching LegalRuleML documents, developed as part of the LegalRuleMLParl project. Under the hood, it is a PHP 7.0 Laravel web app which uses BaseX for XML storage and querying, and PostgreSQL for all other data storage.

## Authorship and copyright

LRML Search was written by [<NAME>](https://github.com/rst0git) and [<NAME>](https://github.com/hikari-no-yume). Copyright © 2017 University of Aberdeen.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

## User's guide

Documentation in Markdown format [can be found in `src/resources/help/usersguide.md`](src/resources/help/usersguide.md), and also within the app itself.

## Maintenance notes

This is a Laravel application. Therefore, its best practice should be adhered to in maintenance, e.g. database changes should have their own migrations.

If you are modifying `LRMLToHTMLConverter`, bear in mind that in production, it is only run once for each document at the point of upload, and then the HTML version is cached in the PostgreSQL database. Therefore, changes made to the converter will only affect existing documents if they are reuploaded. By contrast, in debug mode it is run every time a document is viewed, allowing for rapid iteration.

## Getting started
#### Install [Docker](https://docs.docker.com/engine/installation/)
- [Debian](https://docs.docker.com/v1.12/engine/installation/linux/debian/)
- [Ubuntu](https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-16-04#step-1-—-installing-docker)
- [Linux Mint](http://linuxbsdos.com/2016/12/13/how-to-install-docker-and-run-docker-containers-on-linux-mint-1818-1/)
- [Arch linux](https://wiki.archlinux.org/index.php/Docker#Installation)

#### Install [docker-compose](https://docs.docker.com/compose/install/)
- For Ubuntu
```sh
apt-get install -y docker-compose
```

- Using pip
```sh
pip install docker-compose
```
#### Install the php extensions: `php-zip`, `php-mbstring`, `php-xml`
- For Ubuntu
```sh
apt-get install -y php7.0 php7.0-zip php7.0-mbstring php7.0-xml
```

#### Copy `.env.example` to `.env`
```sh
cp ./src/.env.example ./src.env
```

#### Run `composer install`
```sh
cd ./src
curl -sS https://getcomposer.org/installer | php
php composer.phar install
```

#### Execute `run.sh`
```sh
./run.sh
```

#### Finally set file permissions and generate session key
```
chmod -R 755 src/
chmod -R o+w src/storage/
chmod -R o+w src/bootstrap/cache/
chmod -R o+w src/public/uploads/
docker-compose exec web bash -c "php artisan key:generate"
```

#### User account

By default (see `src/database/seeds/UsersTableSeeder.php`), a user account with the email address `user@localhost` and the password `<PASSWORD>` is created. With this account, you can log in and upload or delete documents, as well as create other user accounts.

For security reasons it is not a good idea to keep this initial account around; delete it or change its password. (Unfortunately, neither can be done directly through the interface right now.)

## File structure
<commit_msg>readme: Add note about SELinux<commit_after># LRML Search

## Overview

LRML Search is a web application for storing, viewing and searching LegalRuleML documents, developed as part of the LegalRuleMLParl project. Under the hood, it is a PHP 7.0 Laravel web app which uses BaseX for XML storage and querying, and PostgreSQL for all other data storage.

## Authorship and copyright

LRML Search was written by [<NAME>](https://github.com/rst0git) and [<NAME>](https://github.com/hikari-no-yume). Copyright © 2017 University of Aberdeen.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

## User's guide

Documentation in Markdown format [can be found in `src/resources/help/usersguide.md`](src/resources/help/usersguide.md), and also within the app itself.

## Maintenance notes

This is a Laravel application. Therefore, its best practice should be adhered to in maintenance, e.g. database changes should have their own migrations.

If you are modifying `LRMLToHTMLConverter`, bear in mind that in production, it is only run once for each document at the point of upload, and then the HTML version is cached in the PostgreSQL database. Therefore, changes made to the converter will only affect existing documents if they are reuploaded. By contrast, in debug mode it is run every time a document is viewed, allowing for rapid iteration.

## Getting started
#### Install [Docker](https://docs.docker.com/engine/installation/)
- [Debian](https://docs.docker.com/v1.12/engine/installation/linux/debian/)
- [Ubuntu](https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-16-04#step-1-—-installing-docker)
- [Linux Mint](http://linuxbsdos.com/2016/12/13/how-to-install-docker-and-run-docker-containers-on-linux-mint-1818-1/)
- [Arch linux](https://wiki.archlinux.org/index.php/Docker#Installation)

#### Install [docker-compose](https://docs.docker.com/compose/install/)
- For Ubuntu
```sh
apt-get install -y docker-compose
```

- Using pip
```sh
pip install docker-compose
```
#### Install the php extensions: `php-zip`, `php-mbstring`, `php-xml`
- For Ubuntu
```sh
apt-get install -y php7.0 php7.0-zip php7.0-mbstring php7.0-xml
```

#### Copy `.env.example` to `.env`
```sh
cp ./src/.env.example ./src.env
```

#### Run `composer install`
```sh
cd ./src
curl -sS https://getcomposer.org/installer | php
php composer.phar install
```

#### Execute `run.sh`
```sh
./run.sh
```

#### Finally set file permissions and generate session key
```
chmod -R 755 src/
chmod -R o+w src/storage/
chmod -R o+w src/bootstrap/cache/
chmod -R o+w src/public/uploads/
docker-compose exec web bash -c "php artisan key:generate"
```

#### Enabled SELinux

If SELinux is enabled the security context of the `src` directory needs to be set accordingly.

```
chcon -Rt svirt_sandbox_file_t ./src
```

#### User account

By default (see `src/database/seeds/UsersTableSeeder.php`), a user account with the email address `user@localhost` and the password `<PASSWORD>` is created. With this account, you can log in and upload or delete documents, as well as create other user accounts.

For security reasons it is not a good idea to keep this initial account around; delete it or change its password. (Unfortunately, neither can be done directly through the interface right now.)

## File structure

{'fraction_non_alphanumeric': 0.10730743910467412, 'fraction_numerical': 0.01053324555628703, 'mean_word_length': 4.353065539112051, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 16, 'lorem ipsum': 0, 'www.': 4, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '390104', 'n_tokens_mistral': 2372, 'n_tokens_neox': 2175, 'n_words': 928}