当前位置: 首页>>代码示例>>Python>>正文


Python PunktSentenceTokenizer.sentences_from_text方法代码示例

本文整理汇总了Python中nltk.tokenize.PunktSentenceTokenizer.sentences_from_text方法的典型用法代码示例。如果您正苦于以下问题:Python PunktSentenceTokenizer.sentences_from_text方法的具体用法?Python PunktSentenceTokenizer.sentences_from_text怎么用?Python PunktSentenceTokenizer.sentences_from_text使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在nltk.tokenize.PunktSentenceTokenizer的用法示例。


在下文中一共展示了PunktSentenceTokenizer.sentences_from_text方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: teeth

# 需要导入模块: from nltk.tokenize import PunktSentenceTokenizer [as 别名]
# 或者: from nltk.tokenize.PunktSentenceTokenizer import sentences_from_text [as 别名]
from nltk.tokenize import PunktSentenceTokenizer
from nltk.collocations import *
from nltk.tokenize import word_tokenize
from nltk.util import ngrams

txt = "I was in the room in Los Angeles in 1988, about 200 feet from Michael Dukakis, when Bernard Shaw asked him what he'd do if his wife were raped. Now that really was a sucker punch of a question. I was on the other side of the arena, in Cleveland, when Donald Trump bared his teeth (metaphorically speaking) at Megyn Kelly."

pst = PunktSentenceTokenizer()
sents = pst.sentences_from_text(txt.encode('utf-8').replace('\n',''))
print sents
bigrams = ngrams(word_tokenize(sents[1].replace('.','')),2)
print bigrams
开发者ID:jbrambleDC,项目名称:newsIQ,代码行数:14,代码来源:tokenization_example.py

示例2: PunktSentenceTokenizer

# 需要导入模块: from nltk.tokenize import PunktSentenceTokenizer [as 别名]
# 或者: from nltk.tokenize.PunktSentenceTokenizer import sentences_from_text [as 别名]
pst = PunktSentenceTokenizer()
files =[]
words = []
##allow to take a directory
for i in sys.argv:
  match = re.match(".*\.txt$", i)
  if match:
    files.append(i)

print 'file_name' + '\t' + 'politcal_stance'

for f in files:
  with open(f,"rb") as class_file:
    if sys.argv[1] == '--sents':
      data = class_file.read().replace('\n', '')
      sents = pst.sentences_from_text(data)
      for sent in sents:
        sent_words = nltk.word_tokenize(sent)
        for word in sent_words:
          words.append(word)
      feats = dict([(word, True) for word in words])

    else:
      for line in class_file:
        line_words = nltk.word_tokenize(line)
        for word in line_words:
          words.append(word)
      feats = dict([(word, True) for word in words])

    print f + '\t' + classifier.classify(feats)
开发者ID:jbrambleDC,项目名称:newsIQ,代码行数:32,代码来源:news_cat_pred.py

示例3: sentence_parser

# 需要导入模块: from nltk.tokenize import PunktSentenceTokenizer [as 别名]
# 或者: from nltk.tokenize.PunktSentenceTokenizer import sentences_from_text [as 别名]
def sentence_parser( input_str ):

    sentences_tokenize = PunktSentenceTokenizer()
    for sentence in sentences_tokenize.sentences_from_text( input_str ):
        if sentence.strip() != u'':
            yield sentence
开发者ID:antonfait,项目名称:SerchEngine,代码行数:8,代码来源:text_parser.py


注:本文中的nltk.tokenize.PunktSentenceTokenizer.sentences_from_text方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。