repeat
- Last Updated: May 13, 2026
- 4 minute read
- Semaphore
- Documentation
The repeat rule allows a particular section of the template to be repeated for any label that matches the Term Types, Word Types, and Behaviour Types attributes set on the repeat rule.
The repeat rule is generally used either as a sub-block within a grouping rule (e.g. <any>, <max>, etc.), or containing a grouping rule. This is to ensure each label is in a separate sub-block, and not all labels in the same sub-block. The example below shows a common case where a repeat is used with a max block to prevent over-firing. It is most commonly used to create rule blocks containing Alt Labels and their sub-types, where there can be multiple labels, as opposed the Pref Labels where there is only one label (per language).
If the repeat rule does not have Term Types, Word Types, or Behaviour Types specified, then all Term Types, Word Types, and Behaviour Types are assumed.
Inheritance of labeltypes, wordtypes, and behaviourtypes to Child Rules
If the child rules do not have Term Types, Word Types, or Behaviour Types attributes on them, they will inherit the Word Types, Term Types, and Behaviour Types from the repeat rule.
The child rules can also have Term Types, Word Types, and Behaviour Types attributes on them, however, their effect is different.
The Term Types and Behaviour Types set on a child rule will be used if there is no Term Types or Behaviour Types set on the repeat rule. However, if there is a Term Types or Behaviour Types set on the repeat rule, it will override the Term Types and Behaviour Types set on the child rule.
The Word Types set on a child rule is evaluated as a union with the Word Typesset on the repeat rule. This means if the Word Types on the child rule is a sub-type of that set on the repeat, or the repeat has no Word Types set, then just the Word Types set on the child rule is used. And, if the Word Types set on the child rule is not the same or a sub-type of that set on the repeat rule, the child rule will not be generated at all.
Attributes
The repeat rule allows the following template specific attributes:
Example 1
For a model that contains the concept ‘Drug Trafficking’ with alternative labels ‘Drug Barons’, ‘Drug Lords’ (set to ‘Treat as exact phrase only’), ‘Dealer’, ‘LSD’, ‘THC’ these labels would get assigned the following labeltypes and wordtypes:
| label | labeltypes | wordtypes |
|---|---|---|
| Drug Trafficking | prefLabel | MULTIWORD |
| Drug Barons | alternative label, altLabel | MULTIWORD |
| Drug Lords [Treat as exact phrase only] | alternative label, altLabel | MULTIWORD |
| Dealer | alternative label, altLabel | NOUN |
| LSD | alternative label, altLabel | ACRONYM |
| THC | alternative label, altLabel | ACRONYM |
Using the following template rule:
<repeat wordtypes="MULTIWORD" labeltypes="prefLabel|altLabel">
<max>
<phraselist case="0" stem="1" weight="15" wordtypes="PHRASE"/>
<nearlist case="0" count="2" stem="1" weight="5"/>
<sentencelist case="0" stem="1" weight="3"/>
</max>
</repeat>
Note the wordtypes on the <phraselist> rule is a sub-type of that set on the repeat rule, which acts as a further filter.
The following output would be generated:
<max>
<phrase data="Drug Trafficking" case="0" stem="1" weight="15"/>
<near data="Drug Trafficking" case="0" count="2" stem="1" weight="5"/>
<sentence data="Drug Trafficking" case="0" stem="1" weight="3"/>
</max>
<max>
<phrase data="Drug Barons" case="0" stem="1" weight="15"/>
<near data="Drug Barons" case="0" count="2" stem="1" weight="5"/>
<sentence data="Drug Barons" case="0" stem="1" weight="3"/>
</max>
<max>
<phrase data="Drug Lords" case="0" stem="1" weight="15"/>
<near data="Drug Lords" case="0" count="2" stem="1" weight="5"/>
<sentence data="Drug Lords" case="0" stem="1" weight="3"/>
</max>
If, however, the repeat was not used (and the wordtypes and labeltypes were moved to the child rules):
<max>
<phraselist wordtypes="PHRASE" labeltypes="prefLabel|altLabel" case="0" stem="1" weight="15"/>
<nearlist wordtypes="MULTIWORD" labeltypes="prefLabel|altLabel" case="0" count="2" stem="1" weight="5"/>
<sentencelist wordtypes="MULTIWORD" labeltypes="prefLabel|altLabel" case="0" stem="1" weight="3"/>
</max>
Then a completely different set of rules are generated, where all qualifying labels are put into a single <max> block:
<max>
<phrase data="Drug Trafficking" case="0" stem="1" weight="15"/>
<phrase data="Drug Barons" case="0" stem="1" weight="15"/>
<phrase data="Drug Lords" case="0" stem="1" weight="15"/>
<near data="Drug Trafficking" case="0" count="2" stem="1" weight="5"/>
<near data="Drug Barons" case="0" count="2" stem="1" weight="5"/>
<phrase data="Drug Lords" case="0" stem="1" weight="5"/>
<sentence data="Drug Trafficking" case="0" stem="1" weight="3"/>
<sentence data="Drug Barons" case="0" stem="1" weight="3"/>
<phrase data="Drug Lords" case="0" stem="1" weight="3"/>
</max>
Example 2 A problem with the rule in Example 1 is that for the label ‘Drug Lords’, which is set to “Treat as exact phrase only”, a near and a sentence rule is generated, which is not desirable for a “Treat as exact phrase only” label.
The near and sentence rules can be eliminated for ‘Drug Lords’ by adding to those rules: behaviourtypes=“^Treat as exact phrase only”.
<repeat wordtypes="MULTIWORD" labeltypes="prefLabel|altLabel">
<max>
<phraselist case="0" stem="1" weight="15" wordtypes="PHRASE"/>
<nearlist behaviourtypes="^Treat as exact phrase only" case="0" count="2" stem="1" weight="5"/>
<sentencelist behaviourtypes="^Treat as exact phrase only" case="0" stem="1" weight="3"/>
</max>
</repeat>
Which generates the following output:
<max>
<phrase data="Drug Trafficking" case="0" stem="1" weight="15"/>
<near data="Drug Trafficking" case="0" count="2" stem="1" weight="5"/>
<sentence data="Drug Trafficking" case="0" stem="1" weight="3"/>
</max>
<max>
<phrase data="Drug Barons" case="0" stem="1" weight="15"/>
<near data="Drug Barons" case="0" count="2" stem="1" weight="5"/>
<sentence data="Drug Barons" case="0" stem="1" weight="3"/>
</max>
<max>
<phrase data="Drug Lords" case="0" stem="1" weight="15"/>
</max>
Note that only the phrase rule is generated for ‘Drug Lords’.
The attribute: behaviourtypes=“^Treat as exact phrase only”, could be added to the repeat rule itself, but then no rules, including the desired phrase rule, would be generated for ‘Drug Lords’.