01 package gate.creole.orthomatcher;
02
03 import gate.Annotation;
04
05
06 /**
07 * RULE #5: if the 1st token of one name
08 * matches the second name
09 * e.g. "Pepsi Cola" == "Pepsi"
10 * Condition(s): case-insensitive match
11 * Applied to: all name annotations
12 *
13 * Note that we don't want to use nicknames here because you don't use nicknames for last names
14 */
15 public class MatchRule6 implements OrthoMatcherRule {
16
17 OrthoMatcher orthomatcher;
18
19 public MatchRule6(OrthoMatcher orthmatcher){
20 this.orthomatcher=orthmatcher;
21 }
22
23 public boolean value(String s1, String s2) {
24
25 boolean result=false;
26
27 if (orthomatcher.tokensLongAnnot.size()> 1 &&
28 ((Annotation) orthomatcher.tokensLongAnnot.get(0)).getFeatures().get("kind").equals("number"))
29 result=false;
30 {
31 // if (s1.startsWith("Patrick") || s2.startsWith("Patrick")) {
32 // Out.prln("Rule 5: " + s1 + "and " + s2);
33 // }
34
35 //require that when matching person names, the shorter one to be of length 1
36 //for the rule to apply. In other words, avoid matching Peter Smith and
37 //Peter Kline, because they share a Peter token.
38 if ( (orthomatcher.shortAnnot.getType().equals(orthomatcher.personType)
39 || orthomatcher.longAnnot.getType().equals(orthomatcher.personType)
40 )
41 &&
42 orthomatcher.tokensShortAnnot.size()>1
43 )
44 result = false;
45 else {
46 if (orthomatcher.tokensLongAnnot.size()<=1)
47 result = false; else
48 if (((Annotation) orthomatcher.tokensShortAnnot.get(0)).getFeatures().containsKey("ortho_stop"))
49 result = false; else
50
51 {result = OrthoMatcherHelper.straightCompare((String)
52 ((Annotation) orthomatcher.tokensLongAnnot.get(0)
53 ).getFeatures().get(orthomatcher.TOKEN_STRING_FEATURE_NAME),
54 s2,
55 orthomatcher.caseSensitive);
56 }
57 }
58
59 }
60
61 if (result && orthomatcher.log.isDebugEnabled()) {
62 orthomatcher.log.debug("rule 6 matched " + s1 + " to " + s2);
63 }
64 if (result) OrthoMatcherHelper.usedRule(6);
65
66 return result;
67 }
68
69 public String getId(){
70 return "MatchRule6";
71 }
72 }
|