當前位置: 首頁>>代碼示例>>Python>>正文


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怎麽用?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 
開發者ID:regardscitoyens,項目名稱:the-law-factory-parser,代碼行數:19,代碼來源:common.py

示例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) 
開發者ID:google,項目名稱:diff-match-patch,代碼行數:17,代碼來源:speedtest.py

示例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() 
開發者ID:google,項目名稱:diff-match-patch,代碼行數:5,代碼來源:diff_match_patch_test.py

示例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) 
開發者ID:google,項目名稱:diff-match-patch,代碼行數:12,代碼來源:diff_match_patch_test.py

示例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)) 
開發者ID:google,項目名稱:diff-match-patch,代碼行數:17,代碼來源:speedtest.py

示例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() 
開發者ID:fake-name,項目名稱:ReadableWebProxy,代碼行數:5,代碼來源:diff_match_patch_test.py

示例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) 
開發者ID:fake-name,項目名稱:ReadableWebProxy,代碼行數:12,代碼來源:diff_match_patch_test.py

示例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)

#----------------------------------------------------------------------- 
開發者ID:joxeankoret,項目名稱:nightmare,代碼行數:30,代碼來源:nightmare_frontend.py

示例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 
開發者ID:regardscitoyens,項目名稱:the-law-factory-parser,代碼行數:12,代碼來源:common.py

示例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 
開發者ID:rpryzant,項目名稱:neutralizing-bias,代碼行數:7,代碼來源:make_corpus_vectors.py

示例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 
開發者ID:rpryzant,項目名稱:neutralizing-bias,代碼行數:7,代碼來源:gen_data_from_crawl.py

示例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('"') 
開發者ID:eliranwong,項目名稱:UniqueBible,代碼行數:29,代碼來源:BiblesSqlite.py

示例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,
        ) 
開發者ID:xeroc,項目名稱:piston-lib,代碼行數:52,代碼來源:steem.py


注:本文中的diff_match_patch.diff_match_patch方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。