Python数据操作

您所在的位置:网站首页 词根归类合并 Python数据操作

Python数据操作

2023-09-18 05:59| 来源: 网络整理| 查看: 265

1、词干化 在自然语言处理领域,我们i经常会遇到两个或两个以上单词具有共同根源的情况。 例如,agreed, agreeing 和 agreeable这三个词具有相同的词根。 涉及任何这些词的搜索应该把它们当作是根词的同一个词。 因此将所有单词链接到它们的词根变得非常重要。在NLTK库中有一些方法来完成这个链接,并给出显示根词的输出。 以下程序使用Porter Stemming算法进行词干分析:

# 词干分析 import nltk from nltk.stem.porter import PorterStemmer porter_stemmer = PorterStemmer() word_data = "It originated from the idea that there are readers who prefer learning new skills from the comforts of their drawing rooms" # First Word tokenization nltk_tokens = nltk.word_tokenize(word_data) #Next find the roots of the word for w in nltk_tokens: print("Actual: %s Stem: %s" % (w, porter_stemmer.stem(w)))

结果:

Actual: It Stem: It Actual:


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3