MatchRule6.java
01 package gate.creole.orthomatcher;
02 
03 
04 
05 /**
06  * RULE #5: if the 1st token of one name
07  * matches the second name
08  * e.g. "Pepsi Cola" == "Pepsi"
09  * Condition(s): case-insensitive match
10  * Applied to: all name annotations
11  *
12  * Note that we don't want to use nicknames here because you don't use nicknames for last names
13  */
14 public class MatchRule6 implements OrthoMatcherRule {
15 
16   OrthoMatcher orthomatcher;
17   
18   public MatchRule6(OrthoMatcher orthmatcher){
19     this.orthomatcher=orthmatcher;
20   }
21   
22   @Override
23   public boolean value(String s1, String s2) {
24     
25     boolean result=false;
26     
27        if (orthomatcher.tokensLongAnnot.size()&&
28               orthomatcher.tokensLongAnnot.get(0).getFeatures().get("kind").equals("number"))
29        result=false;
30        {
31               //  if (s1.startsWith("Patrick") || s2.startsWith("Patrick")) {
32               //  Out.prln("Rule 5: " + s1 + "and " + s2);
33               //  }
34         
35               //require that when matching person names, the shorter one to be of length 1
36               //for the rule to apply. In other words, avoid matching Peter Smith and
37               //Peter Kline, because they share a Peter token.
38               if ( (orthomatcher.shortAnnot.getType().equals(orthomatcher.personType)
39                       || orthomatcher.longAnnot.getType().equals(orthomatcher.personType)
40               )
41               &&
42               orthomatcher.tokensShortAnnot.size()>1
43               )
44                 result = false;
45               else {
46                     if (orthomatcher.tokensLongAnnot.size()<=1)
47                       result = falseelse 
48                     if (orthomatcher.tokensShortAnnot.get(0).getFeatures().containsKey("ortho_stop"))
49                       result = falseelse
50                     
51                     {result = OrthoMatcherHelper.straightCompare((String)
52                             orthomatcher.tokensLongAnnot.get(0).getFeatures().get(OrthoMatcher.TOKEN_STRING_FEATURE_NAME),
53                             s2,
54                             orthomatcher.caseSensitive);
55                     }
56               }
57       
58        }
59        
60       if (result && OrthoMatcher.log.isDebugEnabled()) {
61         OrthoMatcher.log.debug("rule 6 matched " + s1 + " to " + s2);
62        }
63       if (resultOrthoMatcherHelper.usedRule(6);
64       
65       return result;
66   }
67   
68   @Override
69   public String getId(){
70     return "MatchRule6";
71   }
72 }