Tokenizer, Stop Word Removal, Stemming in Java
Asked Answered
B

4

20

I am looking for a class or method that takes a long string of many 100s of words and tokenizes, removes the stop words and stems for use in an IR system.

For example:

"The big fat cat, said 'your funniest guy i know' to the kangaroo..."

the tokenizer would remove the punctuation and return an ArrayList of words

the stop word remover would remove words like "the", "to", etc

the stemmer would reduce each word the their 'root', for example 'funniest' would become funny

Many thanks in advance.

Bung answered 3/11, 2009 at 0:4 Comment(0)
D
8

AFAIK Lucene can do what you want. With StandardAnalyzer and StopAnalyzer you can to the stop word removal. In combination with the Lucene contrib-snowball (which includes work from Snowball) project you can do the stemming too.

But for stemming also consider this answer to: Stemming algorithm that produces real words

Dextro answered 3/11, 2009 at 0:15 Comment(1)
hey! @Dextro going Lucene does not help? need to more specific link.Wilek
S
6

These are standard requirements in Natural Language Processing so I would look in such toolkits. Since you require Java I'd start with OpenNLP: http://opennlp.sourceforge.net/

If you can look at other languages there is also NLTK (Python)

Note that "your funniest guy i know" is not standard syntax and this makes it harder to process than "You're the funniest guy I know". Not impossible, but much harder. I don't know of any system that would equate "your" to "you are".

Simulated answered 3/11, 2009 at 0:10 Comment(1)
Is there topic modeling in openNLP? didnt see that in the description.Eisegesis
J
1

I have dealt with the issue on a number of tasks I have worked with, so let me give a tokenizer suggestion. As I do not see it given directly as an answer, I often use edu.northwestern.at.utils.corpuslinguistics.tokenizer.* as my family of tokenizers. I see a number of cases where I used the PennTreebankTokenizer class. Here is how you use it:

    WordTokenizer wordTokenizer = new PennTreebankTokenizer();
    List<String> words = wordTokenizer.extractWords(text);

The link to this work is here. Just a disclaimer, I have no affiliation with Northwestern, the group, or the work they do. I am just someone who uses the code occasionally.

Jobie answered 16/6, 2012 at 22:6 Comment(2)
where can I download the northwestern tokenizers from?Paleolithic
@Paleolithic Try at bitbucket.org/pibburns/morphadorner/src/…. Perhaps I gave the wrong package. After 4 years it is tough to see if the package changed or I was wrong originallyJobie
N
0

Here is comprehensive list of NLP tools. Sometime it makes sense to create these yourself as they will be lighter and you would have more control to the inner workings: use simple regular expression for tokenizations. For stop words just push the list below or some other list to a HashSet:

common-english-words.txt

Here is one of many Java implementation of porter stemer).

Newhouse answered 3/11, 2009 at 0:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.