0

My jape grammer looks as below,

Phase: PhoneFinder
Input: Token
Options: control = appelt debug = false
Rule: PhoneRule
(
 {Token.kind == number,Token.category == CD,Token.length == 10}
 |
  (
   ({Token.kind == punctuation, Token.category == "("})? 
   ({Token.kind == number, Token.category == CD})?
   ({Token.kind == punctuation, Token.category == ")"})?
   ({Token.kind == punctuation, Token.category == ":"})?
   ({Token.kind == number, Token.category == CD})?
   ({Token.kind == punctuation, Token.category == ":"})?
   ({Token.kind == number, Token.category == CD})?
   ({Token.kind == punctuation, Token.category == ":"})?
   ({Token.kind == number, Token.category == CD})?
  )
 |
 (
   ({Token.kind == punctuation, Token.category == "("})[0,1] 
   ({Token.kind == number, Token.category == CD})[1,4]
   ({Token.kind == punctuation, Token.category == ")"})[0,1] 
   ({Token.kind == punctuation, Token.category == "-"})[0,1]
   ({Token.kind == number, Token.category == CD})[1,7]
  )
)
:phoneLookup
-->
{
    AnnotationSet rawPhone = bindings.get("phoneLookup");
    if(rawPhone != null && rawPhone.size() > 0 && rawPhone.lastNode().getOffset() - rawPhone.firstNode().getOffset() >= 10){
            FeatureMap features = Factory.newFeatureMap();
            features.put("rule","PhoneRule");
            features.put("kind","phone");
            outputAS.add(rawPhone.firstNode() ,rawPhone.lastNode(),"PhoneFinder",features);
            return;
    }
}

I am working on detecting phone number from a text, and I have written a rule to do the same. It keeps running infinitely when control is set to appelt or brill. It works with control set to all.

  • Interesting, but what is your question? – dedek Oct 17 '22 at 06:34
  • Did you noticed that the middle part of the head of the rule (the longest one) has question mark at the end of each line? Is it intentional? – dedek Oct 17 '22 at 06:35
  • @dedek I want to find the longest match only from all the matches. That can be done using control set to appelt. But it keeps running infinitely. So my question is that what problem does my logic have which keeps it running infinitely. – Mehtab Singh Oct 18 '22 at 15:29
  • I think that your JAPE is allowing too many possibilities, how it can be matched, so it takes so long to select the longest match. It is also possible that it is consuming too much memory, which in turn causes massive slow down of the Java process. Hard to tell. I would suggest you to gradually recreate the JAPE (its LHS) from more simple pattern and test each version, if it ends in a reasonable time. Also make it more restrictive, so there are not that many possibilities how to match the JAPE. – dedek Oct 20 '22 at 11:02

0 Answers0