def max_content_density(self): """ Returns the Max Content Density. Content Density is the ratio of open class words to closed class words. """ if self.__max_cdensity is None: if self.__treestrings is None: self.__treestrings = self.treestrings() self.__cdensity, self.__min_cdensity, self.__max_cdensity = cUtil.calc_content_density(self.treestrings()) return self.__max_cdensity
def max_content_density(self): """ Returns the Max Content Density. Content Density is the ratio of open class words to closed class words. """ if self.__max_cdensity is None: if self.__treestrings is None: self.__treestrings = self.treestrings() self.__cdensity, self.__min_cdensity, self.__max_cdensity = cUtil.calc_content_density( self.treestrings()) return self.__max_cdensity
def run(self, data): results = [] try: for corpus in data: split_string = corpus.contents.split(" ") temp_corpus = list(filter("{SL}".__ne__, split_string)) temp_corpus = list(filter("{sl}".__ne__, temp_corpus)) temp_corpus_contents = " ".join(temp_corpus) # print(corpus.contents) temp_bubble = SPLAT(temp_corpus_contents) temp_trees = TreeStringParser().get_parse_trees( temp_bubble.sents()) # print(temp_bubble.splat()) # cdensity = temp_bubble.content_density() cdensity = cUtil.calc_content_density(temp_trees) print(cdensity) # print(temp_bubble.treestrings()) # idensity = temp_bubble.idea_density() idensity = cUtil.calc_idea_density(temp_trees)[0] # print(idensity) flesch_score = temp_bubble.flesch_readability() # print(flesch_score) kincaid_score = temp_bubble.kincaid_grade_level() # print(kincaid_score) types = len(temp_bubble.types()) tokens = len(temp_bubble.tokens()) type_token_ratio = float(float(types) / float(tokens)) results.append({ 'corpus_id': corpus.id, 'content_density': cdensity, 'idea_density': idensity, 'flesch_score': flesch_score, 'kincaid_score': kincaid_score, 'types': types, 'tokens': tokens, 'type_token_ratio': type_token_ratio }) results = json.dumps(results) # print(results) return results except TypeError as e: print(e) raise TransactionException('Corpus contents does not exist.')