Python:“get\u costed\u productions”对象不支持索引

2024-04-24 09:42:51 发布

您现在位置:Python中文网/ 问答频道 /正文

def get_costed_productions(psents):
    """ Creates costed/weighted productions from a given list of parsed sentences."""
    prods_dict = production_distribution(psents)
    prods_nt_counts=nt_counts(prods_dict)
    costed_prods=[CostedProduction(p.lhs(),p.rhs(),production_cost(p, prods_nt_counts, prods_dict))
               for p in prods_dict.keys()]
    return costed_prods

prods = get_costed_productions(psents)
ppg=PCFG(Nonterminal('NP'), prods)
sprods = ppg.productions(Nonterminal('S'))
npprods = ppg.productions(Nonterminal('VP'))

nps = filter(lambda prod: prod[1].lhs().symbol() == 'NP', list(prods))
rhs = map(lambda x: x[1], nps)
rhs_dist = nltk.FreqDist(rhs)
print len(rhs_dist.keys())
print rhs_dist.tabulate()

获取错误:get_costed_productions对象不支持索引 要解决此问题,我需要在get\u costed\u productions函数中做哪些更改?你知道吗


Tags: getdistdictlistproductionlhscountsrhs