簡體   English   中英

NLTK中的小寫停用詞並將停用詞存儲在列表中

[英]lowercase stop-words in NLTK and storing the stop-words in the list

我親愛的朋友們,我想知道如何在名為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']

嘗試這個:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM