<commit_before>class WordCloudOp:

    def run(self, data):
        terms = { }
        results = [ ]
        try:
            for corpus in data:
                tokens = corpus.tokenized_contents
                for token in tokens:
                    if token in terms:
                        terms[token]+=1
                    else:
                        terms[token]=1
            for term in terms:
                results.append({ "term" : term, "frequency" : terms[term]})
            return results
        except LookupError:
            raise TransactionException('NLTK \'Punkt\' Model not installed.', 500)
        except TypeError:
            raise TransactionException('Corpus contents does not exist.')
<commit_msg>Sort term frequency results by frequency<commit_after>class WordCloudOp:

    def run(self, data):
        terms = { }
        results = [ ]
        try:
            for corpus in data:
                tokens = corpus.tokenized_contents
                for token in tokens:
                    if token in terms:
                        terms[token]+=1
                    else:
                        terms[token]=1
            for term in terms:
                results.append({ "term" : term, "frequency" : terms[term]})

            #sort results by term frequency
            results.sort(key=lambda results: results['frequency'], reverse=False)
            
            return results
        except LookupError:
            raise TransactionException('NLTK \'Punkt\' Model not installed.', 500)
        except TypeError:
            raise TransactionException('Corpus contents does not exist.')

{'fraction_non_alphanumeric': 0.08053691275167785, 'fraction_numerical': 0.006101281269066504, 'mean_word_length': 1.4404761904761905, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '493740', 'n_tokens_mistral': 398, 'n_tokens_neox': 368, 'n_words': 120}