MatchRule3.java
01 package gate.creole.orthomatcher;
02 
03 import java.util.ArrayList;
04 
05 import gate.Annotation;
06 
07 /**
08  * RULE #3: adding a possessive at the end
09  * of one name causes a match
10  * e.g. "Standard and Poor" == "Standard and Poor's"
11  * and also "Standard and Poor" == "Standard's"
12  * Condition(s): case-insensitive match
13  * Applied to: all name annotations
14  */
15 public class MatchRule3 implements OrthoMatcherRule {
16 
17     OrthoMatcher orthomatcher;
18     
19     public MatchRule3(OrthoMatcher orthmatcher){
20       this.orthomatcher=orthmatcher;
21     }
22   
23   public boolean value(String s1,  String s2) { //short string
24 
25     boolean result=false;
26     
27     if (s2.endsWith("'s"|| s2.endsWith("'")
28               ||(s1.endsWith("'s")|| s1.endsWith("'"))) {
29 
30         String s2_poss = null;
31 
32         if (!s2.endsWith("'s")) s2_poss = s2.concat("'s");
33         else s2_poss = s2.concat("'");
34 
35         if (s2_poss != null && OrthoMatcherHelper.straightCompare(s1, s2_poss,orthomatcher.caseSensitive)) {
36           if (orthomatcher.log.isDebugEnabled()) {
37             orthomatcher.log.debug("rule 3 matched " + s1 + " to " + s2);
38           }
39           result = true;
40         }
41 
42         // now check the second case i.e. "Standard and Poor" == "Standard's"
43         String token = (String)
44         ((Annotationorthomatcher.tokensLongAnnot.get(0)).getFeatures().get(orthomatcher.TOKEN_STRING_FEATURE_NAME);
45 
46         if (!token.endsWith("'s")) s2_poss = token.concat("'s");
47         else s2_poss = token.concat("'");
48 
49         if (s2_poss != null && OrthoMatcherHelper.straightCompare(s2_poss,s2,orthomatcher.caseSensitive)) {
50           if (orthomatcher.log.isDebugEnabled()){
51             orthomatcher.log.debug("rule 3 matched " + s1 + " to " + s2);
52           }
53           result = true;
54         }
55 
56       // if (s2.endsWith("'s")
57     
58       if (resultOrthoMatcherHelper.usedRule(3);
59       
60       return result;
61   }
62   
63   public String getId(){
64     return "MatchRule3";
65   }
66 }