Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

java - Jape file to find the pattern within a sentence

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"}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...