本文整理汇总了Python中corpus.Corpus.test_with_svm方法的典型用法代码示例。如果您正苦于以下问题:Python Corpus.test_with_svm方法的具体用法?Python Corpus.test_with_svm怎么用?Python Corpus.test_with_svm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类corpus.Corpus
的用法示例。
在下文中一共展示了Corpus.test_with_svm方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _process_parsed_conn
# 需要导入模块: from corpus import Corpus [as 别名]
# 或者: from corpus.Corpus import test_with_svm [as 别名]
def _process_parsed_conn(self, articles, which='test'):
"""
generate explicit relation for each true discourse connective
"""
connParser = Connective()
conn_feat_name = FILE_PATH + '/../tmp/conn.feat'
conn_feat_file = open(conn_feat_name, 'w')
checked_conns = []
for art in articles:
checked_conns.append(connParser.print_features(art, which, conn_feat_file))
conn_feat_file.close()
conn_vec_name = FILE_PATH + '/../tmp/conn.vec'
conn_pred_name = FILE_PATH + '/../tmp/conn.pred'
Corpus.test_with_svm(conn_feat_name, connParser.feat_map_file, conn_vec_name, connParser.model_file, conn_pred_name)
conn_res = [float(l.strip().split()[-1]) for l in open(conn_pred_name, 'r')]
assert len(checked_conns) == len(articles), 'article size not match'
s = 0
for art, cand_conns in zip(articles, checked_conns):
length = len(cand_conns)
cand_res = conn_res[s:s+length]
s += length
for conn, label in zip(cand_conns, cand_res):
if label > 0:
rel = Relation()
rel.doc_id = art.id
rel.rel_type = 'Explicit'
rel.article = art
rel.conn_leaves = conn
rel.conn_addr = [n.leaf_id for n in conn]
art.exp_relations.append(rel)
# remove auto checked confilict connectives
# art.remove_confilict_relations()
assert s == len(conn_res), 'conn size not match'
示例2: test
# 需要导入模块: from corpus import Corpus [as 别名]
# 或者: from corpus.Corpus import test_with_svm [as 别名]
def test(self):
to_file = open(self.test_file, 'w')
self.prepare_data(DEV_PARSE_PATH, DEV_REL_PATH, 'test', to_file)
to_file.close()
Corpus.test_with_svm(self.test_file, self.feat_map_file, self.test_vec_file, self.model_file, self.predicted_file)