python nltk.index()_用NLTK处理自己的文件 | 学步园

  • Post author:
  • Post category:python


>>> import nltk

>>> from nltk.corpus import BracketParseCorpusReader

>>> corpus_root = r”C:\Program Files\360\360zip\LiveUpdateLog”

>>> file_pattern = r”.*.log”

>>> ptb = BracketParseCorpusReader(corpus_root, file_pattern)

>>> ptb.fileids()

[‘360zipUpdate.log’, ‘P2SP_360zipupdate.log’, ‘P2SP_360zipupdate22ss.log’, ‘eretertwer.log’, ‘fergwegjwelkg.log’, ‘tqos_log.log’]

>>> len(ptb.sents())

0

>>> ptb.sents(fileids=’tqos_log.log’)[19]

Traceback (most recent call last):

File “”, line 1, in

ptb.sents(fileids=’tqos_log.log’)[19]

File “C:\Python27\lib\site-packages\nltk-2.0.4-py2.7.egg\nltk\corpus\reader\util.py”, line 264, in __getitem__

raise IndexError(‘index out of range’)

IndexError: index out of range



版权声明:本文为weixin_39614262原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。