MatchRule12.java
01 package gate.creole.orthomatcher;
02 
03 import gate.Annotation;
04 
05 /**
06  * RULE #12: do the first and last tokens of one name
07  * match the first and last tokens of the other?
08  * Condition(s): case-sensitive match
09  * Applied to: organisation annotations only
10  */
11 public class MatchRule12 implements OrthoMatcherRule {
12 
13     OrthoMatcher orthomatcher;
14   
15   public MatchRule12(OrthoMatcher orthmatcher){
16       this.orthomatcher=orthmatcher;
17   }
18   
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         ((Annotationorthomatcher.tokensLongAnnot.get(0)).getFeatures().get(orthomatcher.TOKEN_STRING_FEATURE_NAME);
29         String s2_first = (String)
30         ((Annotationorthomatcher.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             ((Annotationorthomatcher.tokensLongAnnot.get(orthomatcher.tokensLongAnnot.size()-1)).getFeatures().get(OrthoMatcher.TOKEN_STRING_FEATURE_NAME);
37             String s2_last = (String)
38             ((Annotationorthomatcher.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   public String getId(){
55     return "MatchRule12";
56   }
57 }