File indexing completed on 2024-04-14 03:49:12

0001 /*
0002     SPDX-FileCopyrightText: 2010 Benjamin Schleinzer <ben-kde@schleinzer.eu>
0003     SPDX-FileCopyrightText: 2007-2010 Frederik Gladhorn <gladhorn@kde.org>
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 #ifndef WRITTENPRACTICEVALIDATOR_H
0007 #define WRITTENPRACTICEVALIDATOR_H
0008 
0009 #include <Sonnet/Speller>
0010 
0011 #include "parleydocument.h"
0012 
0013 #include "testentry.h"
0014 
0015 namespace Practice
0016 {
0017 class WrittenPracticeValidator
0018 {
0019 public:
0020     WrittenPracticeValidator(int translation, KEduVocDocument *doc);
0021     ~WrittenPracticeValidator();
0022 
0023     void setEntry(TestEntry *entry);
0024     void validateAnswer(const QString &answer);
0025     bool spellcheckerAvailable();
0026     QString getCorrectedAnswer();
0027 
0028 private:
0029     void setLanguage(int translation);
0030 
0031     /** Simple check if the words are the same */
0032     bool isCorrect(const QString &correct, const QString &answer);
0033 
0034     /** Check if the answer is a synonym of the testentry
0035      *  also check for capitalization mistakes and accent mistakes
0036      *  if the option is set */
0037     bool isSynonymMistake(const QString &answer);
0038 
0039     /** Check if the answer is a punctuation mistakes */
0040     bool isPunctuationMistake(const QString &original, const QString &answer);
0041 
0042     /** Check if the answer is a capitalization mistakes */
0043     bool isCapitalizationMistake(const QString &original, const QString &answer);
0044 
0045     /** Check is an accent mistake was made. Take capitalization into account
0046      * if the option was set in the preferences */
0047     bool isAccentMistake(const QString &original, const QString &answer);
0048 
0049     TestEntry *m_entry{nullptr};
0050     KEduVocDocument *m_doc{nullptr};
0051     QString m_correctedAnswer;
0052     int m_translation{0};
0053     TestEntry::ErrorTypes m_error;
0054 
0055     /// spellchecker
0056     Sonnet::Speller *m_speller{nullptr};
0057     bool m_spellerAvailable{false};
0058 };
0059 
0060 }
0061 
0062 #endif // WRITTENPRACTICEVALIDATOR_H