本文整理汇总了Python中ngram.NGram.items_sharing_ngrams方法的典型用法代码示例。如果您正苦于以下问题:Python NGram.items_sharing_ngrams方法的具体用法?Python NGram.items_sharing_ngrams怎么用?Python NGram.items_sharing_ngrams使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ngram.NGram
的用法示例。
在下文中一共展示了NGram.items_sharing_ngrams方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from ngram import NGram [as 别名]
# 或者: from ngram.NGram import items_sharing_ngrams [as 别名]
class Plagiarism:
def __init__(self,text):
self.ng=NGram()
file = open(text,"r")
linea = file.readline()
while linea != '':
if linea != '\n':
self.ng.add(linea)
linea = file.readline()
self.lsn=list(self.ng);
file.close()
def verify(self,text_compare):
results = []
dictio = []
file2 = open(text_compare,"r")
linea2 = file2.readline()
while linea2 != '':
if linea2 != '\n':
dictio += [self.ng.items_sharing_ngrams(linea2)]
compares = 0.0
for parrafo in self.lsn:
comp = NGram.compare(parrafo,linea2)
if compares < comp:
compares = comp
results += [compares]
linea2 = file2.readline()
file2.close()
major_ocurrences=[]
for d in dictio:
major=0
for val in d.values():
if major<val:
major=val
major_ocurrences+=[major]
avg_perc=0.0
for r in results:
avg_perc+=r
avg_perc=avg_perc/len(results)
print("Mayor numero de ocurrencias por parrafo del texto copia: "+repr(major_ocurrences))
print("Porcentaje Similitud: "+repr(avg_perc))