01 package gate.creole.orthomatcher;
02
03 import java.util.HashMap;
04 import java.util.HashSet;
05 import java.util.Map;
06
07 import gate.Annotation;
08
09 /**
10 * RULE #7: if one of the tokens in one of the
11 * names is in the list of separators eg. "&"
12 * then check if the token before the separator
13 * matches the other name
14 * e.g. "R.H. Macy & Co." == "Macy"
15 * Condition(s): case-sensitive match
16 * Applied to: organisation annotations only
17 */
18 public class MatchRule8 implements OrthoMatcherRule {
19
20 OrthoMatcher orthomatcher;
21
22 public MatchRule8(OrthoMatcher orthmatcher){
23 this.orthomatcher=orthmatcher;
24 }
25
26 public boolean value(String s1, String s2) {
27
28 boolean result=false;
29
30 //don't try it unless the second string is just one token
31 if (orthomatcher.tokensShortAnnot.size() != 1)
32 result = false;
33 else
34 {
35 String previous_token = null;
36
37 for (int i = 0; i < orthomatcher.tokensLongAnnot.size(); i++ ) {
38 if (orthomatcher.connector.containsKey( ((Annotation) orthomatcher.tokensLongAnnot.get(i)
39 ).getFeatures().get(OrthoMatcher.TOKEN_STRING_FEATURE_NAME) )) {
40 previous_token = (String) ((Annotation) orthomatcher.tokensLongAnnot.get(i-1)
41 ).getFeatures().get(OrthoMatcher.TOKEN_STRING_FEATURE_NAME);
42
43 break;
44 }
45 }
46
47 //now match previous_token with other name
48 if (previous_token != null) {
49 // if (s1.equalsIgnoreCase("chin") || s2.equalsIgnoreCase("chin"))
50 // Out.prln("Rule7");
51 result = OrthoMatcherHelper.straightCompare(previous_token,s2,orthomatcher.caseSensitive);
52
53 }
54 }
55
56 if (result) OrthoMatcherHelper.usedRule(8);
57 return result;
58
59 }
60
61 public String getId(){
62 return "MatchRule8";
63 }
64 }
|