MatchRule13.java
01 package gate.creole.orthomatcher;
02 
03 
04 /**
05  * RULE #12: do the first and last tokens of one name
06  * match the first and last tokens of the other?
07  * Condition(s): case-sensitive match
08  * Applied to: person annotations only
09  */
10 public class MatchRule13 implements OrthoMatcherRule {
11 
12     OrthoMatcher orthomatcher;
13   
14   public MatchRule13(OrthoMatcher orthmatcher){
15       this.orthomatcher=orthmatcher;
16   }
17   
18   @Override
19   public boolean value(String s1, String s2) {
20       // first do the easy case e.g. "Pan American" == "Pan Am"
21 
22       boolean result =false;
23     
24       if (orthomatcher.tokensLongAnnot.size()>&& orthomatcher.tokensShortAnnot.size()>1) {
25 //      Out.prln("Rule 12");
26 
27         // get first and last tokens of s1 & s2
28         String s1_first = (String)
29         orthomatcher.tokensLongAnnot.get(0).getFeatures().get(OrthoMatcher.TOKEN_STRING_FEATURE_NAME);
30         String s2_first = (String)
31         orthomatcher.tokensShortAnnot.get(0).getFeatures().get(OrthoMatcher.TOKEN_STRING_FEATURE_NAME);
32 
33         MatchRule1 matchRule1=new MatchRule1(orthomatcher);
34         if (!(matchRule1.value(s1_first,s2_first|| OrthoMatcherHelper.initialMatch(s1_first,s2_first)))
35           result = false;
36         else {
37               String s1_last = (String)
38               orthomatcher.tokensLongAnnot.get(orthomatcher.tokensLongAnnot.size()-1).getFeatures().get(OrthoMatcher.TOKEN_STRING_FEATURE_NAME);
39               String s2_last = (String)
40               orthomatcher.tokensShortAnnot.get(orthomatcher.tokensShortAnnot.size()-1).getFeatures().get(OrthoMatcher.TOKEN_STRING_FEATURE_NAME);
41       
42               boolean retVal =  OrthoMatcherHelper.straightCompare(s1_last,s2_last,orthomatcher.caseSensitive);
43               if (retVal && OrthoMatcher.log.isDebugEnabled()) {
44                 OrthoMatcher.log.debug("rule 13 matched " + s1 + "(id: " + orthomatcher.longAnnot.getId() ") to "
45                         + s2+ "(id: " + orthomatcher.shortAnnot.getId() ")");
46               }
47               result = retVal;
48         }
49       // if (tokensLongAnnot.countTokens()>1
50       
51       if (resultOrthoMatcherHelper.usedRule(13);
52       return result;
53   }
54   
55   @Override
56   public String getId(){
57     return "MatchRule13";
58   }
59 }