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 #12: do the first and last tokens of one name
10 * match the first and last tokens of the other?
11 * Condition(s): case-sensitive match
12 * Applied to: person annotations only
13 */
14 public class MatchRule13 implements OrthoMatcherRule {
15
16 OrthoMatcher orthomatcher;
17
18 public MatchRule13(OrthoMatcher orthmatcher){
19 this.orthomatcher=orthmatcher;
20 }
21
22 public boolean value(String s1, String s2) {
23 // first do the easy case e.g. "Pan American" == "Pan Am"
24
25 boolean result =false;
26
27 if (orthomatcher.tokensLongAnnot.size()>1 && orthomatcher.tokensShortAnnot.size()>1) {
28 // Out.prln("Rule 12");
29
30 // get first and last tokens of s1 & s2
31 String s1_first = (String)
32 ((Annotation) orthomatcher.tokensLongAnnot.get(0)).getFeatures().get(OrthoMatcher.TOKEN_STRING_FEATURE_NAME);
33 String s2_first = (String)
34 ((Annotation) orthomatcher.tokensShortAnnot.get(0)).getFeatures().get(OrthoMatcher.TOKEN_STRING_FEATURE_NAME);
35
36 MatchRule1 matchRule1=new MatchRule1(orthomatcher);
37 if (!(matchRule1.value(s1_first,s2_first) || OrthoMatcherHelper.initialMatch(s1_first,s2_first)))
38 result = false;
39 else {
40 String s1_last = (String)
41 ((Annotation) orthomatcher.tokensLongAnnot.get(orthomatcher.tokensLongAnnot.size()-1)).getFeatures().get(OrthoMatcher.TOKEN_STRING_FEATURE_NAME);
42 String s2_last = (String)
43 ((Annotation) orthomatcher.tokensShortAnnot.get(orthomatcher.tokensShortAnnot.size()-1)).getFeatures().get(OrthoMatcher.TOKEN_STRING_FEATURE_NAME);
44
45 boolean retVal = OrthoMatcherHelper.straightCompare(s1_last,s2_last,orthomatcher.caseSensitive);
46 if (retVal && orthomatcher.log.isDebugEnabled()) {
47 orthomatcher.log.debug("rule 13 matched " + s1 + "(id: " + orthomatcher.longAnnot.getId() + ") to "
48 + s2+ "(id: " + orthomatcher.shortAnnot.getId() + ")");
49 }
50 result = retVal;
51 }
52 } // if (tokensLongAnnot.countTokens()>1
53
54 if (result) OrthoMatcherHelper.usedRule(13);
55 return result;
56 }
57
58 public String getId(){
59 return "MatchRule13";
60 }
61 }
|