问题
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":
Include
Sentence
annotations in theInput
.
This does the main thing. Even if you do not useSentence
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.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