Java Reference
In-Depth Information
In the next example, we demonstrate the PorterStemmer class against an array of
words. The input could as easily have originated from some other text source. An instance
of the PorterStemmer class is created and then its stem method is applied to each
word of the array:
String words[] = {"bank", "banking", "banks", "banker",
"banked", "bankart"};
PorterStemmer ps = new PorterStemmer();
for(String word : words) {
String stem = ps.stem(word);
System.out.println("Word: " + word + " Stem: " + stem);
}
When executed, you will get the following output:
Word: bank Stem: bank
Word: banking Stem: bank
Word: banks Stem: bank
Word: banker Stem: banker
Word: banked Stem: bank
Word: bankart Stem: bankart
The last word is used in combination with the word "lesion" as in "Bankart lesion". This is
an injury of the shoulder and doesn't have much to do with the previous words. It does
show that only common affixes are used when finding the stem.
Other potentially useful PorterStemmer class methods are found in the following
table:
Method
Meaning
add
This will add a char to the end of the current stem word
stem The method used without an argument will return true if a different stem occurs
reset Reset the stemmer so a different word can be used
Search WWH ::




Custom Search