두 번 이상 나타나는 트라이 그램으로 정의 된 텍스트에서 "일반적으로 사용되는 구"를 얻고 싶습니다. 내가 scored
의 요소의 수는 총 단어 수로 나눈 괘의 발생 횟수는 것으로 나타났습니다NLTK에서 트라이 그램의 발생 횟수를 얻으십시오
[(('This', 'is', 'a'), 0.2), (('Hello', 'world', 'This'), 0.1), (('a', 'dog', 'This'), 0.1), (('dog', 'This', 'is'), 0.1), (('is', 'a', 'cat'), 0.1), (('is', 'a', 'dog'), 0.1), (('world', 'This', 'is'), 0.1)]
import nltk
def get_words(string):
tokenizer = nltk.tokenize.RegexpTokenizer(r'\w+')
return tokenizer.tokenize(string)
string = "Hello, world. This is a dog. This is a cat."
words = get_words(string)
finder = nltk.collocations.TrigramCollocationFinder.from_words(words)
scored = finder.score_ngrams(nltk.collocations.TrigramAssocMeasures().raw_freq)
결과 scored
입니다 : 지금까지 나는이 있습니다 (이 경우 10). 단어 수로 '사후 배수'하지 않고 직접 발생 횟수를 얻을 수있는 방법이 있습니까?
[NLTK - Bigram의 계산 빈도] 가능한 복제본 (http://stackoverflow.com/questions/19145332/nltk-counting-frequency-of-bigram) –