<commit_before>package info.puzz.a10000sentences.activities;

import android.content.Context;
import android.databinding.BaseObservable;
import android.preference.Preference;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import info.puzz.a10000sentences.Preferences;
import info.puzz.a10000sentences.models.Sentence;
import info.puzz.a10000sentences.utils.StringUtils;
import info.puzz.a10000sentences.utils.WordChunk;
import temp.DBG;

public class SentenceQuiz extends BaseObservable {

    private final List<WordChunk> chunks;
    private final List<String> vocabChunks;
    private final Sentence sentence;
    private int currentChunk;
    public String[] answers;

    int incorrectAnswersGiven = 0;
    int correctAnswersGiven = 0;
    private int currentKnownSentenceAlternative = 0;

    public SentenceQuiz(Sentence sentence, int answersNo, List<Sentence> randomSentencesForVocab) {
        this.sentence = sentence;
        chunks = StringUtils.getWordChunks(sentence.targetSentence);
        currentChunk = 0;
        answers = new String[answersNo];
        vocabChunks = new ArrayList<>();
        DBG.todo("Check if empty");
        for (Sentence s : randomSentencesForVocab) {
            for (WordChunk wch : StringUtils.getWordChunks(s.targetSentence)) {
                vocabChunks.add(wch.word);
            }
        }
        resetRandomAnswers();
    }

    public String getQuizSentence() {
        StringBuilder res = new StringBuilder();
        for (int i = 0; i < chunks.size(); i++) {
            if (res.length() > 0) {
                res.append(" ");
            }
            WordChunk chunk = chunks.get(i);
            if (i >= currentChunk) {
                res.append(chunk.chunk.replace(chunk.word, StringUtils.repeat('_', 3)));
            } else {
                res.append(chunk.chunk);
            }
        }
        return res.toString();
    }
    
    public String getKnownSentence() {
        String[] knownSentences = sentence.getKnownSentences();
        return knownSentences[currentKnownSentenceAlternative % knownSentences.length];
    }

    public void nextKnownSentenceAlternative() {
        ++ currentKnownSentenceAlternative;
        notifyChange();
    }

    public boolean guessWord(String word) {
        if (isFinished()) {
            return false;
        }
        boolean guessed = StringUtils.equalsIgnoreCase(chunks.get(currentChunk).word, word);
        if (guessed) {
            ++ currentChunk;
            resetRandomAnswers();
            notifyChange();
            ++ correctAnswersGiven;
        } else {
            ++ incorrectAnswersGiven;
        }
        return guessed;
    }
<commit_msg>Reload icon if known sentence has alternatives<commit_after>package info.puzz.a10000sentences.activities;

import android.content.Context;
import android.databinding.BaseObservable;
import android.preference.Preference;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import info.puzz.a10000sentences.Preferences;
import info.puzz.a10000sentences.models.Sentence;
import info.puzz.a10000sentences.utils.StringUtils;
import info.puzz.a10000sentences.utils.WordChunk;
import temp.DBG;

public class SentenceQuiz extends BaseObservable {

    private final List<WordChunk> chunks;
    private final List<String> vocabChunks;
    private final Sentence sentence;
    private int currentChunk;
    public String[] answers;

    int incorrectAnswersGiven = 0;
    int correctAnswersGiven = 0;
    private int currentKnownSentenceAlternative = 0;

    public SentenceQuiz(Sentence sentence, int answersNo, List<Sentence> randomSentencesForVocab) {
        this.sentence = sentence;
        chunks = StringUtils.getWordChunks(sentence.targetSentence);
        currentChunk = 0;
        answers = new String[answersNo];
        vocabChunks = new ArrayList<>();
        DBG.todo("Check if empty");
        for (Sentence s : randomSentencesForVocab) {
            for (WordChunk wch : StringUtils.getWordChunks(s.targetSentence)) {
                vocabChunks.add(wch.word);
            }
        }
        resetRandomAnswers();
    }

    public String getQuizSentence() {
        StringBuilder res = new StringBuilder();
        for (int i = 0; i < chunks.size(); i++) {
            if (res.length() > 0) {
                res.append(" ");
            }
            WordChunk chunk = chunks.get(i);
            if (i >= currentChunk) {
                res.append(chunk.chunk.replace(chunk.word, StringUtils.repeat('_', 3)));
            } else {
                res.append(chunk.chunk);
            }
        }
        return res.toString();
    }
    
    public String getKnownSentence() {
        String[] knownSentences = sentence.getKnownSentences();
        String res = knownSentences[currentKnownSentenceAlternative % knownSentences.length];
        if (knownSentences.length > 1) {
            res += "  {fa-refresh}";
        }
        return res;
    }

    public void nextKnownSentenceAlternative() {
        ++ currentKnownSentenceAlternative;
        notifyChange();
    }

    public boolean guessWord(String word) {
        if (isFinished()) {
            return false;
        }
        boolean guessed = StringUtils.equalsIgnoreCase(chunks.get(currentChunk).word, word);
        if (guessed) {
            ++ currentChunk;
            resetRandomAnswers();
            notifyChange();
            ++ correctAnswersGiven;
        } else {
            ++ incorrectAnswersGiven;
        }
        return guessed;
    }

{'fraction_non_alphanumeric': 0.09721973094170404, 'fraction_numerical': 0.011659192825112108, 'mean_word_length': 2.4590570719602978, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 16, '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': '537951', 'n_tokens_mistral': 1644, 'n_tokens_neox': 1522, 'n_words': 326}