如何比较两段文字? [英] How to compare two paragraphs of text?

查看:195
本文介绍了如何比较两段文字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要删除带有许多段落的文本中重复的段落。

I need to remove duplicated paragraphs in a text with many paragraphs.

我使用类 java.security.MessageDigest 来计算每个段落的MD5哈希值,然后将这些哈希值添加到 Set 中。

如果 add()'ed成功,则表示最新的段落是重复的。

If add()'ed successfully, it means the latest paragraph is a duplicate one.

这样的风险吗?

除了 String.equals(),有没有其他方法? / p>

Except String.equals(), is there any other way to do it?

推荐答案

在哈希之前,您可以规范化段落删除标点符号,转换为小写字母并删除其他空格。
正规化后,只有不同的段落会有相同的散列。

Before hashing you could normalize the paragraphs e.g. Removing punctuation, conversion to lower case and removing additional whitespace. After normalizing, paragraphs that only differ there would get the same hash.

这篇关于如何比较两段文字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆