文本重复率检查

<!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>文本重复率检查</title> <style> body { font-family: Arial, sans-serif; margin: 0; padding: 20px; background-color: #f5f5f5; } h1 { text-align: center; } .container { max-width: 600px; margin: 0 auto; background-color: #fff; padding: 20px; border-radius: 5px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); } label { display: block; margin-bottom: 5px; } textarea { width: 100%; padding: 10px; border-radius: 5px; border: 1px solid #ccc; box-sizing: border-box; resize: vertical; } button { padding: 10px 20px; background-color: #4CAF50; color: #fff; border: none; border-radius: 5px; cursor: pointer; margin-top: 10px; } button:hover { background-color: #45a049; } #result { margin-top: 20px; font-weight: bold; text-align: center; } </style> </head> <body> <div class="container"> <h1>文本重复率检查</h1> <label for="textA">标准文本(A):</label> <textarea id="textA" rows="4"></textarea><br> <label for="textB">对比文本(B):</label> <textarea id="textB" rows="4"></textarea><br> <button onclick="checkDuplication()">检查重复率</button> <div id="result"></div> </div> <script> function cleanText(text) { // 去除除中文之外的所有字符,包括空格、换行等 return text.replace(/[^\u4e00-\u9fa5]+/g, ''); } function checkDuplication() { const textA = document.getElementById('textA').value; const textB = document.getElementById('textB').value; // 清洗文本 const cleanTextA = cleanText(textA); const cleanTextB = cleanText(textB); // 计算重复字符数量 const intersection = [...new Set(cleanTextA + cleanTextB)].filter(char => cleanTextA.includes(char) && cleanTextB.includes(char)); const commonChars = intersection.length; // 注意:这里的重复率是基于两个文本共同拥有的不同字符数量与两个文本不同字符并集数量的比例 const totalUniqueChars = [...new Set(cleanTextA + cleanTextB)].length; const duplicationRate = (commonChars / totalUniqueChars) * 100; // 显示结果 document.getElementById('result').textContent = `重复率: ${duplicationRate.toFixed(2)}%`; } </script> </body> </html>

 


__EOF__

本文作者Josi
本文链接https://www.cnblogs.com/joiny-/p/18250483.html
关于博主:编程小萌新一名,希望从今天开始慢慢提高,一步步走向技术的高峰!
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!
posted @   joiny-  阅读(26)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· C#/.NET/.NET Core技术前沿周刊 | 第 29 期(2025年3.1-3.9)
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
点击右上角即可分享
微信分享提示