首先,用于计算语言学的主要python库是NLTK(“自然语言工具包”)。 这是一个稳定,成熟的库,由专业计算语言学家创建和维护。 它还包含大量的教程,常见问题解答等。我强烈推荐它。
下面是一个简单的python代码模板,用于解决您的Question中提出的问题; 尽管它是运行的模板-将任何文本作为字符串提供(如我所做的那样),它将返回单词频率列表以及这些单词的排名列表(按``重要性''(或适合用作关键字) ),方法很简单。
给定文档的关键字(显然)是从文档中的重要单词中选择的,即很可能将其与另一个文档区分开的单词。 如果您对文本的主题没有先验知识,那么一种常见的技术是从其频率来推断给定单词/术语的重要性或重要性,或者重要性= 1 /频率。
text = """ The intensity of the feeling makes up for the disproportion of the objects. Things are equal to the imagination, which have the power of affecting the mind with an equal degree of terror, admiration, delight, or love. When Lear calls upon the heavens to avenge his cause, "for they are old like him," there is nothing extravagant or impious in this sublime identification of his age with theirs; for there is no other image which could do justice to the agonising sense of his wrongs and his despair! """
BAD_CHARS = ".!?,\'\""
# transform text into a list words--removing punctuation and f

本文介绍了如何使用Python的自然语言工具包(NLTK)进行文本处理和关键词提取。通过一个简单的代码模板展示了如何去除标点符号,计算词频,并根据词频排序来确定关键词的重要性,以帮助提取文档中的关键信息。
最低0.47元/天 解锁文章
370

被折叠的 条评论
为什么被折叠?



