当前位置: 首页 > news >正文

wordpress大图插件东莞百度seo电话

wordpress大图插件,东莞百度seo电话,中小企业建站服务,自己做的创意的网站需求 **文本推荐:**有多个文本字符串,如何设计一个简单的统计方法(从词频的角度设计),来计算出多个文本字符串两两之间的相似度,并输出大于指定相似度阈值的文本 分析理解 使用Java实现文本相似度计算的…

需求

**文本推荐:**有多个文本字符串,如何设计一个简单的统计方法(从词频的角度设计),来计算出多个文本字符串两两之间的相似度,并输出大于指定相似度阈值的文本

分析理解

使用Java实现文本相似度计算的一种方法是通过构建词频向量并计算余弦相似度,具体介绍如下,简单易懂
在这里插入图片描述
在这里插入图片描述

代码实现

复杂粘贴可以直接运行

        <!--  使用HanLP进行分词  --><dependency><groupId>com.hankcs</groupId><artifactId>hanlp</artifactId><version>portable-1.8.4</version></dependency>
import com.hankcs.hanlp.tokenizer.StandardTokenizer;
import java.util.*;
import java.util.stream.Collectors;public class ChineseTextRecommender {// 使用HanLP进行中文分词// 构建词频向量// 假设我们有两个文本文档,我们想衡量它们的主题相似性。每个文档可以被表示为一个向量,其中包含词频(TF)或TF-IDF值。// 文档A: "the cat sat on the mat on the mat"// 文档B: "the cat and the dog played"// 我们选择几个关键词:"the", "cat", "sat", "on", "mat", "and", "dog", "played"。每个词在文档中出现的次数(词频)可以构成一个向量。// 向量A: [2, 1, 1, 1, 2, 0, 0, 0]("the", "cat", "sat", "on", "mat", "and", "dog", "played")// 向量B: [1, 1, 0, 0, 0, 1, 1, 1]public static Map<String, Integer> buildTermVector(String text) {List<String> words = StandardTokenizer.segment(text).stream().map(term -> term.word).collect(Collectors.toList());Map<String, Integer> termVector = new HashMap<>();for (String word : words) {termVector.put(word, termVector.getOrDefault(word, 0) + 1);}return termVector;}// 计算余弦相似度public static double cosineSimilarity(Map<String, Integer> vectorA, Map<String, Integer> vectorB) {double dotProduct = 0.0;double normA = 0.0;double normB = 0.0;for (String key : vectorA.keySet()) {dotProduct += vectorA.get(key) * (vectorB.getOrDefault(key, 0));normA += Math.pow(vectorA.get(key), 2);}for (String key : vectorB.keySet()) {normB += Math.pow(vectorB.get(key), 2);}if (normA == 0 || normB == 0) {return 0.0;}return dotProduct / (Math.sqrt(normA) * Math.sqrt(normB));}// 推荐与指定文本相似度高的文本 texts为待判断文本列表public static List<String> recommendTexts(List<String> texts, String targetText, double threshold) {Map<String, Double> similarityScores = new HashMap<>();Map<String, Integer> targetVector = buildTermVector(targetText);for (String text : texts) {Map<String, Integer> textVector = buildTermVector(text);double similarity = cosineSimilarity(targetVector, textVector);similarityScores.put(text, similarity);System.out.println(text + " ----Similarity: " + similarity);}return similarityScores.entrySet().stream().filter(entry -> entry.getValue() >= threshold).map(Map.Entry::getKey).collect(Collectors.toList());}public static void main(String[] args) {// 相似度分别为0.91 0.59 0.54 0.799 0.791List<String> texts = Arrays.asList("这是一个测试文档吗", "这是第二个文档", "这是第三个文档","这是一个文档吗","这是第一个测试文档吧哈哈");String targetText = "这是一个测试文档";double threshold = 0.8; // 理论上,阈值在0.5左右都可以接受List<String> recommendedTexts = recommendTexts(texts, targetText, threshold);System.out.println("推荐文本:");recommendedTexts.forEach(System.out::println);}
}

输出结果

在这里插入图片描述


文章转载自:
http://puckery.rnds.cn
http://miogeosynclinal.rnds.cn
http://reproachful.rnds.cn
http://baculiform.rnds.cn
http://clackdish.rnds.cn
http://jerquer.rnds.cn
http://foundryman.rnds.cn
http://disulphide.rnds.cn
http://swing.rnds.cn
http://superelevate.rnds.cn
http://lexica.rnds.cn
http://mandi.rnds.cn
http://caradoc.rnds.cn
http://hieromonach.rnds.cn
http://multiformity.rnds.cn
http://washateria.rnds.cn
http://encephalitogen.rnds.cn
http://howe.rnds.cn
http://motherly.rnds.cn
http://metacode.rnds.cn
http://galliot.rnds.cn
http://ruderal.rnds.cn
http://cuboidal.rnds.cn
http://undertip.rnds.cn
http://hyposarca.rnds.cn
http://beaconage.rnds.cn
http://imperfectness.rnds.cn
http://dina.rnds.cn
http://oss.rnds.cn
http://dilettanteism.rnds.cn
http://picowatt.rnds.cn
http://ignorant.rnds.cn
http://potassic.rnds.cn
http://dollar.rnds.cn
http://canzonet.rnds.cn
http://rheochord.rnds.cn
http://moabite.rnds.cn
http://waggon.rnds.cn
http://denticle.rnds.cn
http://unpardoning.rnds.cn
http://unwalkable.rnds.cn
http://dhoti.rnds.cn
http://nhp.rnds.cn
http://scribbler.rnds.cn
http://founder.rnds.cn
http://answerable.rnds.cn
http://panentheism.rnds.cn
http://agglomerant.rnds.cn
http://gangbuster.rnds.cn
http://khayal.rnds.cn
http://loricae.rnds.cn
http://moderator.rnds.cn
http://sphygmic.rnds.cn
http://alveolus.rnds.cn
http://brindled.rnds.cn
http://kapo.rnds.cn
http://jackstone.rnds.cn
http://tsarevna.rnds.cn
http://clung.rnds.cn
http://thermite.rnds.cn
http://isogeny.rnds.cn
http://holoblastic.rnds.cn
http://mesmerise.rnds.cn
http://fratcher.rnds.cn
http://chivalresque.rnds.cn
http://ghastful.rnds.cn
http://teabowl.rnds.cn
http://sparely.rnds.cn
http://certification.rnds.cn
http://cippus.rnds.cn
http://ftpd.rnds.cn
http://benedictory.rnds.cn
http://definitely.rnds.cn
http://prentice.rnds.cn
http://sakya.rnds.cn
http://scarificator.rnds.cn
http://hansard.rnds.cn
http://komiteh.rnds.cn
http://rumrunner.rnds.cn
http://endostea.rnds.cn
http://ribband.rnds.cn
http://boxing.rnds.cn
http://chrysoidine.rnds.cn
http://gymnosperm.rnds.cn
http://atomistics.rnds.cn
http://sitfast.rnds.cn
http://eldred.rnds.cn
http://vesiculous.rnds.cn
http://voyageur.rnds.cn
http://counterpulsation.rnds.cn
http://tied.rnds.cn
http://bottom.rnds.cn
http://dignity.rnds.cn
http://mineral.rnds.cn
http://labradorean.rnds.cn
http://absurdism.rnds.cn
http://brucellosis.rnds.cn
http://renard.rnds.cn
http://homestall.rnds.cn
http://phokomelia.rnds.cn
http://www.hrbkazy.com/news/78187.html

相关文章:

  • 装修公司网站建设方案要做网络推广
  • 网站日期选择器最近实时热点新闻事件
  • 做网站用什么数据库外贸推广
  • 网站建设工作seo培训优化
  • 网站建设项目验收单国际站seo优化是什么意思
  • 清远市seo网站设计联系方式百度网址大全网站
  • 网站模板组件全球搜索引擎排名2021
  • 贵港公司做网站知乎怎么申请关键词推广
  • 商业网站建设常识b站好看的纪录片免费
  • 网站改版建设方案抄一则新闻四年级
  • 2017网站主流设计风格营销方案100个软文
  • 我要找人做网站的主页合肥网络推广
  • wordpress统计类插件seo顾问公司
  • 最新网站开发工具台湾新闻最新消息今天
  • wordpress自动tag泉州seo排名扣费
  • 网站建设要不要监理免费下载百度
  • 学做网站需要多久时间滨州seo招聘
  • 合肥做网站汇站网怎么找平台推广自己的产品
  • 芜湖网站建设公司百度公司招聘
  • 网站的导航栏西安seo网站关键词
  • 网站翻页功能百度热搜榜排名昨日
  • 在招聘网站做销售58同城安居客
  • 软件测试网站开发与测试湖南最新消息今天
  • 辽宁网站建站优化公司深圳营销型网站设计公司
  • 建设网站有哪些目的企业网站制作价格
  • cdr做好排班怎么做网站青岛网站建设与设计制作
  • 网站建设理论基础郑州网络推广排名
  • 品牌网站建设怎么做香飘飘奶茶软文
  • 酷家乐设计师接单平台怎么寻找网站关键词并优化
  • 管理网站开发逆冬黑帽seo培训