Jape file to find the pattern within a sentence

回眸只為那壹抹淺笑 提交于 2019-12-01 09:12:12

In such cases you cannot use Contextual Operators like {X within Y} because they work for a single annotation only, not for a sequence of annotations.

But you can use a "trick":

  1. Include Sentence annotations in the Input.
    This does the main thing. Even if you do not use Sentence anywhere in the rule, it prevents such matches where a new sentence starts somewhere between the annotations.
    But it does not prevent matches where a sentence starts at the same point as the annotation itself.

  2. Prohibit any sentence to start at the same point as the second annotation using the ! operator: {Lookup, !Sentence}.

Phase: secondpass 
Input: Lookup Sentence 
Options: control = brill

Rule: A3b 
(
    {Lookup.majorType == "trouble"}
    {Lookup.majorType == "alteration", !Sentence}
):label 
--> :label.A3b = {rule= "A3b"}

As well as the Sentence annotations covering the sentences themselves, the sentence splitter also creates Split annotations on the sentence boundaries. If you include Split in your Input line but do not mention {Split} in a rule, this will have the effect of preventing a match that crosses a sentence boundary.

Phase: secondpass
Input: Lookup Split
Options: control = brill

Rule: A3b
({Lookup.majorType == "trouble"}
 {Lookup.majorType == "alteration"}
):label
--> :label.A3b = {rule= "A3b"}

The way this works is that the Input line determines which annotations the JAPE matcher can "see" - if the trouble and alteration Lookup annotations are in different sentences, then the matcher will see the sequence {Lookup}{Split}{Lookup}, which does not match a rule that wants {Lookup}{Lookup}.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!