2017-05-01 5 views
4
나는 셰익스피어의 NLTK 영장에서 문장 가져하려고

-this 도움말 사이트 다음 -하지만 난 문제 (A word2vec 모델을 학습하기 위해) 문장에 대한 액세스 권한을 얻는 데 :파이썬 NLTK 셰익스피어 전집

from nltk.corpus import shakespeare #XMLCorpusreader 
shakespeare.fileids() 
['a_and_c.xml', 'dream.xml', 'hamlet.xml', 'j_caesar.xml', ...] 

play = shakespeare.xml('dream.xml') #ElementTree object 
print(play) 
<Element 'PLAY' at ...> 

for i in range(9): 
    print('%s: %s' % (play[i].tag, play[i].text)) 

을 다음을 반환합니다.

TITLE: A Midsummer Night's Dream 
PERSONAE: 

SCNDESCR: SCENE Athens, and a wood near it. 
PLAYSUBT: A MIDSUMMER NIGHT'S DREAM 
ACT: None 
ACT: None 
ACT: None 
ACT: None 
ACT: None 

왜 모든 행위가 없습니까?

내가 이해하고자하는 셰익스피어의 XMLCorpusReader에 적용 할 때 여기에 정의 된 방법 (http://www.nltk.org/howto/corpus.html#data-access-methods)의

없음 (.sents(), tagged_sents(), chunked_sents(), parsed_sents는()) 제대로 작동하지 :
1/문장 ElementTree 객체

답변

3

문제는 요소 트리의 모든 어린이에서 텍스트를 추출하는 방법에 귀결 그들을 찾는 방법을 알고하는 방법

2/

하는 방법을. 이 꽤 시도 Python element tree - extract text from element, stripping tags

에 중복이 :

for p in play: 
    print('%s: %s' % (p.tag, list(p.itertext()))) 

당신이

를 수행 할 작업을 여기에 논리를 삽입