Zane Carter Zane Carter - 1 year ago 102
Python Question

NLTK: How can I extract information based on sentence maps?

I know you can use noun extraction to get nouns out of sentences but how can I use sentence overlays/maps to take out phrases?

For example:

Sentence Overlay:

"First, @action; Second, Foobar"


"First, Dance and Code; Second, Foobar"

I want to return:

action = "Dance and Code"

  • Normal Noun Extractions wont work because it wont always be nouns

  • The way sentences are phrased differs so it cant be words[x] ... because the positioning of the words changes

Answer Source

You can slightly rewrite your string templates to turn them into regexps, and see which one (or which ones) match.

>>> template = "First, (?P<action>.*); Second, Foobar"
>>> mo =, "First, Dance and Code; Second, Foobar")
>>> if mo:
Dance and Code
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download