# Choppr user manual

## Introduction

Choppr is a tool that helps to convert a document into a representation of the document in RDF. This representation includes all original content, but is enhanced with information about the structure of the document. Such a representation is referred to as a _decomposition_.

For example: a document might, on the highest level, consist of chapters, which in turn consist of articles, which in turn consist of sentences.

The output of Choppr follows the [Source of Norms Ontology](https://gitlab.com/normativesystems/knowledge-modeling/source-ontology). The intended use of this ontology is to refer to sources within normative interpretations made in [Flint](https://gitlab.com/normativesystems/knowledge-modeling/flint-ontology).


## Installation

Choppr can be run in the browser by navigating to [choppr.dev](http://choppr.dev). (There is also choppr.app, but this version is outdated and is currently not recommended for use).

Alternatively, the newest version of Choppr can be run locally by cloning the [Gitlab repository](https://gitlab.com/normativesystems/choppr/choppr-standalone) and opening index.html in a browser. This version might be less stable and not all features might be available (especially the connection to the triple store).

## Interface overview

The interface of Choppr consists of seven horizontal panes:

1. Choppr
2. Import
3. Tree
4. Source
5. Recipe
6. Separators
7. Export

A pane can be expanded or collapsed by clicking its title bar. The size can be changed by clicking and dragging the bar.

## Importing a new document

A new document can be imported in two ways.

### Import local assets

A new document can be imported by clicking __Select local assets__ in the __Import__ pane. Supported formats are:
* txt
* xml
* html

It is currently advised to use __txt__, as support for html and xml is still limited. A flat text version of any Dutch law can be downloaded from [wetten.nl](https://wetten.nl) by clicking the download button on the top right and selecting _TXT_ as the output format.

After selecting the file, click __Import assets__ to continue importing the document. You are then taken to the next pane.

### Import by web address

It will also be possible to import a document directly from the web. This functionality is still under development.

Existing documents can also be loaded from the triple store. See [Loading a decomposition](#loading-a-decomposition).


## Decomposing a document

The decomposition of the document takes place in the Tree, Source, Recipe and Separator panes. These panes automatically open when a document has been imported.

### 1. Selecting preprocessors

Start by selecting which preprocessors you want to apply to your document. Preprocessors help split your document into chunks that can then be further decomposed using custom separators. Default preprocessors are:

* Chunks: splits the document into chunks on line breaks (this is recommended)
* Paragraph chunks: splits the document into chunks on double line breaks
* Tabbed elements: created chunks where tabs occur
* Sentence chunks: splits the document into chunks whenever a period ('.') occurs. This often produces undesirable results (periods also occur in abbreviations, decimal points and lists).
* Empty lines: removes empty lines (this is recommended)

### 2. Creating separators

The next step is creating separators, one for each of the types of structural elements that you would like to recognize (e.g. chapters, articles, paragraphs, list items).

In the separator pane, click the _+_-icon to create a new separator. Fill in the following fields (the example described here creates a separator for articles in Dutch law texts).

| Field  |  Explanation | Example |
| ---| ---| ---|
| Separator Name | Internal name for your separator, shown only in Choppr | Articles |
| Description | Description of your separator, shown only in Choppr | |
| Tags | Tags for your separator, shown only in Choppr | |
| Separator Type | Select _Chunk identifier_ if you want to identify headings that start a new block. Select _Splitter_ if you want to split a chunk in two parts by this separator. Select _CSS Selector_ if you want to enrich your chunk identifier with a CSS selector (this feature is not fully operational yet) | Chunk identifier |
| Expression | The regular expression is used to specify a match pattern in the text. To learn how to write regular expressions, see for example [RegexOne](https://regexone.com/). | `^Artikel (\d+)\. (.*)` |
| Representation | This determines whether or not an element is shown as an indented list item. Select ListItem for members of bullet lists or enumerators, Default otherwise  | Default |
| Type | The name of the type of element you want to recognize. | Article |
| Numbering | The capture group that contains the number of the element you want to identify. Leave this empty if no numbering is present. | `$1` |
| Title |  The capture group that contains the title of the element you want to identify. Leave this empty if no title is present. | `$2` |

The example separator above turns a block of text that starts with _Artikel 19. Voorwaarden_ into an element of type _Article_ with number _19_ and title _Voorwaarden_ (but note that the regular expression would have to be revised to also recognize _Artikel 19a. Kostendelende medebewoner_).

### 3. Creating a recipe

Separators only take effect if they are used in a recipe. A recipe encodes the order and hierarchy in which separators are applied. This order and and hierarchy affect the hierarchy of the elements in the doucment. For example: the [Participation act](https://wetten.overheid.nl/BWBR0015703/2024-07-01) consists of chapters (hoofdstukken), which in turn consist of sections (paragrafen), which in turn consist of articles (artikelen).

This hierarchy can be represented as follows in Choppr:

1. First, add a Chapter separator to the recipe, by double clicking the separator.
2. Then, the Section separator can be added by dragging it into the Chapter separator in the recipe.
3. After that, drag the Article separator into the Section separator in the recipe.

This results in a one-step recipe with the hierarchy:

* Chapter
  * Article
    * Section

This recipe creates a tree structure in the document that is visually represented in the Tree pane as well as the Source pane. In this way, the recipe can be adapted until the tree structure is correct. Separators can be removed from a recipe by dragging them out of the pane.

### 4. Manual splitting and grouping

Some elements will be hard to recognize using automated separators. For these elements, manual actions might be needed. Manual actions become part of the recipe. They can be undone by removing them from the recipe.

#### Split

Click the ✂-icon to activate the Split tool. Once activated, clicking on the document will split the element at the click position. Deactivate the split tool by clicking the 🠝-icon.

#### Group

Elements can also be grouped or ungrouped

Click the 🠝-icon to activate the Select tool and click on one or more elements to select them (selected elements are highlighted in green).

Pressing the group button groups elemenents into a new element of type Group. Pressing the ungroup button replaces an element by its subelements.

#### Edit type and labels

Select an element and click the 🪪-icon to edit its information such as Type, Numbering and Title.

#### Remove an element

An element can be removed by selecting it and clicking the 🗑-icon.

### 5. Adding or updating document metadata

The last decomposition step consists of adding or updating the document metadata. Click on the Export pane to open it and click _Edit_ to open the metadata window.

The following metadata can be added:

| Field  |  Explanation | Example |
| ---| ---| ---|
| title | Titel van de bron | Participatiewet |
| hasOrigin | URI van de oorspronkelijke bron | https://wetten.overheid.nl/BWBR0015703/2024-01-01 |
| version | Versie van de bron | 01-01-2024 |
| authoredBy | De auteur van de bron | Minister van SZW |
| editedBy | De maker van de decompositie | Robert van Doesburg |
| decompositionVersion | Versie van de decompositie | 2.0 |
| applicableAt | Plaats waar de bron geldt | Nederland |
| applicableFrom | Datum waarop de bron geldig wordt | 01-01-2024 |
| applicableUntil | Datum tot wanneer de bron geldig is | 30-06-2024 |


## Saving a decomposition

A decomposition can be saved to your computer as a file or in the triple store.

To save as a file, click the 💾-icon in the Export pane. The file is saved in [JSON-LD](https://en.wikipedia.org/wiki/JSON-LD) format. It can be loaded in the [Interpretation Editor](https://norm-editor.netlify.app/) for further analysis.

To save in the triple store, click the _API_-button in the Export pane to save.

## Loading a decomposition

An existing decomposition can be loaded back into Choppr in order to make changes. In the Import pane, you can either load a JSON-LD file from your computer (tab _Local assets_) or load a decomposition that was saved to the triple store (tab _Remote assets_).

Once a decomposition has been selected, you can choose which parts you would like to load: the source, separators and/or the recipe.

If you would like to decompose a new document using an existing recipe and separators, you can load a txt-file with your new document along with an existing decomposition, and deselect the Source checkbox before continuing.

## Feature requests and bug reports

Would you like to report a bug or request a new feature? Please open an issue on in the [Choppr repository](https://gitlab.com/normativesystems/choppr/choppr-standalone/-/issues/) on GitLab.