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;
}
}
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;
}
}
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;
}
}
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();
}
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");
}
Aggregations