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 #15: Does every token in the shorter name appear in the longer name?
10 */
11 public class MatchRule16 implements OrthoMatcherRule {
12
13 OrthoMatcher orthmatcher;
14
15 public MatchRule16(OrthoMatcher orthomatcher){
16 this.orthmatcher=orthomatcher;
17 }
18
19 public boolean value(String s1, String s2) {
20
21 boolean result =true;
22
23 //do a token-by-token test
24 Annotation token1, token2;
25 // catch (ExecutionException e) {}
26 for (int i=0; i < orthmatcher.tokensShortAnnot.size(); i++) {
27 token1 = (Annotation) orthmatcher.tokensShortAnnot.get(i);
28 //first check if not punctuation, because we need to skip it
29 if (token1.getFeatures().get(orthmatcher.TOKEN_KIND_FEATURE_NAME).equals(orthmatcher.PUNCTUATION_VALUE))
30 continue;
31
32 String ts1 = (String)token1.getFeatures().get(orthmatcher.TOKEN_STRING_FEATURE_NAME);
33 boolean foundMatch = false;
34 for (int j=0; j<orthmatcher.tokensLongAnnot.size(); j++) {
35 // Out.prln("i = " + i);
36 token2 = (Annotation) orthmatcher.tokensLongAnnot.get(j);
37 if (token2.getFeatures().get(OrthoMatcher.TOKEN_KIND_FEATURE_NAME).equals(OrthoMatcher.PUNCTUATION_VALUE))
38 continue;
39
40 String ts2 = (String)token2.getFeatures().get(OrthoMatcher.TOKEN_STRING_FEATURE_NAME);
41
42 if (i == 0 && j == 0) {
43 foundMatch = orthmatcher.getOrthography().fuzzyMatch(ts1, ts2);
44 }
45 else {
46 if (orthmatcher.caseSensitive) {
47 if (ts2.equals(ts1)) {
48 foundMatch = true;
49 break;
50 }
51 }
52 else {
53 if (ts2.equalsIgnoreCase(ts1)) {
54 foundMatch = true;
55 break;
56 }
57 }
58 }
59 }//for
60 //if no match for the current tokenShortAnnot, then it is not a coref of the
61 //longer annot
62 if (!foundMatch)
63 result = false;
64 } // for
65
66 //only get to here if all word tokens in the short annot were found in
67 //the long annot, so there is a coref relation
68 if (orthmatcher.log.isDebugEnabled())
69 orthmatcher.log.debug("rule 16 matched " + s1 + " to " + s2);
70
71 if(result) OrthoMatcherHelper.usedRule(16);
72 return result;
73 }
74
75 public String getId(){
76 return "MatchRule16";
77 }
78 }
|