def extract(self, sample):
        result = FeatureResult(self._short_name)
        num_syllables = []
        
        words = self._get_words(sample)

        # Create a list of the number of syllables of each word
        for word in words :
            num_syllables.append(syllables_en.count(word))
        
        result.value = float(sum(num_syllables)) / float(len(words))

        return [result]
Exemple #2
0
    def __analyze_text(self,  sample):
        """ Calculates a few properties that are needed for analysis"""
        words = self._get_words(sample)

        self.word_count = len(words)
        self.char_count = len(sample.plain_text)
        
        for word in words:
            self.syllable_count += syllables_en.count(word)
        
        self.sentence_count = len(nltk.sent_tokenize(sample.plain_text))
        
        self.avg_words_per_sentence = float(self.word_count) / \
                                      float(self.sentence_count)
Exemple #3
0
def count_syllables(lines):
    """Syllables in a line for each line"""
    return np.array(list(syllables.count(l) for l in lines))
Exemple #4
0
 def nsyl(self, word):
     return SE.count(word)