2

I would like to lemmatize a bunch of opinions. As I know, nltk cannot lemmatize words in languages different from English. Researching a little, I found pattern, which can lemmatize words in several languages. How can I lemmatize some text with pattern?

This is my test corpus:

# -- coding: utf-8 --

from pattern.es import lemma #unresolved reference

opinions = ["Este es un post de juguetes de aprendizaje \
automático. En realidad, contiene no mucho \
material interesante.",
"Las bases de datos de imágenes proporcionan \
capacidades de almacenamiento.",
"La mayoría de las bases de datos de imágenes \
imágenes seguras de forma permanente.",
"Los datos de imagen de tienda bases de datos.",
"Imagina almacenar bases de datos de bases de \
datos de imágenes. Almacenar datos. Bases de datos \
de imágenes de datos de la tienda."]

print lemma(opiniones)

output:

  File "/Users/user/PycharmProjects/Pruebas/Lemmatizacion.py", line 18, in <module>
    print lemma(opiniones)
  File "/usr/local/lib/python2.7/site-packages/pattern/text/__init__.py", line 1591, in lemma
    if verb.lower() in self._inverse:
AttributeError: 'list' object has no attribute 'lower'

How can I lemmatize opinions?

Nathan Breit
  • 1,661
  • 13
  • 33
john doe
  • 2,233
  • 7
  • 37
  • 58

1 Answers1

4

You can lemmatize text using pattern's parsetree function with the lemmata parameter set to True.

from pattern.es import parsetree
parsetree("buena", lemmata=True)
# Returns [Sentence('buena/JJ/B-ADJP/O/bueno')]
Nathan Breit
  • 1,661
  • 13
  • 33
  • When i import parsetree i have an unresolved reference, how can i solve this? – john doe Oct 13 '14 at 15:48
  • In that case you probably have not properly installed/configured the pattern library. Is this PyCharm error the type of "unresolved reference" you're referring to? http://stackoverflow.com/questions/21236824/unresolved-reference-issue-in-pycharm – Nathan Breit Oct 14 '14 at 08:07
  • Thank you nathan, i followed the instructions and i still having problems with the unresolved reference. What can i do?.. – john doe Oct 21 '14 at 19:24
  • Documentation for Pattern (see the Sentence section for use of parsetree): https://www.clips.uantwerpen.be/pages/pattern-en . Basic usage: `pt = parsetree("buenos dias", lemmata=True) for sentence in pt: for lemmata in sentence.lemmata: print lemmata` – Jamie Birch Dec 29 '17 at 18:50