本文整理汇总了Python中corpus.Corpus.build_corpus方法的典型用法代码示例。如果您正苦于以下问题:Python Corpus.build_corpus方法的具体用法?Python Corpus.build_corpus怎么用?Python Corpus.build_corpus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类corpus.Corpus
的用法示例。
在下文中一共展示了Corpus.build_corpus方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from corpus import Corpus [as 别名]
# 或者: from corpus.Corpus import build_corpus [as 别名]
def main():
logging.basicConfig(format=DefaultSetting.FORMAT_LOG, level=logging.INFO)
start_time = datetime.now()
input_file = 'data/content.with.categories.seg.vni'
stopwords_file = 'data/stopwords.txt'
num_topics = 100
prefix_name = 'demo'
directory = 'tmp'
query = 'data/query.txt'
corpus = Corpus()
corpus.build_corpus(input_file, stopwords_file, directory, prefix_name)
LDA = LDAModel()
LDA.train(corpus.corpus, corpus.dictionary, num_topics, directory, prefix_name)
LDA.show()
docsim = DocSim()
docsim.set_model(LDA.model)
docsim.set_doc(corpus)
docsim.vectorized(num_topics)
# docsim.save(directory, prefix_name)
print 'Training time: ', datetime.now() - start_time
start_time = datetime.now()
reader = codecs.open(query, 'r', 'utf8')
documents = []
for line in reader.readlines():
documents.append(line.replace('\n', ''))
docsim.query(documents, True, directory, prefix_name)
docsim.query(documents, False, directory, prefix_name)
print 'Query time: ', datetime.now() - start_time