本文整理汇总了Python中configuration.Configuration.next_gold_action方法的典型用法代码示例。如果您正苦于以下问题:Python Configuration.next_gold_action方法的具体用法?Python Configuration.next_gold_action怎么用?Python Configuration.next_gold_action使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类configuration.Configuration
的用法示例。
在下文中一共展示了Configuration.next_gold_action方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_features
# 需要导入模块: from configuration import Configuration [as 别名]
# 或者: from configuration.Configuration import next_gold_action [as 别名]
def test_features(self):
sen = [DependencyToken(i, '-', '-', '-', '-') for i in range(11)]
sen[1].head = 5
sen[2].head = 3
sen[3].head = 5
sen[4].head = 5
sen[5].head = 0
sen[6].head = 5
sen[7].head = 8
sen[8].head = 5
sen[9].head = 8
sen[10].head = 5
conf = Configuration(sen)
i = 0
while not conf.is_terminal_state():
act, l = conf.next_gold_action()
label = (act + ':' + l) if l else act
feats = conf.feature_ids()
if i==8:
assert feats[-2] == 2
assert feats[8] == 3
if i==11:
assert feats[10] == 6
conf.do(act, l)
i+=1
assert conf.lm[5] == 1
assert conf.lm2[5] == 3
assert conf.rm[5] == 10
assert conf.rm2[5] == 8
示例2: enumerate
# 需要导入模块: from configuration import Configuration [as 别名]
# 或者: from configuration.Configuration import next_gold_action [as 别名]
import os, sys
from utils import *
from configuration import Configuration
writer = codecs.open(os.path.abspath(sys.argv[2]), 'w', encoding='utf-8')
for i, sen in enumerate(read_conll(os.path.abspath(sys.argv[1]))):
if is_projective([e.head for e in sen[1:]]):
conf = Configuration(sen)
while not conf.is_terminal_state():
act, l = conf.next_gold_action()
label = (act + ':' + l) if l else act
wf, pf,lf = conf.features()
writer.write(' '.join(wf) + ' ' + ' '.join(pf) + ' ' + ' '.join(lf)+ ' ' + label + '\n')
conf.do(act, l)
if (i+1) % 100 == 0: sys.stdout.write(str(i+1) + '...')
writer.close()
print('Done!')