use of ai.elimu.model.content.Sound in project webapp by elimu-ai.
the class SoundDaoTest method testStoreSoundType.
@Test
public void testStoreSoundType() {
Sound sound = new Sound();
sound.setValueIpa("ɛ");
sound.setValueSampa("E");
sound.setSoundType(SoundType.VOWEL);
soundDao.create(sound);
assertThat(soundDao.readByValueSampa("E").getSoundType(), is(SoundType.VOWEL));
}
use of ai.elimu.model.content.Sound in project webapp by elimu-ai.
the class SoundDaoTest method testLowerCaseVsUpperCase.
@Test
public void testLowerCaseVsUpperCase() {
Sound soundLowerCaseT = new Sound();
soundLowerCaseT.setValueIpa("t");
soundLowerCaseT.setValueSampa("t");
soundDao.create(soundLowerCaseT);
Sound soundUpperCaseT = new Sound();
soundUpperCaseT.setValueIpa("θ");
soundUpperCaseT.setValueSampa("T");
soundDao.create(soundUpperCaseT);
assertThat(soundDao.readByValueSampa("t").getValueSampa(), is("t"));
assertThat(soundDao.readByValueSampa("T").getValueSampa(), is("T"));
}
use of ai.elimu.model.content.Sound in project webapp by elimu-ai.
the class LetterSoundCorrespondenceUsageCountScheduler method execute.
// At 06:15 every day
@Scheduled(cron = "00 15 06 * * *")
public synchronized void execute() {
logger.info("execute");
logger.info("Calculating usage count for LetterSoundCorrespondences");
// <id, usageCount>
Map<Long, Integer> letterSoundCorrespondenceFrequencyMap = new HashMap<>();
List<Word> words = wordDao.readAll();
logger.info("words.size(): " + words.size());
for (Word word : words) {
logger.info("word.getText(): " + word.getText());
for (LetterSoundCorrespondence letterSoundCorrespondence : word.getLetterSoundCorrespondences()) {
letterSoundCorrespondenceFrequencyMap.put(letterSoundCorrespondence.getId(), letterSoundCorrespondenceFrequencyMap.getOrDefault(letterSoundCorrespondence.getId(), 0) + word.getUsageCount());
}
}
// Update the values previously stored in the database
for (LetterSoundCorrespondence letterSoundCorrespondence : letterSoundCorrespondenceDao.readAll()) {
logger.info("letterSoundCorrespondence.getId(): " + letterSoundCorrespondence.getId());
logger.info("letterSoundCorrespondence Letters: \"" + letterSoundCorrespondence.getLetters().stream().map(Letter::getText).collect(Collectors.joining()) + "\"");
logger.info("letterSoundCorrespondence Sounds: /" + letterSoundCorrespondence.getSounds().stream().map(Sound::getValueIpa).collect(Collectors.joining()) + "/");
logger.info("letterSoundCorrespondence.getUsageCount() (before update): " + letterSoundCorrespondence.getUsageCount());
int newUsageCount = 0;
if (letterSoundCorrespondenceFrequencyMap.containsKey(letterSoundCorrespondence.getId())) {
newUsageCount = letterSoundCorrespondenceFrequencyMap.get(letterSoundCorrespondence.getId());
}
logger.info("newUsageCount: " + newUsageCount);
letterSoundCorrespondence.setUsageCount(newUsageCount);
letterSoundCorrespondenceDao.update(letterSoundCorrespondence);
logger.info("letterSoundCorrespondence.getUsageCount() (after update): " + letterSoundCorrespondence.getUsageCount());
}
logger.info("execute complete");
}
Aggregations