MatchRule9.java
01 package gate.creole.orthomatcher;
02 
03 import java.util.HashSet;
04 import java.util.Map;
05 
06 import gate.Annotation;
07 
08 /**
09  * RULE #9: does one of the names match the token
10  * just before a trailing company designator
11  * in the other name?
12  * The company designator has already been chopped off,
13  * so the token before it, is in fact the last token
14  * e.g. "R.H. Macy Co." == "Macy"
15  * Applied to: organisation annotations only
16  */
17 public class MatchRule9 implements OrthoMatcherRule {
18 
19   OrthoMatcher orthomatcher;
20   
21   public MatchRule9(OrthoMatcher orthmatcher){
22     this.orthomatcher=orthmatcher;
23   }
24   
25   public boolean value(String s1, String s2) {
26     
27     boolean result=false;
28     
29     // if (s1.equalsIgnoreCase("news") || s2.equalsIgnoreCase("news"))
30     //  Out.prln("Rule 9 " + s1 + " and " + s2);
31         String s1_short = (String)
32         ((Annotationorthomatcher.tokensLongAnnot.get(
33             orthomatcher.tokensLongAnnot.size()-1)).getFeatures().get(orthomatcher.TOKEN_STRING_FEATURE_NAME);
34     //  Out.prln("Converted to " + s1_short);
35         if (orthomatcher.tokensLongAnnot.size()>1) {
36           boolean matched = OrthoMatcherHelper.straightCompare(s1_short, s2, orthomatcher.caseSensitive);
37           //we need to make sure all names match, instead of assuming transitivity,
38           //to avoid matching BBC News with News then News with ITV News, which
39           //by transitivity leads to BBC News matching ITV News which is not what
40           //we want
41           if (matched)
42             orthomatcher.allMatchingNeeded = true;
43           result = matched;
44         //if
45 
46         if (resultOrthoMatcherHelper.usedRule(9);
47         return result;
48   }
49   
50   public String getId(){
51     return "MatchRule9";
52   }
53 }