当前位置: 首页>>代码示例>>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;未经允许,请勿转载。