MatchRule12.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: organisation annotations only
09  */
10 public class MatchRule12 implements OrthoMatcherRule {
11 
12     OrthoMatcher orthomatcher;
13   
14   public MatchRule12(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       boolean result=false;
22    
23       if (orthomatcher.tokensLongAnnot.size()>&& orthomatcher.tokensShortAnnot.size()>1) {
24         // Out.prln("Rule 12");
25 
26         // get first and last tokens of s1 & s2
27         String s1_first = (String)
28         orthomatcher.tokensLongAnnot.get(0).getFeatures().get(OrthoMatcher.TOKEN_STRING_FEATURE_NAME);
29         String s2_first = (String)
30         orthomatcher.tokensShortAnnot.get(0).getFeatures().get(OrthoMatcher.TOKEN_STRING_FEATURE_NAME);
31 
32         if (!OrthoMatcherHelper.straightCompare(s1_first,s2_first,orthomatcher.caseSensitive))
33           result = false;
34         else {
35             String s1_last = (String)
36             orthomatcher.tokensLongAnnot.get(orthomatcher.tokensLongAnnot.size()-1).getFeatures().get(OrthoMatcher.TOKEN_STRING_FEATURE_NAME);
37             String s2_last = (String)
38             orthomatcher.tokensShortAnnot.get(orthomatcher.tokensShortAnnot.size()-1).getFeatures().get(OrthoMatcher.TOKEN_STRING_FEATURE_NAME);
39     
40             boolean retVal =  OrthoMatcherHelper.straightCompare(s1_last,s2_last,orthomatcher.caseSensitive);
41             if (retVal && OrthoMatcher.log.isDebugEnabled()) {
42               OrthoMatcher.log.debug("rule 12 matched " + s1 + "(id: " + orthomatcher.longAnnot.getId() ") to "
43                       + s2+ "(id: " + orthomatcher.shortAnnot.getId() ")");
44             }
45             result = retVal;
46         }
47         
48       // if (tokensLongAnnot.countTokens()>1
49       
50       if (resultOrthoMatcherHelper.usedRule(12);
51       return result;
52   }
53   
54   @Override
55   public String getId(){
56     return "MatchRule12";
57   }
58 }