use of ai.elimu.model.content.Word in project webapp by elimu-ai.
the class JavaToGsonConverter method getNumberGson.
public static NumberGson getNumberGson(Number number) {
if (number == null) {
return null;
} else {
NumberGson numberGson = new NumberGson();
numberGson.setId(number.getId());
numberGson.setLocale(number.getLocale());
numberGson.setTimeLastUpdate(number.getTimeLastUpdate());
numberGson.setRevisionNumber(number.getRevisionNumber());
numberGson.setContentStatus(number.getContentStatus());
numberGson.setValue(number.getValue());
numberGson.setSymbol(number.getSymbol());
numberGson.setWord(getWordGson(number.getWord()));
List<WordGson> words = new ArrayList<>();
for (Word word : number.getWords()) {
WordGson wordGson = getWordGson(word);
words.add(wordGson);
}
numberGson.setWords(words);
return numberGson;
}
}
use of ai.elimu.model.content.Word in project webapp by elimu-ai.
the class WordRestController 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 words = new JSONArray();
for (Word word : wordDao.readAllOrdered(locale)) {
WordGson wordGson = JavaToGsonConverter.getWordGson(word);
String json = new Gson().toJson(wordGson);
words.put(new JSONObject(json));
}
JSONObject jsonObject = new JSONObject();
jsonObject.put("result", "success");
jsonObject.put("words", words);
logger.info("jsonObject: " + jsonObject);
return jsonObject.toString();
}
use of ai.elimu.model.content.Word in project webapp by elimu-ai.
the class SyllableUsageCountScheduler method execute.
// At 07:30 every morning
@Scheduled(cron = "00 30 07 * * *")
public synchronized void execute() {
logger.info("execute");
for (Locale locale : Locale.values()) {
logger.info("Calculating usage count for Syllables with locale " + locale);
Map<String, Integer> syllableFrequencyMap = new HashMap<>();
List<StoryBook> storyBooks = storyBookDao.readAllOrdered(locale);
logger.info("storyBooks.size(): " + storyBooks.size());
for (StoryBook storyBook : storyBooks) {
logger.info("storyBook.getTitle(): " + storyBook.getTitle());
Map<String, Integer> syllableFrequencyMapForBook = SyllableFrequencyHelper.getSyllableFrequency(storyBook);
for (String key : syllableFrequencyMapForBook.keySet()) {
String syllableText = key;
int syllableFrequency = syllableFrequencyMapForBook.get(key);
if (!syllableFrequencyMap.containsKey(syllableText)) {
syllableFrequencyMap.put(syllableText, syllableFrequency);
} else {
syllableFrequencyMap.put(syllableText, syllableFrequencyMap.get(syllableText) + syllableFrequency);
}
}
}
logger.info("syllableFrequencyMap: " + syllableFrequencyMap);
for (String key : syllableFrequencyMap.keySet()) {
String syllableText = key;
// Skip syllables that are actual words
// TODO: add logic to Word editing
Word word = wordDao.readByText(locale, syllableText);
if (word != null) {
continue;
}
// TODO: add support for trigrams
if (syllableText.length() != 2) {
continue;
}
Syllable existingSyllable = syllableDao.readByText(locale, syllableText);
if (existingSyllable == null) {
Syllable syllable = new Syllable();
syllable.setLocale(locale);
syllable.setTimeLastUpdate(Calendar.getInstance());
syllable.setText(syllableText);
syllable.setUsageCount(syllableFrequencyMap.get(syllableText));
syllableDao.create(syllable);
} else {
existingSyllable.setUsageCount(syllableFrequencyMap.get(syllableText));
syllableDao.update(existingSyllable);
}
}
}
logger.info("execute complete");
}
use of ai.elimu.model.content.Word in project webapp by elimu-ai.
the class ImageDaoTest method testReadAllLabeled.
@Test
public void testReadAllLabeled() {
Word wordDog = new Word();
wordDog.setText("dog");
wordDog.setLocale(Locale.EN);
wordDao.create(wordDog);
Word wordCat = new Word();
wordCat.setText("cat");
wordCat.setLocale(Locale.EN);
wordDao.create(wordCat);
List<Image> images = imageDao.readAllLabeled(wordCat, Locale.EN);
assertThat(images.size(), is(0));
Set<Word> words = new HashSet<>();
words.add(wordCat);
Image image = new Image();
image.setTitle("image");
image.setWords(words);
image.setLocale(Locale.EN);
imageDao.create(image);
images = imageDao.readAllLabeled(wordDog, Locale.EN);
assertThat(images.size(), is(0));
images = imageDao.readAllLabeled(wordCat, Locale.EN);
assertThat(images.size(), is(1));
assertThat(images.get(0).getWords().size(), is(1));
words.add(wordDog);
image.setWords(words);
imageDao.update(image);
images = imageDao.readAllLabeled(wordCat, Locale.EN);
assertThat(images.size(), is(1));
assertThat(images.get(0).getWords().size(), is(2));
}
use of ai.elimu.model.content.Word in project webapp by elimu-ai.
the class NumberDaoTest method testStoreWithMultipleNumberWords.
@Test
public void testStoreWithMultipleNumberWords() {
Word word1 = new Word();
wordDao.create(word1);
Word word2 = new Word();
wordDao.create(word2);
List<Word> numberWords = new ArrayList<>();
numberWords.add(word1);
numberWords.add(word2);
Number number = new Number();
number.setWords(numberWords);
numberDao.create(number);
assertThat(number.getWords().size(), is(2));
}
Aggregations