# Tricoteuses Tisseuse

_Find links in/to French legislative documents_

_Tricoteuses Tisseuse_ is free and open source software.

- [software repository](https://git.tricoteuses.fr/logiciels/tricoteuses-juridique/src/branch/main/packages/tisseuse)
- [GNU Affero General Public License version 3 or greater](https://git.tricoteuses.fr/logiciels/tricoteuses-juridique/src/branch/main/packages/tisseuse/LICENSE.md)

_Tricoteuses Tisseuse_ started from a full rewrite of [Metslesliens](https://www.npmjs.com/package/metslesliens) by Seb35, published under the "DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE" (WTFPL) version 2.

## Installation

### Create database

Using Debian GNU/Linux, install PostgreSQL, then:

```sh
sudo su - postgres
createuser tisseuse -P # and enter the password
createdb -O tisseuse tisseuse
psql tisseuse
  CREATE EXTENSION IF NOT EXISTS pg_trgm;
\q
exit
```

### Install dependencies

```sh
npm install
```

## Server Configuration

Create a `.env` file to set configuration variables (you can use `example.env` as a template). Then:

```sh
npm run configure
```

## Legal reference resolver

Tisseuse resolves legal references through a `LegiResolver`. The default
resolver is `canutes`, which uses the configured Canutes database and a generated
`text_titles_infos.json` file.

There are two supported resolver paths for tests and scripts:

- `f_legi`: uses the flat f_legi database and does not need a generated
  `text_titles_infos.json` file.
- `canutes`: uses the Canutes database and requires generating
  `src/lib/text_parsers/text_titles_infos.json` before running tests that parse
  or resolve French text titles.

Use `f_legi` explicitly when you want to run against the flat f_legi database:

```sh
TISSEUSE_LEGI_RESOLVER=f_legi npm test
npx tsx src/scripts/parse_assemblee_bill_raw.ts bill.html.raw --resolver f_legi
```

For the default Canutes resolver, generate the text title index first, then run
the tests:

```sh
npx tsx src/scripts/extract_texts_titles_infos.ts
npm test
```

This creates `src/lib/text_parsers/text_titles_infos.json`. It is generated from
the Canutes database, is listed in `.gitignore`, and must never be committed.

If you need to keep the generated file outside the working tree, pass it through
`TISSEUSE_TEXT_TITLES_INFOS_PATH` or script options instead:

```sh
TISSEUSE_TEXT_TITLES_INFOS_PATH=/path/to/text_titles_infos.json npm test
npx tsx src/scripts/parse_akoma_ntoso_bill_raw.ts bill.akn.xml.raw --text-titles-infos /path/to/text_titles_infos.json
```

If no path is supplied, the Canutes resolver first tries
`src/lib/text_parsers/text_titles_infos.json` from the current working tree, then
the same generated file in the local tisseuse package source tree. That file is
generated data and is not loaded through Vitest global setup; tests that need it
preload it explicitly through the selected resolver.
