<commit_before># Defining Link Specifications

Links Specifications (LS) can be simple or complex.
A simple LS just consists of the measure name together with the arguments to the measure.
Possible arguments to a measure are all properties as defined in [Data Sources](index.md#data-sources).
A possible simple LS is shown in the following example:
```xml
<METRIC>trigrams(x.rdfs:label,y.dc:title)</METRIC>
```
While such simple metrics can be used in many cases, complex metrics are
necessary in complex linking cases.
LIMES includes a formal grammar for specifying complex configurations of
arbitrary complexity.
For this purpose, two categories of binary operations are supported:
../docs/user_manual/configuration_file/defining_link_specifications.md
1. Metric operations and
2. Boolean operations.

## Metric operations

Metric operations allow to combine metric values. They include the operators
`MIN`, `MAX` and `ADD` e.g. as follows:

```
MAX(trigrams(x.rdfs:label,y.dc:title)|0.3,euclidean(x.lat|long, y.latitude|longitude)|0.5).
```

This specification computes the maximum of:

1. The trigram similarity of x's `rdfs:label` and y's `dc:title` is greater or equal to 0.3

2. The 2-dimension Euclidean distance of `x`'s `lat` and `long` with `y`'s `latitude` and `longitude`, i.e.,  $$ \sqrt{((x.lat- y.latitude)^2 + (x.long - y.longitude)^2)} $$ is greater or equal to 0.5.


Note that euclidean supports arbitrarily many dimensions. In addition, note that `ADD` allows to define weighted sums as follows:`ADD(0.3*trigrams(x.rdfs:label,y.dc:title)|0.3, 0.7*euclidean(x.lat|x.long,y.latitude|y.longitude)|0.5)`.

We call `trigrams(x.rdfs:label,y.dc:title)|0.3` the left child of the specification and `euclidean(x.lat|long, y.latitude|longitude)|0.5` the right child of the specification. Both children specifications are simple specifications and combined with a metric operator, they create a complex specification. LIMES gives the user the opportunity to combine **exactly two** complex or simple specifications to create a new complex specification. Note that each child specification must be accompanied by its own threshold.

## Boolean operations

Boolean operations allow to combine and filter the results of metric operations and include `AND`, `OR`, `MINUS`, e.g. as `AND(trigrams(x.rdfs:label,y.dc:title)|0.9, euclidean(x.lat|x.long, y.latitude|y.longitude)|0.7)`.<commit_msg>Update defining_link_specifications.md<commit_after># Defining Link Specifications

Links Specifications (LS) can be simple or complex.
A simple LS just consists of the measure name together with the arguments to the measure.
Possible arguments to a measure are all properties as defined in [Data Sources](index.md#data-sources).
A possible simple LS is shown in the following example:
```xml
<METRIC>trigrams(x.rdfs:label,y.dc:title)</METRIC>
```
While such simple metrics can be used in many cases, complex metrics are
necessary in complex linking cases.
LIMES includes a formal grammar for specifying complex configurations of
arbitrary complexity.
For this purpose, two categories of binary operations are supported:
../docs/user_manual/configuration_file/defining_link_specifications.md
1. Metric operations and
2. Boolean operations.

## Metric operations

Metric operations allow to combine metric values. They include the operators
`MIN`, `MAX`, `MINUS` and `ADD` as follows:

* `MIN(m1, m2)` Computes the *intersection* of the two mappings `m1` and `m2`. In case a link `l` exists in both mappings `m1` and `m2` the `l` with the minimal similarity is taken. In other words, the result of `MIN(m1, m2)` would be all the entries (i.e., links) with *minimum* similarities in both `m1` and `m2`, where nonexisting entries in both `m1` and `m2` are assumed to have a similarity of `0`. For instance, if a link `l` exists *only* in `m1`, then we assume that `m2` contains the same link '`l` with a similarity of `0`. Therefore, the `MIN` will not return `l` as it would have the minimum similarity of `0`. 

* `MAX(m1, m2)` Computes the *union* of the two mappings `m1` and `m2`. In case a link `l` exists in both mappings `m1` and `m2` the `l` with the maximal similarity is taken. In other words, the result of `MAX(m1, m2)` would be all the entries (i.e., links) with *maximum* similarities in both `m1` and `m2`, where nonexisting entries in both `m1` and `m2` are assumed to have a similarity of `0`. For instance, if a link `l` exists *only* in `m1`, then we assume that `m2` contains the same link `l` with a similarity of `0`. Therefore, the `MAX` will always return `l` from `m1` as it would have the maximum similarity. 

* `MINUS(m1, m2)` Computes the *difference* of two mappings. i.e. the set difference `m1 - m2`. In other words, `MINUS` will only return links from `m1` with their respective similarities, only in case such links do not exist in `m2`. 

* `ADD` allows to define weighted sums as follows:`ADD(0.3*trigrams(x.rdfs:label,y.dc:title)|0.3, 0.7*euclidean(x.lat|x.long,y.latitude|y.longitude)|0.5)`.

#### Link specification with metric operations example:

```
MAX(trigrams(x.rdfs:label,y.dc:title)|0.3,euclidean(x.lat|long, y.latitude|longitude)|0.5).
```

This specification computes the maximum of:

1. The *trigram similarity* of x's `rdfs:label` and y's `dc:title` is greater or equal to 0.3

2. The 2-dimension *Euclidean distance* of `x`'s `lat` and `long` with `y`'s `latitude` and `longitude`, i.e.,  $$ \sqrt{((x.lat- y.latitude)^2 + (x.long - y.longitude)^2)} $$ is greater or equal to 0.5. Note that euclidean supports arbitrarily many dimensions. 

We call `trigrams(x.rdfs:label,y.dc:title)|0.3` the left child of the specification and `euclidean(x.lat|long, y.latitude|longitude)|0.5` the right child of the specification. Both children specifications are simple specifications and combined with a metric operator, they create a complex specification. LIMES gives the user the opportunity to combine **exactly two** complex or simple specifications to create a new complex specification. Note that each child specification must be accompanied by its own threshold.

## Boolean operations

Boolean operations allow to combine and filter the results of metric operations and include `AND`, `OR`, `MINUS`, e.g. as `AND(trigrams(x.rdfs:label,y.dc:title)|0.9, euclidean(x.lat|x.long, y.latitude|y.longitude)|0.7)`.
{'fraction_non_alphanumeric': 0.10677165354330709, 'fraction_numerical': 0.016062992125984252, 'mean_word_length': 4.991509433962264, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '1219061', 'n_tokens_mistral': 2028, 'n_tokens_neox': 1880, 'n_words': 828}