本文整理汇总了Python中corpus.Corpus.get_other_leaf方法的典型用法代码示例。如果您正苦于以下问题:Python Corpus.get_other_leaf方法的具体用法?Python Corpus.get_other_leaf怎么用?Python Corpus.get_other_leaf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类corpus.Corpus
的用法示例。
在下文中一共展示了Corpus.get_other_leaf方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: print_features
# 需要导入模块: from corpus import Corpus [as 别名]
# 或者: from corpus.Corpus import get_other_leaf [as 别名]
def print_features(self, relation, labels, which, to_file):
to_line = ''
conn_leaves = relation.conn_leaves
if len(conn_leaves) == 0:
return
conn_str = '_'.join(n.value for n in conn_leaves)
to_line += 'conn:%s ' % conn_str
for leaf in conn_leaves:
to_line += 'conn_part:%s ' % leaf.value
conn_pos = '_'.join(n.parent_node.value for n in conn_leaves)
to_line += 'conn_pos:%s ' % conn_pos
prev = Corpus.get_other_leaf(conn_leaves[0], -1, relation.article)
if prev is not None:
to_line += 'prev_full:%s_%s ' % (prev.value, conn_str)
for label in labels:
to_file.write('%s %s\n' % (to_line, SENSES_LABEL_MAP[label.encode('utf-8')]))
示例2: print_features
# 需要导入模块: from corpus import Corpus [as 别名]
# 或者: from corpus.Corpus import get_other_leaf [as 别名]
def print_features(self, article, which, to_file):
checked_conns = []
for sentence in article.sentences:
all_conns = sentence.check_connectives()
checked_conns += all_conns
for conn in all_conns:
conn_str = '_'.join(n.value for n in conn)
to_file_line = ''
to_file_line += 'conn:'+conn_str+' '
conn_pos = '_'.join([x.parent_node.value for x in conn])
to_file_line += 'lexsyn:conn_POS:'+conn_pos+' '
prev_leaf = Corpus.get_other_leaf(conn[0], -1, article)
if prev_leaf is not None:
to_file_line += 'lexsyn:with_prev_full:'+prev_leaf.value+'_'+conn_str+' '
prev_pos = prev_leaf.parent_node.value
to_file_line += 'lexsyn:prev_POS:'+prev_pos+' '
to_file_line += 'lexsyn:with_prev_POS:'+prev_pos+'_'+conn_pos.split('_')[0]+' '
to_file_line += 'lexsyn:with_prev_POS_full:'+prev_pos+'_'+conn_pos+' '
next_leaf = Corpus.get_other_leaf(conn[-1], 1, article)
if next_leaf is not None:
to_file_line += 'lexsyn:with_next_full:'+conn_str+'_'+next_leaf.value+' '
next_pos = next_leaf.parent_node.value
to_file_line += 'lexsyn:next_POS:'+next_pos+' '
to_file_line += 'lexsyn:with_next_POS:'+conn_pos.split('_')[-1]+'_'+next_pos+' '
to_file_line += 'lexsyn:with_next_POS_full:'+conn_pos+'_'+next_pos+' '
# Pitler & Nenkova (ACL 09) features:
# self_cat, parent_cat, left_cat, right_cat, right_VP, right_trace
res = sentence.get_connective_categories(conn)
res2 = ['selfCat:'+res[0],
'parentCat:'+res[1],
'leftCat:'+res[2],
'rightCat:'+res[3]]
if res[4]:
res2.append('rightVP')
if res[5]:
res2.append('rightTrace')
for e in res2:
to_file_line += 'syn:'+e+' '
for e in res2:
to_file_line += 'conn-syn:'+'conn:'+conn_str+'-'+e+' '
for j in range(0, len(res2)):
for pair in res2[j+1:]:
to_file_line += 'syn-syn:'+res2[j]+'-'+pair+' '
res3 = sentence.get_syntactic_features(*res[6])
to_file_line += 'path-self>root:'+res3[0]+' '
to_file_line += 'path-self>root2:'+res3[1]+' '
label = '0'
if conn in article.disc_connectives:
label = '1'
to_file.write(to_file_line+' '+label+'\n')
return checked_conns