3

Possible Duplicate:
Extracting nouns from Noun Phase in NLP

Do anyone have some examples on how to extract all nouns from a string using Python's NLTK?

For example, i have this string: "I Like Tomatoes and Lettuce". I want to build a method that returns "Tomatoes" and "Lettuce."

If not in Python, does anyone know of any other solution?

Community
  • 1
  • 1
Mateus Pinheiro
  • 870
  • 2
  • 12
  • 20

2 Answers2

1

Get the NLTK package, and either use its built-in parser then this method; or, much faster, part-of-speech tag the string and get all the words out that have the tag NN; those are the nouns. Read up on other part-of-speech tags to find out how you can properly extract I and like.

Neither method is flawless, but it's about the best you can do. Accuracy of a good part-of-speech tagger will be above 95% on clean input. I don't think you can reach such accuracy with a WordNet-based method without a lot of extra work.

Community
  • 1
  • 1
Fred Foo
  • 355,277
  • 75
  • 744
  • 836
  • The part-of-speech tag link is behind password protection. Do you have other links to similar resources? – Cecilia Oct 02 '14 at 22:06
0

Dave Taylor wrote an adlib generator using Bash that queried Princetons wordnet to get this done. You could do something very similar in python of course with wordnets help.

Here is the link

Linux Journal - Dave Taylor adlib generator.

grantk
  • 3,958
  • 4
  • 28
  • 37
  • -1. This works for the trivial examples in that article, but will not scale to actual NLP tasks. There are much better methods to do this straight in Python with little effort. – Fred Foo May 05 '11 at 11:22