1   package gate.creole.morph;
2   
3   /**
4    * <p>Title: </p>
5    * <p>Description: </p>
6    * <p>Copyright: Copyright (c) 2003</p>
7    * <p>Company: </p>
8    * @author not attributable
9    * @version 1.0
10   */
11  
12  public class MorphFunctions {
13  
14    /** The word for which the program should find the root and the affix */
15    private String input;
16    /** Affix to the root word */
17    private String affix;
18    /** Length of the word provided to the program */
19    private int len;
20  
21    /**
22     * Default Constructor
23     */
24    public MorphFunctions() {
25  
26    }
27  
28    /**
29     * Method returns the found affix of the word provided to the program, for
30     * which the root and the affix has to be found
31     * @return affix if found, "  " otherwise
32     */
33    public String getAffix() {
34      if(affix==null) {
35        return " ";
36      } else {
37        return affix;
38      }
39    }
40  
41    /**
42     * Sets the input for which the roor entry has to be found in the program
43     * @param input
44     */
45    public void setInput(String input) {
46      this.input = input;
47      this.len = input.length();
48      this.affix = null;
49    }
50  
51    /**
52     * Deletes the "del" given number of characters from right,
53     * <BR> appends the "add" given string at the end and
54     * <BR> sets the affix as "affix"
55     * <BR> and returns this new string
56     */
57    public String stem(int del, String add, String affix) {
58      int stem_length = len - del;
59      String result = this.input.substring(0,stem_length)+add;
60      this.affix = affix;
61      return result;
62    } // method stem()
63  
64  
65    /**
66     * Deletes the "del" given number of characters from right,
67     * <BR> appends the "add" given string at the end
68     * <BR> and returns this new string
69     */
70    public String semi_reg_stem(int del, String add) {
71      int stem_length = len - del;
72      int inputLength = len;
73  
74      /* look for -es, -ed, -ing; cannot be anything else */
75      if(input.charAt(inputLength-1) == 's' || input.charAt(inputLength-1) == 'S') {
76        stem_length-=1;
77        this.affix = "s";
78      }
79  
80  
81      if(input.charAt(inputLength-1) == 'd' || input.charAt(inputLength-1) == 'D') {
82        stem_length-=2;
83        this.affix = "ed";
84      }
85  
86  
87      if(input.charAt(inputLength-1) == 'g' || input.charAt(inputLength-1) == 'G') {
88        stem_length-=3;
89        this.affix = "ing";
90      }
91  
92      String result = input.substring(0,stem_length)+add;
93      return result;
94    } // method semi_reg_stem()
95  
96  
97    /**
98     * returns the "root" as result and sets "affix" as affix
99     */
100   public String irreg_stem(String root, String affix) {
101     String result = root;
102     this.affix = affix;
103     return result;
104   } // method irreg_stem()
105 
106 
107   /**
108    * returns the input as the root word
109    */
110   public String null_stem() {
111     String result = input;
112     return result;
113   } // method null_stem()
114 }