clips / pattern

Web mining module for Python, with tools for scraping, natural language processing, machine learning, network analysis and visualization.
https://github.com/clips/pattern/wiki
BSD 3-Clause "New" or "Revised" License
8.73k stars 1.58k forks source link

parts of speech example invalid syntax #86

Closed Liontooth closed 10 years ago

Liontooth commented 10 years ago

The pattern documentation is generally excellent; this one at http://www.clips.ua.ac.be/pages/pattern-en#parser is not working:

The tag() function simply annotates words with their part-of-speech tag and returns a list of (word, tag)-tuples:

tag(string, tokenize=True, encoding='utf-8')
>>> from pattern.en import tag
>>>
>>> for word, pos in tag('I feel *happy*!')
>>>     if pos == "JJ": # Retrieve all adjectives.
>>>         print word

happy

When I try this in python 2.7.7, I get:

>>> from pattern.en import tag
>>> for word, pos in tag('I feel *happy*!')
  File "<stdin>", line 1
    for word, pos in tag('I feel *happy*!')
                                          ^
SyntaxError: invalid syntax

What is the correct syntax? Is there an example parts of speech tagger?

Cheers, Dave

abensrhir commented 10 years ago

Dave , Are you sure you didn't forget to put a ":" by the end of the 'for' statement ? i guess the syntax written on the webpage is missing a ":"

Liontooth commented 10 years ago

Abensrhir -- Ouch, thank you! Still, this should be fixed in the web documentation.