从句子列表中提取关键词的方法/工具

时间:2012-03-18 17:42:21

标签: nlp search-engine data-mining text-mining semantic-analysis

我有一个很大的句子列表,并希望用自己独特的关键字标记每个句子,以帮助我确定哪些句子类似于分组目的。

举个例子:

The dog ran fast. - tagged as: dog
The cat is sleeping - tagged as: cat
The German Sheppard is awake. - tagged as dog

我一直在寻找像alchemy api和openCalais这样的关键字提取工具,但是,你似乎还可以使用这些工具来提取数据块中的含义,比如整个文档或段落,而不是标记1000个独特的但类似的个别句子。

简而言之,理想情况下我想:

  1. 从文档或网页中提取句子(可能来自大型电子表格或推文列表)
  2. 在其上放置一个唯一标识符(某种类型的关键字)
  3. 通过keywrd将句子组合在一起

1 个答案:

答案 0 :(得分:4)

我认为附加标识符的意思类似于nltk的POS-Tagging(词性)和词干。这是nltkbook的link,可能会帮助你。下载说明为here
选择的语言IMO应该是Python 我有一些你可能想要研究的例子:

词干

>>>import nltk
>>>from nltk.stem import PorterStemmer
>>>stemmer = PorterStemmer()
>>>stemmer.stem('cooking')
#'cook' 

创建词性标记词语料库

>>> from nltk.corpus.reader import TaggedCorpusReader
>>> reader = TaggedCorpusReader('.', r'.*\.pos')
>>> reader.words()
['The', 'expense', 'and', 'time', 'involved', 'are', ...]
>>> reader.tagged_words()
[('The', 'AT-TL'), ('expense', 'NN'), ('and', 'CC'), ...]
>>> reader.sents()
[['The', 'expense', 'and', 'time', 'involved', 'are', 'astronomical', '.']]
>>> reader.tagged_sents()
[[('The', 'AT-TL'), ('expense', 'NN'), ('and', 'CC'), ('time', 'NN'), ('involved', 'VBN'), ('are', 'BER'), ('astronomical', 'JJ'), ('.', '.')]]
>>> reader.paras()
[[['The', 'expense', 'and', 'time', 'involved', 'are', 'astronomical', '.']]]
>>> reader.tagged_paras()
[[[('The', 'AT-TL'), ('expense', 'NN'), ('and', 'CC'), ('time', 'NN'), ('involved', 'VBN'), ('are', 'BER'), ('astronomical', 'JJ'), ('.', '.')]]]

>>> from nltk.tokenize import SpaceTokenizer
>>> reader = TaggedCorpusReader('.', r'.*\.pos', word_tokenizer=SpaceTokenizer())
>>> reader.words()
['The', 'expense', 'and', 'time', 'involved', 'are', ...]

>>> from nltk.tokenize import LineTokenizer
>>> reader = TaggedCorpusReader('.', r'.*\.pos', sent_tokenizer=LineTokenizer())
>>> reader.sents()
[['The', 'expense', 'and', 'time', 'involved', 'are', 'astronomical', '.']]

>>> reader = TaggedCorpusReader('.', r'.*\.pos', tag_mapping_function=lambda t: t.lower())
>>> reader.tagged_words(simplify_tags=True)
[('The', 'at-tl'), ('expense', 'nn'), ('and', 'cc'), ...]

>>> from nltk.tag import simplify
>>> reader = TaggedCorpusReader('.', r'.*\.pos', tag_mapping_function=simplify.simplify_brown_tag)
>>> reader.tagged_words(simplify_tags=True)
[('The', 'DET'), ('expense', 'N'), ('and', 'CNJ'), ...]
>>> reader = TaggedCorpusReader('.', r'.*\.pos', tag_mapping_function=simplify.simplify_tag)
>>> reader.tagged_words(simplify_tags=True)
[('The', 'A'), ('expense', 'N'), ('and', 'C'), ...]

以上两个代码示例来自nltk的书籍示例。我张贴了这样你无论是否使用都可以以面值表示 根据两个功能的组合思考。它们是否符合您的目的?
此外,您可能需要查看 STOPWORDS ,以便从您给出的第一句话中获取Dog。