Shared constraints - adamb924/mortal-engine GitHub Wiki

Because languages tend to re-use the same patterns, it is helpful to be able to reuse constraints.

The basis for this example is examples/12-Phonological-Allomorphy.xml, described here. This is a language where a prefix agrees in ATR with the stem: e.g., [e-sit], but [ɛ-sɪn]. That example was created with <phonological-condition> tags in each allomorph.

Because that same phonological condition comes up a lot, it's useful to have it at just one place in the code, and then refer to it as needed. We do this with the <shared-conditions> tag.

The complete example is in examples/13-Shared-Conditions.xml. Toward the top of the file, we have the <shared-conditions> tag. It has a list of constraints. Each constraint has the id attribute (e.g., id="atr-harmony"), which gives the constraint a name. The id attribute is required in this context.

<shared-conditions>
   <phonological-condition type="following" id="atr-harmony">
      <match-expression lang="wk-LA">.*[ieo]</match-expression>
   </phonological-condition>
   <phonological-condition type="following" id="non-atr-harmony">
      <match-expression lang="wk-LA">.*[ɪɛɔ]</match-expression>
   </phonological-condition>
</shared-conditions>

Further down the file, when we want to add a constraint, we do it with a tag like <condition id="atr-harmony" />. The atr-harmony constraint that we defined in <shared-conditions> will be inserted.

<morpheme label="Classifier">
   <allomorph>
      <condition id="atr-harmony" />
      <form lang="wk-LA">e</form>
   </allomorph>
   <allomorph>
      <condition id="non-atr-harmony" />
      <form lang="wk-LA">ɛ</form>
   </allomorph>
</morpheme>

The advantage is clear. The same condition can be used as many times as you want in the file. (In this example, it's used in the “Plural” morpheme as well.) This makes your files shorter and easier to read. If you need to update a constraint, you only have to do it in one place.

If you want to use a constraint more than once, you must put it in the <shared-conditions> element up top. If you add an id attribute to any other constraint, it won't do anything. If you try to refer to a constraint with a <conditition> tag with an id that you haven't defined in <shared-conditions>, it will print an error to the log.

⚠️ **GitHub.com Fallback** ⚠️