Exemple #1
0
def generate_article_score(content):
    ATD.setDefaultKey(settings.ATD_API_KEY)
    metrics = ATD.stats(content)
    error_types = ['grammar','spell','style']
    error_count = 0
    word_count = 0
    grammar_error_count = 0
    spell_error_count = 0
    style_error_count = 0
    for m in metrics:
        if m.type in error_types:
            error_count+=m.value
        if m.type == error_types[0]:
            grammar_error_count+=m.value
        if m.type == error_types[1]:
            spell_error_count+=m.value
        if m.type == error_types[2]:
            style_error_count+=m.value
        if m.type == 'stats' and m.key == 'words':
            word_count = m.value
    return_dict = {
        'error_count':error_count,
        'word_count':word_count,
        'grammar_error_count': grammar_error_count,
        'spell_error_count': spell_error_count,
        'style_error_count': style_error_count,
    }
    return return_dict
Exemple #2
0
def check_grammar(text):
    ATD.setDefaultKey("ENTER_YOUR_API_KEY")
    metrics = ATD.stats(text)
    spell_count = 0
    grammar_count = 0
    for i in [str(m) for m in metrics]:
        if is_subseq('spell', i):
            spell_count += int(re.search(r'[\d]+', i).group(0))
        elif is_subseq('grammar', i):
            grammar_count += int(re.search(r'[\d]+', i).group(0))

    return [grammar_count, spell_count]