与NLP中的词干相关的查询

问题描述 投票:-2回答:1

我正在基于使用python在NLP下进行词干处理的动手任务。

下面是需要逐步执行以获取结果的任务。

我已经完成到第13步,并陷入了第14和15步(请参阅下文)。

[请帮助我了解如何执行步骤14和15。

TASK

  1. 导入文本语料库棕色

  2. 提取与属于幽默体裁的文本集合相关的单词列表。将结果存储到变量humor_words

  3. 将列表幽默单词中的每个单词转换为小写,并将结果存储在lc_humor_words中。

  4. 查找lc_humor_words中存在的唯一单词的列表。将结果存储在lc_humor_uniq_words

  5. 导入语料库words

  6. 提取与语料库单词关联的单词列表。将结果存储在变量wordlist_words

  7. 查找wordlist_words中存在的唯一单词的列表。将结果存储在wordlist_uniq_words

  8. 创建名为porter的PorterStemmer的实例。

  9. 创建名为lancaster的LancasterStemmer的实例。

  10. 将带有搬运工实例的每个单词出现在lc_humor_uniq_words中,并将结果存储在列表中[

  11. ]
  12. 使用兰开斯特实​​例阻止

    lc_humor_uniq_words

  13. 中存在的每个单词,并将结果存储在listl_stemmed`]
  14. p_stemmed

  15. 过滤词干的词,这些词也出现在wordlist_uniq_words中。将结果存储在p_stemmed_in_wordlist中。
  16. l_stemmed

  17. 过滤词干的词,这些词也出现在wordlist_uniq_words中。将结果存储到l_stemmed_in_wordlist
  18. lc_humor_uniq_words]中过滤单词,这些单词的长度与其在p_stemmed中出现的相应词干的长度相同,并且还包含至少一个与相应词干的字符不同的字符。将结果存储在列表中[

  19. lc_humor_uniq_words]中过滤单词,其长度与在[[l_stemmed
  20. 中出现的其对应词干相同,并且还包含至少一个与相应词干不同的字符。将结果存储在列表

    l_stemmed_diff

    。] >>
    打印p_stemmed_diff中出现的单词数。
  21. 打印l_stemmed_diff中出现的单词数。

  22. -下面是我在第13步之前完成的步骤。

    import nltk import nltk.corpus from nltk.corpus import brown humor_words = brown.words(categories = 'humor') lc_humor_words = [w.lower() for w in humor_words] lc_humor_uniq_words = set(lc_humor_words) from nltk.corpus import words wordlist_words = words.words() wordlist_uniq_words = set(wordlist_words) from nltk.stem import PorterStemmer porter = PorterStemmer() from nltk.stem import LancasterStemmer lancaster = LancasterStemmer() p_stemmed = [] for word in lc_humor_uniq_words: p_stemmed.append(porter.stem(word)) l_stemmed = [] for wordd in lc_humor_uniq_words: l_stemmed.append(lancaster.stem(wordd)) p_stemmed_in_wordlist = [word1 for word1 in p_stemmed if word1 in wordlist_uniq_words] l_stemmed_in_wordlist = [word2 for word2 in l_stemmed if word2 in wordlist_uniq_words]

我正在使用python在NLP下基于词干进行动手操作。以下是需要逐步执行以获取结果的任务。我已经完成到第13步,并得到了...

将下面的代码用于步骤14-17
p_stemmed_diff=[] for w1,w2 in zip(lc_humor_uniq_words,p_stemmed): if len(w1) == len(w2) and w1 != w2: p_stemmed_diff.append(w1) l_stemmed_diff=[] for w1,w2 in zip(lc_humor_uniq_words,l_stemmed): if len(w1) == len(w2) and w1 != w2: l_stemmed_diff.append(w1) print(len(p_stemmed_diff)) print(len(l_stemmed_diff))
nlp nltk python-3.7 stemming
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.