001 package gate.creole.morph;
002
003 /**
004 * <p>Title: </p>
005 * <p>Description: </p>
006 * <p>Copyright: Copyright (c) 2003</p>
007 * <p>Company: </p>
008 * @author not attributable
009 * @version 1.0
010 */
011
012 public class MorphFunctions {
013
014 /** The word for which the program should find the root and the affix */
015 private String input;
016 /** Affix to the root word */
017 private String affix;
018 /** Length of the word provided to the program */
019 private int len;
020
021 /**
022 * Default Constructor
023 */
024 public MorphFunctions() {
025
026 }
027
028 /**
029 * Method returns the found affix of the word provided to the program, for
030 * which the root and the affix has to be found
031 * @return affix if found, " " otherwise
032 */
033 public String getAffix() {
034 if(affix==null) {
035 return " ";
036 } else {
037 return affix;
038 }
039 }
040
041 /**
042 * Sets the input for which the roor entry has to be found in the program
043 * @param input
044 */
045 public void setInput(String input) {
046 this.input = input;
047 this.len = input.length();
048 this.affix = null;
049 }
050
051 /**
052 * Deletes the "del" given number of characters from right,
053 * <BR> appends the "add" given string at the end and
054 * <BR> sets the affix as "affix"
055 * <BR> and returns this new string
056 */
057 public String stem(int del, String add, String affix) {
058 int stem_length = len - del;
059 String result = this.input.substring(0,stem_length)+add;
060 this.affix = affix;
061 return result;
062 } // method stem()
063
064
065 /**
066 * Deletes the "del" given number of characters from right,
067 * <BR> appends the "add" given string at the end
068 * <BR> and returns this new string
069 */
070 public String semi_reg_stem(int del, String add) {
071 int stem_length = len - del;
072 int inputLength = len;
073
074 /* look for -es, -ed, -ing; cannot be anything else */
075 if(input.charAt(inputLength-1) == 's' || input.charAt(inputLength-1) == 'S') {
076 stem_length-=2;
077 this.affix = "s";
078 }
079
080
081 if(input.charAt(inputLength-1) == 'd' || input.charAt(inputLength-1) == 'D') {
082 stem_length-=2;
083 this.affix = "ed";
084 }
085
086
087 if(input.charAt(inputLength-1) == 'g' || input.charAt(inputLength-1) == 'G') {
088 stem_length-=3;
089 this.affix = "ing";
090 }
091
092 String result = input.substring(0,stem_length)+add;
093 return result;
094 } // method semi_reg_stem()
095
096
097 /**
098 * returns the "root" as result and sets "affix" as affix
099 */
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 }
|