当前位置:网站首页>C# F23.StringSimilarity库 字符串重复度、文本相似度、防抄袭
C# F23.StringSimilarity库 字符串重复度、文本相似度、防抄袭
2022-04-23 11:35:00 【铺侦探-刘亚东】
最近在我们的铺侦探(买铺租铺就上铺侦探)项目中,为了防止经纪人发布铺源的时候抄袭其他经纪人的铺源介绍,所以我们准备根据内容的相似度进行初步的防抄袭判断。
话不多说,懒得打字,下面直接上干货:
直接在VS的Nuget管理器中搜索:F23.StringSimilarity安装。GitHub传送门,里面有详细的介绍,并且也在不断更新。
该库目前实现了十多种算法,根据自己的需求选取合适自己业务的算法,每一种算法都有自己的优缺点,建议把每一种算法大致弄明白,方便自己选择使用哪种,可以根据该插件中每个算法的命名去搜索了解。
下图是通过谷歌自动翻译的十多种算法截图,上面的GitHub传送门可以自己进去看,每一种的算法都有介绍:
每种算法的使用都很简单,下面是各种算法的使用示例:
public static void Main(string[] args)
{
var str1 = Html2Text(@"<div><div style='padding: 10px 0 5px 0'><p>1:物业面积:二楼 1221㎡,三楼:518㎡。<br/>2:整层卖,独立过道,可以自己打通使用啊。<br/>3:旅游度假区,人流量非常大。</p></div></div>");
var str2 = Html2Text(@"<div><div style='padding: 10px 0 5px 0'><p>1:<br/> 三楼:518.76平方米<br/> 2:整层,独立过道,可以自己打通使用<br/>3:旅游度假区,大型商业街中心,人流量超大。</p></div></div>");
var jaroWinkler = new JaroWinkler();
var a= jaroWinkler.Similarity(str1, str2);
var normalizedLevenshtein = new NormalizedLevenshtein();
var b= normalizedLevenshtein.Similarity(str1, str2);
var cosine = new Cosine();
var c= cosine.Similarity(str1, str2);
var jaccard = new Jaccard();
var d = jaccard.Similarity(str1, str2);
var sorensenDice = new SorensenDice();
var e = sorensenDice.Similarity(str1, str2);
var ratcliffObershelp = new RatcliffObershelp();
var f = ratcliffObershelp.Similarity(str1, str2);
var longestCommonSubsequence = new LongestCommonSubsequence();
var g= longestCommonSubsequence.Distance(str1, str2);
}
public static string Html2Text(string htmlStr)
{
if (String.IsNullOrEmpty(htmlStr))
{
return "";
}
string regEx_style = "<style[^>]*?>[\\s\\S]*?<\\/style>"; //定义style的正则表达式
string regEx_script = "<script[^>]*?>[\\s\\S]*?<\\/script>"; //定义script的正则表达式
string regEx_html = "<[^>]+>"; //定义HTML标签的正则表达式
htmlStr = Regex.Replace(htmlStr, regEx_style, "");//删除css
htmlStr = Regex.Replace(htmlStr, regEx_script, "");//删除js
htmlStr = Regex.Replace(htmlStr, regEx_html, "");//删除html标记
htmlStr = Regex.Replace(htmlStr, "\\s*|\t|\r|\n", "");//去除tab、空格、空行
htmlStr = htmlStr.Replace(" ", "");
htmlStr = htmlStr.Replace("\"", "");
htmlStr = htmlStr.Replace("\"", "");
htmlStr = htmlStr.Replace(" ", "");
return htmlStr.Trim();
}
顺便赠送一个过滤html代码的函数,上图中的Html2Text(string htmlStr)
哈哈。
然后说说我自己使用的思路吧,我用的是这个:NormalizedLevenshtein,相似度值在0~1之间
因为在网上查询了一下,这个算法比较适合论文的抄袭判断,比较符合我的需求,当然还需要加入一些自己的逻辑,比如把两个字符串的html代码去掉再比较,数字字母是否需要比较等等,然后设置一个阀值,我设置的是0.65,大于这个值就认为是抄袭的。当然抄袭只是说的是本系统直接的抄袭,因为我只与本系统之间的数据进行了比较。
版权声明
本文为[铺侦探-刘亚东]所创,转载请带上原文链接,感谢
https://blog.csdn.net/superman26/article/details/124350055
边栏推荐
- Precautions for PCB
- How does QT turn qwigdet into qdialog
- MIT: label every pixel in the world with unsupervised! Humans: no more 800 hours for an hour of video
- 创客教育中的统筹方案管理模式
- Laravel admin time range selector daterange default value problem
- 云呐|固定资产盘点中,支持多种盘点方式(资产清查盘点)
- Interpretation of 2022 robot education industry analysis report
- 分享两个实用的shell脚本
- oh-my-lotto
- Learn go language 0x04: Code of exercises sliced in go language journey
猜你喜欢
分享两个实用的shell脚本
初探 Lambda Powertools TypeScript
SOFA Weekly | 年度优秀 Committer 、本周 Contributor、本周 QA
MQ is easy to use in laravel
Database design of simple voting system
On the integration of steam education in early childhood education
Redis optimization series (II) redis master-slave principle and master-slave common configuration
Laravel增加自定义助手函数
Get things technology network optimization - CDN resource request Optimization Practice
年度最尴尬的社死瞬间,是Siri给的
随机推荐
卷积层和池化层总结
Using Baidu PaddlePaddle EasyDL to accomplish specified target recognition
MQ的了解
qt5. 8. You want to use SQLite in the 64 bit static library, but the static library has no method to compile the supporting library
Interpreting the art created by robots
汇编语言 运行环境设置等教程链接整理
Cognition and R & D technology of micro robot
谁说抠图要会 PS?这个开源神器还能批量抠,效果拔群!
云呐|固定资产盘点中,支持多种盘点方式(资产清查盘点)
Siri gave the most embarrassing social death moment of the year
When the activity is in progress! Click the link to join the live studio to participate in "can AI really save energy?" Let's have a discussion!
创客教育中的统筹方案管理模式
Redis学习之五---高并发分布式锁实战
On lambda powertools typescript
R-drop: a more powerful dropout regularization method
PyTorch 神经网络训练器
redis优化系列(二)Redis主从原理、主从常用配置
Get things technology network optimization - CDN resource request Optimization Practice
Practical data Lake iceberg lesson 30 MySQL - > iceberg, time zone problems of different clients
解决由于找不到amd_ags_x64.dll,无法继续执行代码。重新安装程序可能会解决此问题,地平线(Forza Horizon 5)