本文整理匯總了Python中diff_match_patch.diff_match_patch方法的典型用法代碼示例。如果您正苦於以下問題:Python diff_match_patch.diff_match_patch方法的具體用法?Python diff_match_patch.diff_match_patch怎麽用?Python diff_match_patch.diff_match_patch使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類diff_match_patch
的用法示例。
在下文中一共展示了diff_match_patch.diff_match_patch方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: compute_similarity_by_articles
# 需要導入模塊: import diff_match_patch [as 別名]
# 或者: from diff_match_patch import diff_match_patch [as 別名]
def compute_similarity_by_articles(text1, text2):
dmp = diff_match_patch()
dmp.Diff_Timeout = 0
arts = set(text1.keys()) | set (text2.keys())
common_text = 0
text_length = 0
for a in arts:
if a in text1 and a in text2:
diff = dmp.diff_main(text1[a], text2[a])
common_text += sum([len(txt) for op, txt in diff if op == 0])
text_length += max(len(text1[a]), len(text2[a]))
elif a in text1:
text_length += len(text1[a])
else:
text_length += len(text2[a])
sim = common_text / text_length
return sim
示例2: main
# 需要導入模塊: import diff_match_patch [as 別名]
# 或者: from diff_match_patch import diff_match_patch [as 別名]
def main():
text1 = open("speedtest1.txt").read()
text2 = open("speedtest2.txt").read()
dmp = dmp_module.diff_match_patch()
dmp.Diff_Timeout = 0.0
# Execute one reverse diff as a warmup.
dmp.diff_main(text2, text1, False)
gc.collect()
start_time = time.time()
dmp.diff_main(text1, text2, False)
end_time = time.time()
print "Elapsed time: %f" % (end_time - start_time)
示例3: setUp
# 需要導入模塊: import diff_match_patch [as 別名]
# 或者: from diff_match_patch import diff_match_patch [as 別名]
def setUp(self):
"Test harness for dmp_module."
self.dmp = dmp_module.diff_match_patch()
示例4: diff_rebuildtexts
# 需要導入模塊: import diff_match_patch [as 別名]
# 或者: from diff_match_patch import diff_match_patch [as 別名]
def diff_rebuildtexts(self, diffs):
# Construct the two texts which made up the diff originally.
text1 = ""
text2 = ""
for x in range(0, len(diffs)):
if diffs[x][0] != dmp_module.diff_match_patch.DIFF_INSERT:
text1 += diffs[x][1]
if diffs[x][0] != dmp_module.diff_match_patch.DIFF_DELETE:
text2 += diffs[x][1]
return (text1, text2)
示例5: main
# 需要導入模塊: import diff_match_patch [as 別名]
# 或者: from diff_match_patch import diff_match_patch [as 別名]
def main():
text1 = open("speedtest1.txt").read()
text2 = open("speedtest2.txt").read()
dmp = dmp_module.diff_match_patch()
dmp.Diff_Timeout = 0.0
# Execute one reverse diff as a warmup.
dmp.diff_main(text2, text1, False)
gc.collect()
start_time = time.time()
dmp.diff_main(text1, text2, False)
end_time = time.time()
print("Elapsed time: %f" % (end_time - start_time))
示例6: setUp
# 需要導入模塊: import diff_match_patch [as 別名]
# 或者: from diff_match_patch import diff_match_patch [as 別名]
def setUp(self):
"Test harness for dmp_module."
self.dmp = dmp_module.diff_match_patch()
示例7: diff_rebuildtexts
# 需要導入模塊: import diff_match_patch [as 別名]
# 或者: from diff_match_patch import diff_match_patch [as 別名]
def diff_rebuildtexts(self, diffs):
# Construct the two texts which made up the diff originally.
text1 = ""
text2 = ""
for x in range(0, len(diffs)):
if diffs[x][0] != dmp_module.diff_match_patch.DIFF_INSERT:
text1 += diffs[x][1]
if diffs[x][0] != dmp_module.diff_match_patch.DIFF_DELETE:
text2 += diffs[x][1]
return (text1, text2)
示例8: GET
# 需要導入模塊: import diff_match_patch [as 別名]
# 或者: from diff_match_patch import diff_match_patch [as 別名]
def GET(self):
if not 'user' in session or session.user is None:
f = register_form()
return render.login(f)
i = web.input()
if not i.has_key("id"):
return render.error("No crash identifier given")
if i.has_key("diff"):
is_diff = True
else:
is_diff = False
db = connect_db()
original_file, crash_file = find_original_file(db, i.id)
if original_file is None:
return render.error("Cannot find original sample.")
dmp = diff_match_patch()
buf1 = open(original_file, "rb").read()
buf2 = open(crash_file, "rb").read()
differences = dmp.diff_main(buf1, buf2, False, False)
return render.show_diff(original_file, crash_file, buf1, buf2, \
differences, hexdump)
#-----------------------------------------------------------------------
示例9: compute_similarity
# 需要導入模塊: import diff_match_patch [as 別名]
# 或者: from diff_match_patch import diff_match_patch [as 別名]
def compute_similarity(text1, text2):
dmp = diff_match_patch()
dmp.Diff_Timeout = 0
diff = dmp.diff_main(text1, text2)
# similarity
common_text = sum([len(txt) for op, txt in diff if op == 0])
text_length = max(len(text1), len(text2))
sim = common_text / text_length
return sim
示例10: diff
# 需要導入模塊: import diff_match_patch [as 別名]
# 或者: from diff_match_patch import diff_match_patch [as 別名]
def diff(s1, s2):
dmp = dmp_module.diff_match_patch()
d = dmp.diff_main(s1, s2)
dmp.diff_cleanupSemantic(d)
return d
示例11: diff_dmp
# 需要導入模塊: import diff_match_patch [as 別名]
# 或者: from diff_match_patch import diff_match_patch [as 別名]
def diff_dmp(s1, s2):
dmp = dmp_module.diff_match_patch()
d = dmp.diff_main(s1, s2)
dmp.diff_cleanupSemantic(d)
return d
示例12: readTranslationsDiff
# 需要導入模塊: import diff_match_patch [as 別名]
# 或者: from diff_match_patch import diff_match_patch [as 別名]
def readTranslationsDiff(self, b, c, v, texts):
plainBibleList, formattedBibleList = self.getTwoBibleLists(False)
mainText = config.mainText
if texts == ["ALL"]:
texts = plainBibleList + formattedBibleList
if mainText in texts:
texts.remove(mainText)
texts.insert(0, mainText)
verses = "<h2>{0}</h2>".format(self.bcvToVerseReference(b, c, v))
try:
dmp = diff_match_patch()
*_, mainVerseText = self.readTextVerse(mainText, b, c, v)
for text in texts:
book, chapter, verse, verseText = self.readTextVerse(text, b, c, v)
if not text == mainText and not text in config.originalTexts:
diff = dmp.diff_main(mainVerseText, verseText)
verseText = dmp.diff_prettyHtml(diff)
divTag = "<div>"
if b < 40 and text in config.rtlTexts:
divTag = "<div style='direction: rtl;'>"
verses += "{0}({1}{2}</ref>) {3}</div>".format(divTag, self.formVerseTag(b, c, v, text), text, verseText.strip())
config.mainText = mainText
return verses
except:
return "Package 'diff_match_patch' is missing. Read <ref onclick={0}website('https://github.com/eliranwong/UniqueBible#install-dependencies'){0}>https://github.com/eliranwong/UniqueBible#install-dependencies</ref> for guideline on installation.".format('"')
示例13: edit
# 需要導入模塊: import diff_match_patch [as 別名]
# 或者: from diff_match_patch import diff_match_patch [as 別名]
def edit(self,
identifier,
body,
meta={},
replace=False):
""" Edit an existing post
:param str identifier: Identifier of the post to reply to. Takes the
form ``@author/permlink``
:param str body: Body of the reply
:param json meta: JSON meta object that can be attached to the
post. (optional)
:param bool replace: Instead of calculating a *diff*, replace
the post entirely (defaults to ``False``)
"""
original_post = Post(identifier, steem_instance=self)
if replace:
newbody = body
else:
import diff_match_patch
dmp = diff_match_patch.diff_match_patch()
patch = dmp.patch_make(original_post["body"], body)
newbody = dmp.patch_toText(patch)
if not newbody:
log.info("No changes made! Skipping ...")
return
reply_identifier = constructIdentifier(
original_post["parent_author"],
original_post["parent_permlink"]
)
new_meta = {}
if meta:
if original_post["json_metadata"]:
import json
new_meta = original_post["json_metadata"].update(meta)
else:
new_meta = meta
return self.post(
original_post["title"],
newbody,
reply_identifier=reply_identifier,
author=original_post["author"],
permlink=original_post["permlink"],
meta=new_meta,
)