MatchRule7.java
01 package gate.creole.orthomatcher;
02 
03 import gate.Annotation;
04 
05 /**
06  * RULE #6: if one name is the acronym of the other
07  * e.g. "Imperial Chemical Industries" == "ICI"
08  * Applied to: organisation annotations only
09  */
10 
11 public class MatchRule7 implements OrthoMatcherRule {
12 
13     OrthoMatcher orthomatcher;
14   
15   public MatchRule7(OrthoMatcher orthmatcher){
16     this.orthomatcher=orthmatcher;
17   }
18   
19   public boolean value(String s1, String s2) {
20     
21         boolean result=false;
22     
23         int i = 0;
24 
25         //check and if the shorted string has a space in it, then it's not
26         //an acronym
27         if (s2.indexOf(" "0)
28           result = false;
29         else {
30             // Abbreviations of one-word names are very rare and can lead to weird errors
31             if (orthomatcher.tokensLongAnnot.size() <= 1) {
32               result = false;
33             }
34             else {
35                 //Out.prln("Acronym: Matching " + s1 + "and " + s2);
36                 StringBuffer acronym_s1 = new StringBuffer("");
37                 StringBuffer acronymDot_s1 = new StringBuffer("");
38         
39                 for ;i < orthomatcher.tokensLongAnnot.size(); i++ ) {
40                   String toAppend = ( (String) ((Annotationorthomatcher.tokensLongAnnot.get(i)
41                   ).getFeatures().get(OrthoMatcher.TOKEN_STRING_FEATURE_NAME)).substring(0,1);
42                   acronym_s1.append(toAppend);
43                   acronymDot_s1.append(toAppend);
44                   acronymDot_s1.append(".");
45                 }
46         
47                 //Out.prln("Acronym dot: To Match " + acronymDot_s1 + "and " + s2);
48                 //Out.prln("Result: " + matchRule1(acronymDot_s1.toString(),s2,caseSensitive));
49         
50                 if (OrthoMatcherHelper.straightCompare(acronym_s1.toString(),s2,orthomatcher.caseSensitive||
51                     OrthoMatcherHelper.straightCompare(acronymDot_s1.toString(),s2,orthomatcher.caseSensitive) )
52                   result = true;
53             }
54         }
55 
56         if (resultOrthoMatcherHelper.usedRule(7);
57         return result;
58   }
59   
60   public String getId(){
61     return "MatchRule7";
62   }
63 }