package com.pengyifan.nlp.process;

import java.util.List;

import com.google.common.base.Joiner;
import com.google.common.collect.Lists;

import edu.stanford.nlp.process.Morphology;

/**
 * Extract lemma of the word.
 * <p>
 * Lemmatization usually refers to doing things properly with the use of a
 * vocabulary and morphological analysis of words, normally aiming to remove
 * inflectional endings only and to return the base or dictionary form of a
 * word, which is known as the lemma . If confronted with the token saw,
 * stemming might return just s, whereas lemmatization would attempt to return
 * either see or saw depending on whether the use of the token was as a verb or
 * a noun.
 */
public class ExtractLemma {

  private Morphology morphology;

  public ExtractLemma() {
    morphology = new Morphology();
  }

  /**
   * Returns the stem of the word.
   * 
   * @param word the word
   * @return the stem of the word
   */
  public String lemmatize(String word) {
    return morphology.stem(word);
  }

  /**
   * Returns the stemmer result of the sentence.
   * 
   * @param sentence the sentence
   * @return stem of the sentence
   */
  public String lemmatizeSentence(String sentence) {
    List<String> words = Lists.newArrayList(sentence.split(" "));
    List<String> stems = Lists.newArrayList();
    for (String word : words) {
      stems.add(lemmatize(word));
    }
    return Joiner.on(' ').join(stems);
  }
}

@@ -841,28 +841,29 @@
 Returns the 
-stem
+lemma
  of the word
@@ -913,20 +913,21 @@
 urn the 
-stem
+lemma
  of the 
@@ -1012,24 +1012,26 @@
 (word);%0A  %7D%0A
+  
 %0A  /**%0A   * 
@@ -1046,15 +1046,273 @@
 the 
-stemmer
+lemma of the word.%0A   * %0A   * @param word the word%0A   * @param tag the part-of-speech of the word%0A   * @return the lemma of the word%0A   */%0A  public String lemmatize(String word, String tag) %7B%0A    return morphology.lemma(word, tag);%0A  %7D%0A%0A  /**%0A   * Returns the lemma
  res
@@ -1385,20 +1385,21 @@
 @return 
-stem
+lemma
  of the 

add lemmatize