Jape file to find the pattern within a sentence

人走茶凉 提交于 2019-12-19 09:26:32

问题


I need to annotate a part of a sentence if the words i have written in my jape rule appear in the same sentence. Eg the sentence is "The child cannot resist any changes to his routine". I have put words like resist in "trouble.lst" file and changes in "alteration.lst" file. Now in this sentence i need to annotate the part "resist any changes" as "A3b". I have tried using the below code but it is not considering words in the same sentence. My jape rule is taking words from different sentences as well. Suppose resist comes in one sentence and changes in some other later sentence, so this code is annotating that as well. Can anyone please help me out figure out solution to this?

Phase:secondpass
Input: Lookup
Options: control = brill

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

回答1:


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"}



回答2:


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}.



来源:https://stackoverflow.com/questions/29198611/jape-file-to-find-the-pattern-within-a-sentence

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