Estoy usando NLTK RegexpParser para extraer noungroups y verbgroups de tokens etiquetados.NLTK Chunking y caminar en el árbol de resultados
¿Cómo ando el árbol resultante para encontrar solo los fragmentos que son grupos NP o V?
from nltk.chunk import RegexpParser
grammar = '''
NP: {<DT>?<JJ>*<NN>*}
V: {<V.*>}'''
chunker = RegexpParser(grammar)
token = [] ## Some tokens from my POS tagger
chunked = chunker.parse(tokens)
print chunked
#How do I walk the tree?
#for chunk in chunked:
# if chunk.??? == 'NP':
# print chunk
(S (NP Carrier/NN) para/IN tejido-/JJ y/CC de cultivo celular/JJ para/IN (NP el/preparación DT/NN) de/IN (implantes NP/NNS) y/CC (implante NP/NN) (V que contiene/VBG) (NP el portador/DT/NN) ./.)
Me da AttributeError: 'tupla' objeto no tiene atributo 'nodo' n es de –
respuesta editado ... –
funciona como un encanto - gracias! –