词频统计方案与具体实现-elasticsearch、spark、python

方案一、基于ElasticSearch方式
方案二、基于Spark方式
方案三、基于Python方式

方案一、基于ElasticSearch方式

详见文章,里面列举了各种ElasticSearch的实现样例。主要是通过ES的fielddata做聚合或调取termvector两种方式实现,当然调用方式比较多http requset、highclient、springboot data repository、elasticsearch resttemplate等调用方式

玄明Hanko:最新Java Elasticsearch 7.10教程(六)-词频统计​zhuanlan.zhihu.com图标

 

 

方案二、基于Spark方式

Spark是基于内存的分布式计算组件,Spark官方提供了JavaWordCount的demo,详见以下文章

玄明Hanko:Java Spark入门教程 词频统计 远程调用的几个坑​zhuanlan.zhihu.com图标

 

方案三、基于Python方式

如果你只能实现简单的数据词频统计,python是最的方式,几行代码就可以搞定

text = "http requset highclient springboot"
data = text.lower().split()
words = {}
for word in data:
    if word not in words:
        words[word] = 1
    else:
        words[word] = words[word] + 1
result = sorted(words.items(), reverse=True)
print(result)

 

当然以上的这些分词要实现中文的支持都要依赖中文分词器。中文分词器可以参考:

中文分词器如何选择 jieba ik-analyzer ansj_seg HanLP​blog.csdn.net图标

 

 

posted @ 2020-12-17 16:21  玄明hanko  阅读(437)  评论(0编辑  收藏  举报