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