01 /*
02 * Rule.java
03 *
04 * Copyright (c) 1995-2010, The University of Sheffield. See the file
05 * COPYRIGHT.txt in the software or at http://gate.ac.uk/gate/COPYRIGHT.txt
06 *
07 * This file is part of GATE (see http://gate.ac.uk/), and is free
08 * software, licenced under the GNU Library General Public License,
09 * Version 2, June 1991 (in the distribution as file licence.html,
10 * and also available at http://gate.ac.uk/gate/licence.html).
11 *
12 * HepTag was originally written by Mark Hepple, this version contains
13 * modifications by Valentin Tablan and Niraj Aswani.
14 *
15 * $Id: Rule.java 12006 2009-12-01 17:24:28Z thomas_heitz $
16 */
17
18 /**
19 * Title: HepTag
20 * Description: Mark Hepple's POS tagger
21 * Copyright: Copyright (c) 2001
22 * Company: University of Sheffield
23 * @author Mark Hepple
24 * @version 1.0
25 */
26
27 package hepple.postag;
28
29 import java.util.*;
30
31 public abstract class Rule {
32
33 protected String from;
34 protected String to;
35 protected String ruleId;
36 protected String[] context;
37
38 public void initialise(List ruleParts) {
39 from = (String)ruleParts.get(0);
40 to = (String)ruleParts.get(1);
41 ruleId = (String)ruleParts.get(2);
42 int contextSize = ruleParts.size() - 3;
43 context = new String[contextSize];
44 for (int i=0 ; i<contextSize ; i++) context[i] = (String)ruleParts.get(i+3);
45 }
46
47 abstract public boolean checkContext(POSTagger tagger);
48
49 public boolean hasToTag(POSTagger tagger) {
50 for (int i=0 ; i<tagger.lexBuff[3].length ; i++)
51 if (to.equals(tagger.lexBuff[3][i])) return true;
52 return false;
53 }//public boolean hasToTag(Tagger tagger)
54
55 public boolean apply(POSTagger tagger) {
56 if (hasToTag(tagger) && checkContext(tagger)) {
57 tagger.tagBuff[3] = to;
58 return true;
59 }else return false;
60 }//public boolean apply(Tagger tagger)
61
62 }//public abstract class Rule
|