本文整理匯總了Python中EditModel.EditModel.get_edits方法的典型用法代碼示例。如果您正苦於以下問題:Python EditModel.get_edits方法的具體用法?Python EditModel.get_edits怎麽用?Python EditModel.get_edits使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類EditModel.EditModel
的用法示例。
在下文中一共展示了EditModel.get_edits方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: scan_edits
# 需要導入模塊: from EditModel import EditModel [as 別名]
# 或者: from EditModel.EditModel import get_edits [as 別名]
def scan_edits( edits_file ):
print >> sys.stderr, "Processing "+edits_file
editmodel = EditModel('')
edit_probs = Counter()
edits1 = read_edit1s(edits_file)
print >> sys.stderr, "Counting"
for error,correct in edits1:
count_chars(correct)
v, edit_types = editmodel.get_edits( correct, error )
edit_types = set(edit_types)
edit_types = [each for each in edit_types if each[0] != editmodel.nc]
edit_probs.update(edit_types)
num_char_unigrams = len(char_counts)
print >> sys.stderr, "Normalizing"
norm_edit_probs = {}
for kind,str in edit_probs.keys():
if kind == editmodel.dl:
norm_edit_probs[(kind,str)] = (edit_probs[(kind,str)] + 1.0)/(get_char_bigram_count(str) + num_char_unigrams + 1)
elif kind == editmodel.ins:
norm_edit_probs[(kind,str)] = (edit_probs[(kind,str)] + 1.0)/(get_char_unigram_count(str[0]) + num_char_unigrams + 1)
elif kind == editmodel.sub:
#If this is a substitution, reverse the characters because of bug in get_edits
norm_edit_probs[(kind,str[::-1])] = (edit_probs[(kind,str)] + 1.0)/(get_char_unigram_count(str[0]) + num_char_unigrams + 1)
elif kind == editmodel.trs:
norm_edit_probs[(kind,str)] = (edit_probs[(kind,str)] + 1.0)/(get_char_bigram_count(str) + num_char_unigrams + 1)
print >> sys.stderr, "Writing to file - edits_model"
serialize_data(norm_edit_probs, 'edit_model')
serialize_data(dict(char_counts), 'char_unigram_model')
serialize_data(dict(char_bigram_counts), 'char_bigram_model')