JAPE rule Sentence contains multiple cases

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-23 16:34:41

问题


How can i check whether a sentence contain combinations? For example consider sentence. John appointed as new CEO for google. I need to write a rule to check whether sentence contains < 'new' + 'Jobtitle' >. How can i achieve this. I tried following. I need to check is there 'new' before word .

Rule: CustomRules
(
    {
        Sentence contains {Lookup.majorType == "organization"},
        Sentence contains {Lookup.majorType == "jobtitle"},
        Sentence contains {Lookup.majorType == "person_first"}
    }
) 

回答1:


One way to handle this is to revert it. Focus on the sequence you need and then get the covering Sentence:

(
  {Token@string == "new"}
  {Lookup.majorType = "jobtitle"}
):newJT

You should check this edge when the Sentence starts after "new", like this:

new

CEO

You can use something like this:

{Token ... }
{!Sentence, Lookup.majorType ...}

And then get the sentence (if you really need it) in the java RHS:

long end = newJTAnnots.lastNode().getOffset();
long start = newJTAnnots.firstNode().getOffset();
AnnotationSet sentences = inputAS.get("Sentence", start, end);


来源:https://stackoverflow.com/questions/25657396/jape-rule-sentence-contains-multiple-cases

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