本文整理汇总了Python中vocabulary.Vocabulary.get_term_text方法的典型用法代码示例。如果您正苦于以下问题:Python Vocabulary.get_term_text方法的具体用法?Python Vocabulary.get_term_text怎么用?Python Vocabulary.get_term_text使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vocabulary.Vocabulary
的用法示例。
在下文中一共展示了Vocabulary.get_term_text方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Corpus
# 需要导入模块: from vocabulary import Vocabulary [as 别名]
# 或者: from vocabulary.Vocabulary import get_term_text [as 别名]
#.........这里部分代码省略.........
sample_maxid = int(str_maxid)
except KeyError:
db_meta.Put("__sample_maxid__", "0")
self.close_db_meta(db_meta)
return sample_maxid
def set_sample_maxid(self, sample_maxid):
db_meta = self.open_db_meta()
db_meta.Put("__sample_maxid__", str(sample_maxid))
self.close_db_meta(db_meta)
# ---------------- export_svm_file() ----------------
def export_svm_file(self, samples_name, svm_file):
samples = Samples(self, samples_name)
logging.debug(Logger.debug("Export svm file..."))
tm_tfidf = samples.load_tfidf_matrix()
save_term_matrix_as_svm_file(tm_tfidf, svm_file)
# ---------------- transform_sensitive_terms() ----------------
def transform_sensitive_terms(self, sensitive_words, vocabulary):
sensitive_terms = {}
if not sensitive_words is None:
for word in sensitive_words:
w = sensitive_words[word]
term_id = vocabulary.get_term_id(word)
sensitive_terms[term_id] = w
return sensitive_terms
# ---------------- query_by_id() ----------------
def query_by_id(self, samples_positive, samples_unlabeled, sample_id):
tsm_positive = samples_positive.tsm
tsm_unlabeled = samples_unlabeled.tsm
sensitive_words = {
##u"立案":3.0,
##u"获刑":3.0,
##u"受贿":3.0,
##u"有期徒刑":3.0,
##u"宣判":3.0,
##u"审计":2.0,
##u"调查":2.0
}
sensitive_terms = self.transform_sensitive_terms(sensitive_words, self.vocabulary)
try:
sample_content = samples_unlabeled.db_content.Get(str(sample_id))
#(_, category, date, title, key, url, content) = msgpack.loads(sample_content)
(_, category, date, title, key, url, msgext) = decode_sample_meta(sample_content)
(version, content, (cat1, cat2, cat3)) = msgext
print "sample id: %d" % (sample_id)
print "category: %d" % (category)
print "key: %s" % (key)
print "url: %s" % (url)
print "date: %s" % (date)
print "title: %s" % (title)
print "---------------- content ----------------"
#print "%s" % (content)
sample_terms, term_map = self.vocabulary.seg_content(content)
print "sample_terms: %d terms_count: %d" % (sample_terms, len(term_map))
#for term_id in term_map:
terms_list = sorted_dict_by_values(term_map, reverse=True)
for (term_id, term_used_in_sample) in terms_list:
term_text = self.vocabulary.get_term_text(term_id)
#term_used_in_sample = term_map[term_id]
print "%s(%d): %d" % (term_text, term_id, term_used_in_sample)
except KeyError:
print "Sample %d not found in db_content." % (sample_id)
db_sm = samples_unlabeled.tsm.open_db_sm()
try:
str_sample_info = db_sm.Get(str(sample_id))
(category, sample_terms, term_map) = msgpack.loads(str_sample_info)
print ""
print "---------------- keywords ----------------"
print ""
terms = {}
for term_id in term_map:
term_text = self.vocabulary.get_term_text(term_id)
term_used = term_map[term_id]
(pd_word, speciality, popularity) = calculate_term_positive_degree(term_id, tsm_positive, tsm_unlabeled, sensitive_terms)
terms[term_id] = (pd_word, speciality, popularity, term_used, term_text)
terms_list = sorted_dict_by_values(terms, reverse = True)
for (term_id, (pd_word, speciality, popularity, term_used, term_text)) in terms_list:
print "%s\t%d\t[%.6f,%.6f,%.6f]\t(id:%d)" % (term_text, term_used, pd_word, speciality, popularity, term_id)
except KeyError:
print "Sample %d not found in db_sm." % (sample_id)
samples_unlabeled.tsm.close_db(db_sm)