01 package gate.creole.orthomatcher;
02
03 import java.util.HashMap;
04
05 import gate.Annotation;
06
07
08 /**
09 * RULE #10: is one name the reverse of the other
10 * reversing around prepositions only?
11 * e.g. "Department of Defence" == "Defence Department"
12 * Condition(s): case-sensitive match
13 * Applied to: organisation annotations only
14 */
15
16 public class MatchRule10 implements OrthoMatcherRule {
17
18 OrthoMatcher orthomatcher;
19
20 public MatchRule10(OrthoMatcher orthmatcher){
21 this.orthomatcher=orthmatcher;
22 }
23
24 public boolean value(String s1, String s2) {
25
26 boolean result=false;
27
28 String token = null;
29 String previous_token = null;
30 String next_token = null;
31 boolean invoke_rule=false;
32
33 if (orthomatcher.tokensLongAnnot.size() >= 3
34 && orthomatcher.tokensShortAnnot.size() >= 2) {
35
36 // first get the tokens before and after the preposition
37 int i = 0;
38 for (; i< orthomatcher.tokensLongAnnot.size(); i++) {
39 token = (String)
40 ((Annotation) orthomatcher.tokensLongAnnot.get(i)).getFeatures().get(orthomatcher.TOKEN_STRING_FEATURE_NAME);
41 if (orthomatcher.prepos.containsKey(token)) {
42 invoke_rule=true;
43 break;
44 }//if
45 previous_token = token;
46 }//while
47
48 if (! invoke_rule)
49 result = false;
50 else {
51 if (i < orthomatcher.tokensLongAnnot.size()
52 && previous_token != null) {
53 next_token= (String)
54 ((Annotation) orthomatcher.tokensLongAnnot.get(i++)).getFeatures().get(orthomatcher.TOKEN_STRING_FEATURE_NAME);
55
56 String s21 = (String)
57 ((Annotation) orthomatcher.tokensShortAnnot.get(0)).getFeatures().get(orthomatcher.TOKEN_STRING_FEATURE_NAME);
58 String s22 = (String)
59 ((Annotation) orthomatcher.tokensShortAnnot.get(1)).getFeatures().get(orthomatcher.TOKEN_STRING_FEATURE_NAME);
60 // then compare (in reverse) with the first two tokens of s2
61 if (OrthoMatcherHelper.straightCompare(next_token,(String) s21,orthomatcher.caseSensitive)
62 && OrthoMatcherHelper.straightCompare(previous_token, s22,orthomatcher.caseSensitive))
63 result = true ;
64 }
65 else result = false;
66 }
67 }//if (tokensLongAnnot.countTokens() >= 3
68
69 if (result) OrthoMatcherHelper.usedRule(10);
70 return result;
71 }
72
73 public String getId(){
74 return "MatchRule10";
75 }
76 }
|