lucene - Stemming text in java -
this question has answer here:
- lucene porter stemmer not public 2 answers
im searching possibility stemm strings in java. first wanted lucene examples found in web deprecated. (snowballanalyzer, porterstemmer, ...) want stemm whole sentences.
public static string stemsentence(string sentence) { ... return stemmedsentence; }
how can it?
make this:
public static string stem(string string) throws ioexception { tokenstream tokenizer = new standardtokenizer(version.lucene_47, new stringreader(string)); tokenizer = new standardfilter(version.lucene_47, tokenizer); tokenizer = new lowercasefilter(version.lucene_47, tokenizer); tokenizer = new porterstemfilter(tokenizer); chartermattribute token = tokenizer.getattribute(chartermattribute.class); tokenizer.reset(); stringbuilder stringbuilder = new stringbuilder(); while(tokenizer.incrementtoken()) { if(stringbuilder.length() > 0 ) { stringbuilder.append(" "); } stringbuilder.append(token.tostring()); } tokenizer.end(); tokenizer.close(); return stringbuilder.tostring(); }
Comments
Post a Comment