views:

478

answers:

6

Does anyone know the easiest way to extract only nouns from a body of text?

I've heard about the TreeTagger tool and I tried giving it a shot but couldn't get it to work for some reason.

Any suggestions?

Thanks Phil

EDIT:

 import org.annolab.tt4j.*; 
TreeTaggerWrapper tt = new TreeTaggerWrapper(); 

try { tt.setModel("/Nouns/english.par"); 

tt.setHandler(new TokenHandler() { 
     void token(String token, String pos, String lemma) {    
     System.out.println(token+"\t"+pos+"\t"+lemma); } }); 
     tt.process(words); // words = list of words 

     } finally { tt.destroy(); 
} 

That is my code, English is the language. I was getting the error : The type new TokenHandler(){} must implement the inherited abstract method TokenHandler.token. Am I doing something wrong?

A: 

Have a look at the WordNet database. This lexical database. You could try matching each word against it and check if it's a noun.

I doubt that you will have 100% precision, though; the database doesn't have a match for every possible word in the english language, but at least it's a start.

Scharrels
That's not really accurate. For example, take the sentence "He is walking to school." versus "He said that walking is exhausting." Now, in the second sentence, "walking" is a noun (a verb nominalized via a gerund), but in the first sentence it's the progressive form of the verb "to walk". And taht's just an example, there are more problems.
Maximilian Mayerl
+1  A: 

Check out LingPipe. This can supposedly pick out named entities from English text. But I must confess that NLP isn't my area of expertise.

teabot
A: 

Hi

Easiest way would probably be to compare each word in the text with a dictionary of nouns. After that you're probably going to have to do some elementary parsing and accept approximate correctness in the results. Lots of online references to parsing natural languages.

Regards

Mark

High Performance Mark
A: 

Find a dictionary web site with an API (e.g. WS, RESTful) which you can use to run search queries against.

The results should come in an easily consumable format (e.g. XML, JSON) and should of course include the word's lexical category.

torbengee
+5  A: 

First you will have to tokenize your text. This may seem trivial (split at any whitespace may work for you) but formally it is harder. Then you have to decide what is a noun. Does "the car park" contain one noun (car park), two nouns (car, park) or one noun (park) and one adjective (car)? This is a hard problem, but again you may be able to get by without it.

Does "I saw the xyzzy" identify a noun not in a dictionary? The word "the" probably identifies xyzzy as a noun.

Where are the nouns in "time flies like an arrow". Compare with "fruit flies like a banana" (thanks to Groucho Marx).

We use the Brown tagger (Java) (http://en.wikipedia.org/wiki/Brown%5FCorpus) in the OpenNLP toolkit (opennlp.tools.lang.english.PosTagger; opennlp.tools.postag.POSDictionary on http://opennlp.sourceforge.net/) to find nouns in normal English and I'd recommend starting with that - it does most of your thinking for you. Otherwise look at any of the POSTaggers (http://en.wikipedia.org/wiki/POS%5Ftagger) or (http://www-nlp.stanford.edu/links/statnlp.html#Taggers).

In part-of-speech tagging by computer, it is typical to distinguish from 50 to 150 separate parts of speech for English, for example, NN for singular common nouns, NNS for plural common nouns, NP for singular proper nouns (see the POS tags used in the Brown Corpus)

There is a very full list of NLP toolkits in http://en.wikipedia.org/wiki/Natural%5Flanguage%5Fprocessing%5Ftoolkits. I would strongly suggest you use one of those rather than trying to match against Wordnet or other collections.

peter.murray.rust
+1 for the explanations. Some people seem to think that NLP isn't all that hard, when it actually is one of the most complex things in computing. There is a tremendous number of corner cases and everything will be useless when suddenly the language to process changes. And than, on a more theoretical level, you also have the problem that there is more than 1 definition for noun, or verb, or pronoun etc.
Maximilian Mayerl
@Maximilian thanks for the support. We agree that it's hard. Luckily we are only trying to interpret language written by chemists and that's a good deal easier!
peter.murray.rust
excellent post, thanks. Currently downloading lingpipe, Im on windows though, hope it doesnt have alot of nasty .sh scripts! haha
Phil
We have used LingPipe but it's not open and we have to have an open system for our distribution. If you are just using it personally I don't think there is a problem.
peter.murray.rust
+1  A: 

Based on your edit:

The error says that you must override the abstract method token, and you have a definition for token in your anonymous inner class, but maybe the signature of your token-override doesn't match the signature of the abstract method defined in TokenHandler?

Maximilian Mayerl