2017-09-24 4 views
0

J'essaie d'obtenir la position d'un mot et de la balise de l'entité par itérer sur une phrase, selon les docs planantsSpacy: obtenir la position de mot avec l'étiquette d'entité

import spacy 
nlp = spacy.load('en') 
doc = nlp(u'London is a big city in the United Kingdom.') 
for ent in doc.ents: 
    print(ent.label_, ent.text) 
    # GPE London 
    # GPE United Kingdom 

J'ai essayé obtenir la position du mot avec la balise ent.i et ent.idx cependant aucun de ces travaux et donner l'erreur suivante

AttributeError: 'spacy.tokens.span.Span' object has no attribute 'i' 

Répondre

0

Il semble être ent.start

import spacy 
nlp = spacy.load('en') 
doc = nlp(u'London is a big city in the United Kingdom.') 
for ent in doc.ents: 
    print(ent.label_, ent.text, ent.start) 
    #GPE London 0 
    #GPE the United Kingdom 6