Search in sources :

Example 21 with Sound

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));
}
Also used : Sound(ai.elimu.model.content.Sound) Test(org.junit.Test)

Example 22 with Sound

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"));
}
Also used : Sound(ai.elimu.model.content.Sound) Test(org.junit.Test)

Example 23 with Sound

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");
}
Also used : Letter(ai.elimu.model.content.Letter) Word(ai.elimu.model.content.Word) HashMap(java.util.HashMap) Sound(ai.elimu.model.content.Sound) LetterSoundCorrespondence(ai.elimu.model.content.LetterSoundCorrespondence) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Aggregations

Sound (ai.elimu.model.content.Sound)23 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)13 Letter (ai.elimu.model.content.Letter)10 LetterSoundCorrespondence (ai.elimu.model.content.LetterSoundCorrespondence)10 IOException (java.io.IOException)6 Word (ai.elimu.model.content.Word)5 ArrayList (java.util.ArrayList)5 CSVFormat (org.apache.commons.csv.CSVFormat)5 JSONArray (org.json.JSONArray)4 LetterSoundCorrespondenceContributionEvent (ai.elimu.model.contributor.LetterSoundCorrespondenceContributionEvent)3 Reader (java.io.Reader)3 Path (java.nio.file.Path)3 CSVParser (org.apache.commons.csv.CSVParser)3 CSVRecord (org.apache.commons.csv.CSVRecord)3 SoundContributionEvent (ai.elimu.model.contributor.SoundContributionEvent)2 SoundGson (ai.elimu.model.v2.gson.content.SoundGson)2 StringWriter (java.io.StringWriter)2 HashMap (java.util.HashMap)2 CSVPrinter (org.apache.commons.csv.CSVPrinter)2 JSONObject (org.json.JSONObject)2