tagger tag spanish pos_tag pos español python nlp nltk

python - tag - Lemmatizing POS etiquetó palabras con NLTK?



nltk pos_tag (2)

Como @engineercoding señaló en los comentarios a la respuesta de @ rmalouf, hay muchas más etiquetas en Treebank en comparación con WordNet, consulte aquí para obtener más información .

La siguiente asignación cubre la mayor cantidad de bases posible, también define explícitamente las etiquetas POS sin coincidencias en WordNet:

# Create a map between Treebank and WordNet from nltk.corpus import wordnet as wn # WordNet POS tags are: NOUN = ''n'', ADJ = ''s'', VERB = ''v'', ADV = ''r'', ADJ_SAT = ''a'' # Descriptions (c) https://web.stanford.edu/~jurafsky/slp3/10.pdf tag_map = { ''CC'':None, # coordin. conjunction (and, but, or) ''CD'':wn.NOUN, # cardinal number (one, two) ''DT'':None, # determiner (a, the) ''EX'':wn.ADV, # existential ‘there’ (there) ''FW'':None, # foreign word (mea culpa) ''IN'':wn.ADV, # preposition/sub-conj (of, in, by) ''JJ'':[wn.ADJ, wn.ADJ_SAT], # adjective (yellow) ''JJR'':[wn.ADJ, wn.ADJ_SAT], # adj., comparative (bigger) ''JJS'':[wn.ADJ, wn.ADJ_SAT], # adj., superlative (wildest) ''LS'':None, # list item marker (1, 2, One) ''MD'':None, # modal (can, should) ''NN'':wn.NOUN, # noun, sing. or mass (llama) ''NNS'':wn.NOUN, # noun, plural (llamas) ''NNP'':wn.NOUN, # proper noun, sing. (IBM) ''NNPS'':wn.NOUN, # proper noun, plural (Carolinas) ''PDT'':[wn.ADJ, wn.ADJ_SAT], # predeterminer (all, both) ''POS'':None, # possessive ending (’s ) ''PRP'':None, # personal pronoun (I, you, he) ''PRP$'':None, # possessive pronoun (your, one’s) ''RB'':wn.ADV, # adverb (quickly, never) ''RBR'':wn.ADV, # adverb, comparative (faster) ''RBS'':wn.ADV, # adverb, superlative (fastest) ''RP'':[wn.ADJ, wn.ADJ_SAT], # particle (up, off) ''SYM'':None, # symbol (+,%, &) ''TO'':None, # “to” (to) ''UH'':None, # interjection (ah, oops) ''VB'':wn.VERB, # verb base form (eat) ''VBD'':wn.VERB, # verb past tense (ate) ''VBG'':wn.VERB, # verb gerund (eating) ''VBN'':wn.VERB, # verb past participle (eaten) ''VBP'':wn.VERB, # verb non-3sg pres (eat) ''VBZ'':wn.VERB, # verb 3sg pres (eats) ''WDT'':None, # wh-determiner (which, that) ''WP'':None, # wh-pronoun (what, who) ''WP$'':None, # possessive (wh- whose) ''WRB'':None, # wh-adverb (how, where) ''$'':None, # dollar sign ($) ''#'':None, # pound sign (#) ''“'':None, # left quote (‘ or “) ''”'':None, # right quote (’ or ”) ''('':None, # left parenthesis ([, (, {, <) '')'':None, # right parenthesis (], ), }, >) '','':None, # comma (,) ''.'':None, # sentence-final punc (. ! ?) '':'':None # mid-sentence punc (: ; ... – -) }

He etiquetado POS algunas palabras con nltk.pos_tag (), por lo que se les asigna las etiquetas treebank. Me gustaría minimizar estas palabras utilizando las etiquetas POS conocidas, pero no estoy seguro de cómo hacerlo. Estaba mirando el lematizante de Wordnet, pero no estoy seguro de cómo convertir las etiquetas POS de treebank en etiquetas aceptadas por el lematizante. ¿Cómo puedo realizar esta conversión de manera simple, o hay un lematizante que usa etiquetas treebank?


El lematizador wordnet solo conoce cuatro partes del habla (ADJ, ADV, NOUN y VERB) y solo las reglas NOUN y VERB hacen algo especialmente interesante. Las partes nominales del discurso en el conjunto de etiquetas treebank comienzan con NN, las etiquetas de verbos comienzan con VB, las etiquetas de adjetivo comienzan con JJ y las etiquetas de adverbio comienzan con RB. Entonces, la conversión de un conjunto de etiquetas al otro es bastante fácil, algo como:

from nltk.corpus import wordnet morphy_tag = {''NN'':wordnet.NOUN,''JJ'':wordnet.ADJ,''VB'':wordnet.VERB,''RB'':wordnet.ADV}[penn_tag[:2]]