Logo Search packages:      
Sourcecode: parley version File versions  Download package

void AnswerValidatorOld::defaultCorrector (  ) [private]

Default correction mechanism.

Todo:
does not work completely yet.
Todo:
can solution.length() be zero? *should* be caught by Parley

Definition at line 207 of file answervalidatorold.cpp.

References TestEntry::AccentMistake, TestEntry::ArticleMissing, TestEntry::ArticleWrong, TestEntry::CapitalizationMistake, TestEntry::Correct, TestEntry::Empty, m_doc, m_entry, m_solution, m_userAnswer, sentenceAnalysis(), TestEntry::Synonym, and wordCompare().

Referenced by checkUserAnswer().

{
    ///@todo does not work completely yet.
    ///@todo can solution.length() be zero? *should* be caught by Parley
    if ( m_solution == m_userAnswer ) {
        m_entry->setLastErrors(TestEntry::Correct);
        m_entry->setLastPercentage(1.0);
        return;
    }

    if ( m_userAnswer.isEmpty() ) {
        m_entry->setLastErrors(TestEntry::Empty);
        m_entry->setLastPercentage(0.0);
        return;
    }

    if ( m_solution.toLower() == m_userAnswer.toLower() ) {
        if (Prefs::ignoreCapitalizationMistakes()) {
            m_entry->setLastPercentage(1.0);
        } else {
            m_entry->setLastPercentage(1.0 - CAPITALIZATION_MISTAKE_PUNISHMENT);
        }
        m_entry->setLastErrors(TestEntry::CapitalizationMistake);
        return ;
    }

    if ( ParleyStringHandlerOld::stripAccents(m_solution) == ParleyStringHandlerOld::stripAccents(m_userAnswer) ) {
        if (Prefs::ignoreAccentMistakes()) {
            m_entry->setLastPercentage(1.0);
        } else {
            m_entry->setLastPercentage(1.0 - ACCENT_MISTAKE_PUNISHMENT);
        }
        m_entry->setLastErrors(TestEntry::AccentMistake);
        return ;
    }

    foreach(KEduVocTranslation *synonym, m_entry->entry()->translation(m_translation)->synonyms()) {
        if (synonym->text() == m_userAnswer) {
            m_entry->setLastErrors(TestEntry::Synonym);
            if ( Prefs::countSynonymsAsCorrect() ) {
                m_entry->setLastPercentage(1.0);
            } else {
                m_entry->setLastPercentage(0.0); // bit harsh maybe
            }
            return;
        }
    }

    int numberSolutionWords = m_solution.simplified().split(' ').count();
    int numberAnswerWords = m_userAnswer.simplified().split(' ').count();

    if ( numberSolutionWords == 1 ) {
        double grade;
        TestEntry::ErrorTypes errors;
        wordCompare(m_solution, m_userAnswer, grade, errors);
        m_entry->setLastPercentage(grade);
        m_entry->setLastErrors(errors);
        return;
    }

    if ( numberSolutionWords == 2 ) {
        // could be noun + article
        QStringList solutionWords = m_solution.simplified().split(' ');

        if ( m_translation >= 0 ) {
            if (m_doc->identifier(m_translation).article().isArticle(solutionWords.value(0)) ) {
                // yes, the answer is an article + noun
                if ( numberAnswerWords == 1 ) {
                    double percent;
                    TestEntry::ErrorTypes errors;
                    wordCompare(solutionWords.value(1), m_userAnswer.simplified(), percent, errors);
                    m_entry->setLastPercentage(qMax(percent-WRONG_ARTICLE_PUNISHMENT, 0.0));
                    m_entry->setLastErrors(errors|TestEntry::ArticleMissing);
                    return;
                }
                if ( numberAnswerWords == 2 ) {
                    double percent;
                    TestEntry::ErrorTypes errors;
                    wordCompare(solutionWords.value(1), m_userAnswer.simplified().split(' ').value(1), percent, 
errors);

                    if ( m_userAnswer.simplified().split(' ').value(0) == solutionWords.value(0) ) {
                        m_entry->setLastErrors(errors);
                    } else {
                        m_entry->setLastPercentage(qMax(percent-WRONG_ARTICLE_PUNISHMENT, 0.0));
                        m_entry->setLastErrors(errors|TestEntry::ArticleWrong);
                    }
                    return;
                }
            }
        }
    }

    // ok, more than one word (or one+article)
    sentenceAnalysis();
}

Here is the call graph for this function:

Here is the caller graph for this function:


Generated by  Doxygen 1.6.0   Back to index