01 package gate.creole.orthomatcher;
02
03 import gate.Annotation;
04
05 /**
06 * RULE #11: does one name consist of contractions
07 * of the first two tokens of the other name?
08 * e.g. "Communications Satellite" == "ComSat"
09 * and "Pan American" == "Pan Am"
10 * Condition(s): case-sensitive match
11 * Applied to: organisation annotations only
12 */
13 public class MatchRule11 implements OrthoMatcherRule {
14
15 OrthoMatcher orthomatcher;
16
17 public MatchRule11(OrthoMatcher orthmatcher){
18 this.orthomatcher=orthmatcher;
19 }
20
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 ((Annotation) orthomatcher.tokensLongAnnot.get(0)).getFeatures().get(orthomatcher.TOKEN_STRING_FEATURE_NAME);
36 token12 = (String)
37 ((Annotation) 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 ((Annotation) orthomatcher.tokensShortAnnot.get(0)).getFeatures().get(orthomatcher.TOKEN_STRING_FEATURE_NAME);
44 token22 = (String)
45 ((Annotation) 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()==1 && 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 (result) OrthoMatcherHelper.usedRule(11);
70 return result;
71 }
72
73 public String getId(){
74 return "MatchRule11";
75 }
76 }
|