Pattern segment labels

You can assign a label to any segment of a matching pattern. The label can then be used to identify links that were matched - you can then refer to them and access their features - both in subsequent elements of the matching pattern and in output phrases.

The syntax is:

segment_of_matching_pattern = $label

Where segment_of_matching_pattern is any portion of the matching pattern used for matching and label is an arbitrary name for the segment.

You can only label a segment containing links, it is not possible to label a matching node by itself.

Nesting pattern segment labels

Pattern segment labels can be nested and used in output phrases, as in this example:

Token = $first
(Token.punctuation.period = $second
Token = $third) = $second_third
>$first = First
>$second = Second<value=$first.text()>
>$third = Third
>$second_third = Second_third

Using labels to achieve context dependency

By default, link is created over the entire text snippet that is matched to the matching pattern. You can use labels to create links over one or more segments of the matching pattern.

The syntax for the output phrase is:

1
>$label = new_link_name<feature1=value1, feature2=value2...>

Here's an example where "world!" is only detected when it is directly proceeded with "hello,":

>$label = new_link_name<feature1=value1, feature2=value2...>Token<text()="hello">
Token.punctuation.comma
(
Token<text()="world">
Token.punctuation.exclamation
) =$world_with_punctuation
> $world_with_punctuation = exercise:Exclamation

 

fontfontfont