【问题标题】:lowercase stop-words in NLTK and storing the stop-words in the listNLTK 中的小写停用词并将停用词存储在列表中
【发布时间】:2019-01-10 16:03:48
【问题描述】:

亲爱的朋友们,我想知道如何在名为 tokens 的列表中小写 NLTK 中的停用词

import nltk
from nltk.corpus import stopwords
tokens= ['TOWING', 'VESSEL', 'XXXX', 'XXXX', 'XXXX', 'WAS', 'FACING', 'UP', 'TO', 'BARGES', 'IN', 'MON', 'VIEW', 'MININGS', 'FLEET', 'WHEN', 'WIRE', 'CABLE', 'AT', 'THE', 'CELL', 'PARTED', 'STRIKING', 'XXX', 'XXX', 'IN', 'THE', 'LEFT', 'FOREARM', 'LUNDY', 'WAS', 'TAKEN', 'TO', 'THE', 'HOSPITAL', 'VIA', 'AMBULANCE', 'AND', 'DIAGNOSED', 'WITH', 'XXX']

stop_list = ['all', 'just', 'being', 'over', 'both', 'through', 'yourselves', 'its', 'before', 'herself', 'had', 'should', 'to', 'only', 'under', 'ours', 'has', 'do', 'them', 'his', 'very', 'they',
         'not', 'during', 'now', 'him', 'nor', 'did', 'this', 'she', 'each', 'further', 'where', 'few', 'because', 'doing', 'some', 'are', 'our', 'ourselves', 'out', 'what', 'for', 'while', 'does', 'above', 'between', 't',
         'be', 'we', 'who', 'were', 'here', 'hers', 'by', 'on', 'about', 'of', 'against', 's', 'or', 'own', 'into', 'yourself', 'down', 'your', 'from', 'her', 'their', 'there', 'been', 'whom', 'too', 'themselves', 'was',
         'until', 'more', 'himself', 'that', 'but', 'don', 'with', 'than', 'those', 'he', 'me', 'myself', 'these', 'up', 'will', 'below', 'can', 'theirs', 'my', 'and', 'then', 'is', 'am', 'it', 'an', 'as', 'itself', 'at',
         'have', 'in', 'any', 'if', 'again', 'no', 'when', 'same', 'how', 'other', 'which', 'you', 'after', 'most', 'such', 'why', 'a', 'off', 'i', 'yours', 'so', 'the', 'having', 'once']

english_stops = set(stopwords.words('english'))
for coid in range(0,len(english_stops)):
for coidrec in range(0,len(tokens)):
    if tokens[coidrec].isupper():
        if tokens[coidrec].lower == stop_list[coid]:
            tokens[i].lower
        else:
            pass
tokens
['TOWING', 'VESSEL', 'XXXX', 'XXXX', 'XXXX', 'WAS', 'FACING', 'UP', 'TO', 'BARGES', 'IN', 'MON', 'VIEW', 'MININGS', 'FLEET', 'WHEN', 'WIRE', 'CABLE', 'AT', 'THE', 'CELL', 'PARTED', 'STRIKING', 'XXX', 'XXX', 'IN', 'THE', 'LEFT', 'FOREARM', 'LUNDY', 'WAS', 'TAKEN', 'TO', 'THE', 'HOSPITAL', 'VIA', 'AMBULANCE', 'AND', 'DIAGNOSED', 'WITH', 'XXX']

【问题讨论】:

  • 我注意到lower 后面没有括号。因此,您指的是函数而不是其结果。

标签: python nltk stop-words


【解决方案1】:

试试这个:

tokens = [token.lower() for token in tokens]

【讨论】:

  • 感谢您的回答,但我想到了一种粗略但有效的方法来做同样的事情,我想如果我操纵停用词“英语”并复制常规的小写文本和大写相同的文字然后它也会做同样的事情,但我真的很感谢你们的帮助,非常感谢你们。
猜你喜欢
  • 2014-05-10
  • 2020-07-08
  • 2021-02-02
  • 2018-04-05
  • 2019-01-03
  • 2015-05-30
  • 1970-01-01
  • 2018-07-21
  • 2019-01-12
相关资源
最近更新 更多