示例#1
0
def flesch_index(text):
    sentences = sent_tokenize(text)

    total_sentences = len(sentences)
    total_words = np.sum([word_count(s) for s in sentences])
    total_syllables = np.sum([ np.sum([ syllable_count(w) for w in word_tokenize(s) ]) \
                              for s in sentences ])

    return 0.39*(total_words/total_sentences) + \
            11.8*(total_syllables/total_words) - 15.59
def find_wiki_page(syllable_constraint=5):

    while True:

        tmp = wikipedia.random()

        if syllable_count.syllable_count(tmp) == syllable_constraint\
                and not forbidden_phrases_in_result(tmp):

            return tmp
示例#3
0
def hard_word_count(sent):
    return len([ w for w in word_tokenize(sent) \
                if syllable_count(wnl.lemmatize(w, pos='v'))>=3 ])