/** * Find the stem(s) of the provided word * * @param word Word to find the stems for * @return List of stems for the word */ public List<Stem> stem(char word[], int length) { List<Stem> stems = new ArrayList<Stem>(); if (dictionary.lookupWord(word, 0, length) != null) { stems.add(new Stem(word, length)); } stems.addAll(stem(word, length, null, 0)); return stems; }
/** * Prints the results of the stemming of a word * * @param originalWord Word that has been stemmed * @param stems Stems of the word */ private static void printStemResults(String originalWord, List<Stem> stems) { StringBuilder builder = new StringBuilder().append("stem(").append(originalWord).append(")").append("\n"); for (Stem stem : stems) { builder.append("- ").append(stem.getStem()).append(": "); for (HunspellAffix prefix : stem.getPrefixes()) { builder.append(prefix.getAppend()).append("+"); if (hasText(prefix.getStrip())) { builder.append(prefix.getStrip()).append("-"); } } builder.append(stem.getStem()); for (HunspellAffix suffix : stem.getSuffixes()) { if (hasText(suffix.getStrip())) { builder.append("-").append(suffix.getStrip()); } builder.append("+").append(suffix.getAppend()); } builder.append("\n"); } System.out.println(builder); }
for (HunspellWord hunspellWord : words) { if (hunspellWord.hasFlag(affix.getFlag())) { stems.add(new Stem(strippedWord, length));
restoreState(savedState); posIncAtt.setPositionIncrement(0); termAtt.copyBuffer(nextStem.getStem(), 0, nextStem.getStemLength()); termAtt.setLength(nextStem.getStemLength()); return true; termAtt.copyBuffer(stem.getStem(), 0, stem.getStemLength()); termAtt.setLength(stem.getStemLength());
/** * Find the unique stem(s) of the provided word * * @param word Word to find the stems for * @return List of stems for the word */ public List<Stem> uniqueStems(char word[], int length) { List<Stem> stems = new ArrayList<Stem>(); CharArraySet terms = new CharArraySet(dictionary.getVersion(), 8, dictionary.isIgnoreCase()); if (dictionary.lookupWord(word, 0, length) != null) { stems.add(new Stem(word, length)); terms.add(word); } List<Stem> otherStems = stem(word, length, null, 0); for (Stem s : otherStems) { if (!terms.contains(s.stem)) { stems.add(s); terms.add(s.stem); } } return stems; }