어쩌면 이것은 어리석은 질문 일지 모르지만, 파이썬으로 가장 자주 나오는 단어 10 개를 추출하는 데 문제가 있습니다. 이것은 내가 지금까지 가지고있는 것이다. 뒤에파이썬으로 자료에서 가장 빈번한 단어 추출하기
import re
import string
from nltk.corpus import stopwords
stoplist = stopwords.words('dutch')
from collections import defaultdict
from operator import itemgetter
def toptenwords(mycorpus):
words = mycorpus.words()
no_capitals = set([word.lower() for word in words])
filtered = [word for word in no_capitals if word not in stoplist]
no_punct = [s.translate(None, string.punctuation) for s in filtered]
wordcounter = {}
for word in no_punct:
if word in wordcounter:
wordcounter[word] += 1
else:
wordcounter[word] = 1
sorting = sorted(wordcounter.iteritems(), key = itemgetter, reverse = True)
return sorting
내 시체와 함께이 기능을 인쇄하는 경우, 그것은 '1'로 나에게 모든 단어의 목록을 제공 (BTW, 나는 각 10 개 .txt 인 파일을 두 개의 하위 범주와 신체를 읽는 NLTK 작업) 그것. 그것은 나에게 사전을 주지만 모든 나의 가치관은 하나입니다. 그리고 예를 들어 '아기'라는 단어가 내 코퍼스에서 5 ~ 6 번이라는 것을 알고 있습니다. 그리고 여전히 '아기 : 1'을 제공합니다 ... 따라서 원하는 방식으로 작동하지 않습니다.
Can 누군가 나를 도울까요?
내가 몇 달 전과 똑같은 일을했기 때문에 무엇을 공부하고 있습니까? – Amberlamps
나는 언어학을 공부하고있다. 그 일을 해결 했니? – user2007220