Search in sources :

Example 6 with Allophone

use of ai.elimu.model.content.Allophone in project webapp by elimu-ai.

the class JavaToGsonConverter method getSyllableGson.

public static SyllableGson getSyllableGson(Syllable syllable) {
    if (syllable == null) {
        return null;
    } else {
        SyllableGson syllableGson = new SyllableGson();
        syllableGson.setId(syllable.getId());
        syllableGson.setLocale(syllable.getLocale());
        syllableGson.setTimeLastUpdate(syllable.getTimeLastUpdate());
        syllableGson.setRevisionNumber(syllable.getRevisionNumber());
        syllableGson.setContentStatus(syllable.getContentStatus());
        syllableGson.setText(syllable.getText());
        List<AllophoneGson> allophones = new ArrayList<>();
        for (Allophone allophone : syllable.getAllophones()) {
            AllophoneGson allophoneGson = getAllophoneGson(allophone);
            allophones.add(allophoneGson);
        }
        syllableGson.setAllophones(allophones);
        syllableGson.setUsageCount(syllable.getUsageCount());
        return syllableGson;
    }
}
Also used : AllophoneGson(ai.elimu.model.gson.content.AllophoneGson) Allophone(ai.elimu.model.content.Allophone) SyllableGson(ai.elimu.model.gson.content.SyllableGson) ArrayList(java.util.ArrayList)

Example 7 with Allophone

use of ai.elimu.model.content.Allophone in project webapp by elimu-ai.

the class JavaToGsonConverter method getWordGson.

public static WordGson getWordGson(Word word) {
    if (word == null) {
        return null;
    } else {
        WordGson wordGson = new WordGson();
        wordGson.setId(word.getId());
        wordGson.setLocale(word.getLocale());
        wordGson.setTimeLastUpdate(word.getTimeLastUpdate());
        wordGson.setRevisionNumber(word.getRevisionNumber());
        wordGson.setContentStatus(word.getContentStatus());
        wordGson.setText(word.getText());
        wordGson.setPhonetics(word.getPhonetics());
        List<AllophoneGson> allophones = new ArrayList<>();
        for (Allophone allophone : word.getAllophones()) {
            AllophoneGson allophoneGson = getAllophoneGson(allophone);
            allophones.add(allophoneGson);
        }
        wordGson.setAllophones(allophones);
        wordGson.setUsageCount(word.getUsageCount());
        wordGson.setWordType(word.getWordType());
        wordGson.setSpellingConsistency(word.getSpellingConsistency());
        return wordGson;
    }
}
Also used : WordGson(ai.elimu.model.gson.content.WordGson) AllophoneGson(ai.elimu.model.gson.content.AllophoneGson) Allophone(ai.elimu.model.content.Allophone) ArrayList(java.util.ArrayList)

Example 8 with Allophone

use of ai.elimu.model.content.Allophone in project webapp by elimu-ai.

the class JavaToGsonConverter method getLetterGson.

public static LetterGson getLetterGson(Letter letter) {
    if (letter == null) {
        return null;
    } else {
        LetterGson letterGson = new LetterGson();
        letterGson.setId(letter.getId());
        letterGson.setLocale(letter.getLocale());
        letterGson.setTimeLastUpdate(letter.getTimeLastUpdate());
        letterGson.setRevisionNumber(letter.getRevisionNumber());
        letterGson.setContentStatus(letter.getContentStatus());
        letterGson.setText(letter.getText());
        List<AllophoneGson> allophones = new ArrayList<>();
        for (Allophone allophone : letter.getAllophones()) {
            AllophoneGson allophoneGson = getAllophoneGson(allophone);
            allophones.add(allophoneGson);
        }
        letterGson.setAllophones(allophones);
        letterGson.setBraille(letter.getBraille());
        letterGson.setUsageCount(letter.getUsageCount());
        return letterGson;
    }
}
Also used : AllophoneGson(ai.elimu.model.gson.content.AllophoneGson) Allophone(ai.elimu.model.content.Allophone) ArrayList(java.util.ArrayList) LetterGson(ai.elimu.model.gson.content.LetterGson)

Example 9 with Allophone

use of ai.elimu.model.content.Allophone in project webapp by elimu-ai.

the class AllophoneRestController method list.

@RequestMapping("/list")
public String list(HttpServletRequest request, @RequestParam String deviceId, // TODO: checksum,
@RequestParam Locale locale) {
    logger.info("list");
    logger.info("request.getQueryString(): " + request.getQueryString());
    JSONArray allophones = new JSONArray();
    for (Allophone allophone : allophoneDao.readAllOrdered(locale)) {
        AllophoneGson allophoneGson = JavaToGsonConverter.getAllophoneGson(allophone);
        String json = new Gson().toJson(allophoneGson);
        allophones.put(new JSONObject(json));
    }
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("result", "success");
    jsonObject.put("allophones", allophones);
    logger.info("jsonObject: " + jsonObject);
    return jsonObject.toString();
}
Also used : JSONObject(org.json.JSONObject) Allophone(ai.elimu.model.content.Allophone) AllophoneGson(ai.elimu.model.gson.content.AllophoneGson) JSONArray(org.json.JSONArray) AllophoneGson(ai.elimu.model.gson.content.AllophoneGson) Gson(com.google.gson.Gson) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with Allophone

use of ai.elimu.model.content.Allophone in project webapp by elimu-ai.

the class AllophoneUsageCountScheduler method execute.

// At 06:30 every day
@Scheduled(cron = "00 30 06 * * *")
public synchronized void execute() {
    logger.info("execute");
    for (Locale locale : Locale.values()) {
        logger.info("Calculating usage count of Allophones for locale " + locale);
        Map<String, Integer> allophoneFrequencyMap = new HashMap<>();
        List<Allophone> allophones = allophoneDao.readAllOrdered(locale);
        logger.info("allophones.size(): " + allophones.size());
        List<Word> words = wordDao.readAllOrdered(locale);
        logger.info("words.size(): " + words.size());
        for (Word word : words) {
            List<String> allophonesInWord = PhoneticsHelper.getAllophones(word);
            for (String allophoneInWord : allophonesInWord) {
                if (!allophoneFrequencyMap.containsKey(allophoneInWord)) {
                    allophoneFrequencyMap.put(allophoneInWord, word.getUsageCount());
                } else {
                    allophoneFrequencyMap.put(allophoneInWord, allophoneFrequencyMap.get(allophoneInWord) + word.getUsageCount());
                }
            }
        }
        for (String allophoneIpa : allophoneFrequencyMap.keySet()) {
            Allophone allophone = allophoneDao.readByValueIpa(locale, allophoneIpa);
            allophone.setUsageCount(allophoneFrequencyMap.get(allophoneIpa));
            allophoneDao.update(allophone);
        }
    }
    logger.info("execute complete");
}
Also used : Locale(ai.elimu.model.enums.Locale) Word(ai.elimu.model.content.Word) HashMap(java.util.HashMap) Allophone(ai.elimu.model.content.Allophone) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Aggregations

Allophone (ai.elimu.model.content.Allophone)23 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)14 Contributor (ai.elimu.model.Contributor)11 Word (ai.elimu.model.content.Word)5 ArrayList (java.util.ArrayList)5 Letter (ai.elimu.model.content.Letter)4 AllophoneGson (ai.elimu.model.gson.content.AllophoneGson)4 Locale (ai.elimu.model.enums.Locale)3 Syllable (ai.elimu.model.content.Syllable)2 Audio (ai.elimu.model.content.multimedia.Audio)2 Image (ai.elimu.model.content.multimedia.Image)2 WordRevisionEvent (ai.elimu.model.contributor.WordRevisionEvent)2 Test (org.junit.Test)2 LetterGson (ai.elimu.model.gson.content.LetterGson)1 SyllableGson (ai.elimu.model.gson.content.SyllableGson)1 WordGson (ai.elimu.model.gson.content.WordGson)1 Gson (com.google.gson.Gson)1 HashMap (java.util.HashMap)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1