2017-09-24 6 views
0

私は単語の位置を取得しようとしていると、それは私が試したスペイシー:エンティティタグと単語の位置を取得

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 

スペイシードキュメントごとに、文を反復処理によってエンティティタグですしかし、どちらもこれらの作業のタグent.iとent.idxで単語の位置を取得し、次のエラー

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

答えて

0

を与えることは

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 
をent.startするように見えます
関連する問題