首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在python中从给定文本中挖掘关键字

在python中从给定文本中挖掘关键字
EN

Stack Overflow用户
提问于 2017-07-23 13:26:16
回答 1查看 39关注 0票数 1

待挖掘关键字列表:

代码语言:javascript
复制
keywords_list = ['object-oriented programming','information security industry','python','java programmer']

这是一个文本,上面的关键字必须挖掘出来:

代码语言:javascript
复制
text = "***Python*** allows programmers to define their own types using classes and also ***python*** are most often used for ***object-oriented programming*** .***Python*** has also seen extensive use in the ***information security industry***, including in exploit development."

从上面的文本中,我们必须挖掘给定的关键字,这些关键字可能在文本中,也可能不在文本中。此外,我们还必须计算文本中存在的关键字数量。

输出:

代码语言:javascript
复制
mined_words = ['python','object-oriented programming','information security industry']

count = [3,1,1]
EN

回答 1

Stack Overflow用户

发布于 2017-07-23 19:22:02

代码语言:javascript
复制
count_list = [text.lower().count(kw) for kw in keywords_list]
mined_text = dict(zip(keywords_list, count_list))
output = sorted(mined_text, key = mined_text.get, reverse=True)
count_output = [mined_text.get(out) for out in output]

在未来,最好发布你的进度并寻求建议。现在,希望这对你有用。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45261803

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档