MatchRule11.java
01 package gate.creole.orthomatcher;
02 
03 
04 /**
05  * RULE #11: does one name consist of contractions
06  * of the first two tokens of the other name?
07  * e.g. "Communications Satellite" == "ComSat"
08  * and "Pan American" == "Pan Am"
09  * Condition(s): case-sensitive match
10  * Applied to: organisation annotations only
11  */
12 public class MatchRule11 implements OrthoMatcherRule {
13 
14   OrthoMatcher orthomatcher;
15   
16   public MatchRule11(OrthoMatcher orthmatcher){
17       this.orthomatcher=orthmatcher;
18   }
19   
20   @Override
21   public boolean value(String s1, String s2) {
22       // first do the easy case e.g. "Pan American" == "Pan Am"
23       boolean result =false;
24       
25       String token11 = null;
26       String token12 = null;
27       String token21 = null;
28       String token22 = null;
29 
30       if (orthomatcher.tokensLongAnnot.size() 2)
31         result = false;
32       else {
33           // 1st get the first two tokens of s1
34           token11 = (String)
35           orthomatcher.tokensLongAnnot.get(0).getFeatures().get(OrthoMatcher.TOKEN_STRING_FEATURE_NAME);
36           token12 = (String)
37           orthomatcher.tokensLongAnnot.get(1).getFeatures().get(OrthoMatcher.TOKEN_STRING_FEATURE_NAME);
38     
39           // now check for the first case i.e. "Pan American" == "Pan Am"
40           if (orthomatcher.tokensShortAnnot.size() == 2)  {
41     
42             token21 = (String)
43             orthomatcher.tokensShortAnnot.get(0).getFeatures().get(OrthoMatcher.TOKEN_STRING_FEATURE_NAME);
44             token22 = (String)
45             orthomatcher.tokensShortAnnot.get(0).getFeatures().get(OrthoMatcher.TOKEN_STRING_FEATURE_NAME);
46     
47             if (token11.startsWith(token21)
48                     && token12.startsWith(token22))
49               result = true;
50     
51           // if (tokensShortAnnot.countTokens() == 2)
52     
53           // now the second case e.g.  "Communications Satellite" == "ComSat"
54           else if (orthomatcher.tokensShortAnnot.size()==&& s2.length()>=3) {
55     
56             // split the token into possible contractions
57             // ignore case for matching
58             for (int i=2;i<s2.length();i++) {
59               token21=s2.substring(0,i+1);
60               token22=s2.substring(i+1);
61     
62               if (token11.startsWith(token21)
63                       && token12.startsWith(token22))
64                 result = true;
65             }// for
66           // else if
67       }
68 
69       if (resultOrthoMatcherHelper.usedRule(11);
70       return result;
71   }
72   
73   @Override
74   public String getId(){
75     return "MatchRule11";
76   }
77 }