Search in sources :

Example 1 with Tuc

use of com.ichi2.anki.multimediacard.glosbe.json.Tuc in project Anki-Android by Ramblurr.

the class TranslationActivity method parseJson.

private static ArrayList<String> parseJson(Response resp, String languageCodeTo) {
    ArrayList<String> res = new ArrayList<String>();
    /*
         * The algorithm below includes the parsing of glosbe results. Glosbe.com returns a list of different phrases in
         * source and destination languages. This is done, probably, to improve the reader's understanding. We leave
         * here only the translations to the destination language.
         */
    List<Tuc> tucs = resp.getTuc();
    if (tucs == null) {
        return res;
    }
    for (Tuc tuc : tucs) {
        if (tuc == null) {
            continue;
        }
        List<Meaning> meanings = tuc.getMeanings();
        if (meanings != null) {
            for (Meaning meaning : meanings) {
                if (meaning == null) {
                    continue;
                }
                if (meaning.getLanguage() == null) {
                    continue;
                }
                if (meaning.getLanguage().contentEquals(languageCodeTo)) {
                    String unescappedString = HtmlUtil.unescape(meaning.getText());
                    res.add(unescappedString);
                }
            }
        }
        Phrase phrase = tuc.getPhrase();
        if (phrase != null) {
            if (phrase.getLanguageCode() == null) {
                continue;
            }
            if (phrase.getLanguageCode().contentEquals(languageCodeTo)) {
                String unescappedString = HtmlUtil.unescape(phrase.getText());
                res.add(unescappedString);
            }
        }
    }
    return res;
}
Also used : Tuc(com.ichi2.anki.multimediacard.glosbe.json.Tuc) ArrayList(java.util.ArrayList) Phrase(com.ichi2.anki.multimediacard.glosbe.json.Phrase) Meaning(com.ichi2.anki.multimediacard.glosbe.json.Meaning)

Aggregations

Meaning (com.ichi2.anki.multimediacard.glosbe.json.Meaning)1 Phrase (com.ichi2.anki.multimediacard.glosbe.json.Phrase)1 Tuc (com.ichi2.anki.multimediacard.glosbe.json.Tuc)1 ArrayList (java.util.ArrayList)1