本文整理汇总了Python中nltk.corpus.PlaintextCorpusReader.tokenized方法的典型用法代码示例。如果您正苦于以下问题:Python PlaintextCorpusReader.tokenized方法的具体用法?Python PlaintextCorpusReader.tokenized怎么用?Python PlaintextCorpusReader.tokenized使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nltk.corpus.PlaintextCorpusReader
的用法示例。
在下文中一共展示了PlaintextCorpusReader.tokenized方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PlaintextCorpusReader
# 需要导入模块: from nltk.corpus import PlaintextCorpusReader [as 别名]
# 或者: from nltk.corpus.PlaintextCorpusReader import tokenized [as 别名]
#! /usr/bin/python
import pickle
from nltk import *
from nltk.corpus import PlaintextCorpusReader
training_corpus_root = "../data/training_set"
dev_corupus_root = "../data/development_set"
test_corupus_root = "../data/test_set"
convote_training = PlaintextCorpusReader(training_corpus_root, '.*')
convote_dev = PlaintextCorpusReader(dev_corupus_root, '.*')
convote_test = PlaintextCorpusReader(test_corupus_root, '.*')
bigram = bigrams(convote_training.tokenized())
outfile = open('../data/training_bigrams', 'w')
pos_tokens = pos_tag(convote_training.tokenized())
prep_tokens = []
for (word, pos) in pos_tokens:
if(pos == 'IN'):
prep_tokens.append(word + '|' + pos)
else:
prep_tokens.append(pos)
trigram = nltk.trigrams(prep_tokens)
trigram_file = open('../data/pos_trigrams', 'w')
pickle.dump(bigram, outfile)
pickle.dump(trigram, trigram_file)