2012-09-06 3 views
0

사랑하는 친구들이 할 수있는 내가 목록에 이름 토큰소문자 스톱 단어 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'] 
+0

'lower'다음에 괄호가 없음을 확인합니다. 그러므로 당신은 그 결과가 아닌 그 기능을 언급하고 있습니다. –

답변

1

이 시도를 NLTK에서 중지 단어를 소문자 방법을 알고 :

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

답해 주셔서 고맙습니다.하지만 똑같은 일을하는 데는 비효율적 이었지만 효과적인 방법에 대해 생각했습니다. 나는 '영어'라는 정지 단어를 조작하고 일반 소문자의 복사본을 만들고 같은 텍스트를 대문자로 만들면 그럴 것이라고 생각했습니다. 너희들이 제안하는 것과 똑같은 일을해라.하지만 너의 도움을 많이 주셔서 감사합니다. –

관련 문제