Search in sources :

Example 1 with Word

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

the class SyllableFrequencyHelper method getSyllableFrequency.

public static Map<String, Integer> getSyllableFrequency(StoryBook storyBook) {
    Map<String, Integer> syllableFrequencyMap = new HashMap<>();
    List<String> paragraphs = storyBook.getParagraphs();
    for (String paragraph : paragraphs) {
        logger.info("paragraph: " + paragraph);
        List<String> words = WordExtractionHelper.getWords(paragraph);
        for (String wordInParagraph : words) {
            logger.info("wordInParagraph: " + wordInParagraph);
            Word word = new Word();
            word.setLocale(storyBook.getLocale());
            word.setText(wordInParagraph);
            List<String> syllables = SyllableHelper.getSyllables(word);
            logger.info("syllables.size(): " + syllables.size());
            for (String syllable : syllables) {
                logger.info("syllable: " + syllable);
                if (!syllableFrequencyMap.containsKey(syllable)) {
                    syllableFrequencyMap.put(syllable, 1);
                } else {
                    syllableFrequencyMap.put(syllable, syllableFrequencyMap.get(syllable) + 1);
                }
            }
        }
    }
    return sortByValue(syllableFrequencyMap);
}
Also used : Word(ai.elimu.model.content.Word) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap)

Example 2 with Word

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

the class JavaToGsonConverter method getImageGson.

public static ImageGson getImageGson(Image image) {
    if (image == null) {
        return null;
    } else {
        ImageGson imageGson = new ImageGson();
        imageGson.setId(image.getId());
        imageGson.setLocale(image.getLocale());
        imageGson.setTimeLastUpdate(image.getTimeLastUpdate());
        imageGson.setRevisionNumber(image.getRevisionNumber());
        imageGson.setContentStatus(image.getContentStatus());
        imageGson.setDownloadUrl("/image/" + image.getId() + "." + image.getImageFormat().toString().toLowerCase());
        imageGson.setDownloadSize(image.getBytes().length / 1024);
        imageGson.setContentType(image.getContentType());
        imageGson.setLiteracySkills(image.getLiteracySkills());
        imageGson.setNumeracySkills(image.getNumeracySkills());
        List<LetterGson> letters = new ArrayList<>();
        for (Letter letter : image.getLetters()) {
            LetterGson letterGson = getLetterGson(letter);
            letters.add(letterGson);
        }
        imageGson.setLetters(letters);
        List<NumberGson> numbers = new ArrayList<>();
        for (Number number : image.getNumbers()) {
            NumberGson numberGson = getNumberGson(number);
            numbers.add(numberGson);
        }
        imageGson.setNumbers(numbers);
        List<WordGson> words = new ArrayList<>();
        for (Word word : image.getWords()) {
            WordGson wordGson = getWordGson(word);
            words.add(wordGson);
        }
        imageGson.setWords(words);
        imageGson.setTitle(image.getTitle());
        imageGson.setImageFormat(image.getImageFormat());
        imageGson.setDominantColor(image.getDominantColor());
        return imageGson;
    }
}
Also used : Letter(ai.elimu.model.content.Letter) WordGson(ai.elimu.model.gson.content.WordGson) ImageGson(ai.elimu.model.gson.content.multimedia.ImageGson) Word(ai.elimu.model.content.Word) Number(ai.elimu.model.content.Number) ArrayList(java.util.ArrayList) LetterGson(ai.elimu.model.gson.content.LetterGson) NumberGson(ai.elimu.model.gson.content.NumberGson)

Example 3 with Word

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

the class JavaToGsonConverter method getVideoGson.

public static VideoGson getVideoGson(Video video) {
    if (video == null) {
        return null;
    } else {
        VideoGson videoGson = new VideoGson();
        videoGson.setId(video.getId());
        videoGson.setLocale(video.getLocale());
        videoGson.setTimeLastUpdate(video.getTimeLastUpdate());
        videoGson.setRevisionNumber(video.getRevisionNumber());
        videoGson.setContentStatus(video.getContentStatus());
        videoGson.setDownloadUrl("/video/" + video.getId() + "." + video.getVideoFormat().toString().toLowerCase());
        videoGson.setDownloadSize(video.getBytes().length / 1024);
        videoGson.setContentType(video.getContentType());
        videoGson.setLiteracySkills(video.getLiteracySkills());
        videoGson.setNumeracySkills(video.getNumeracySkills());
        List<LetterGson> letters = new ArrayList<>();
        for (Letter letter : video.getLetters()) {
            LetterGson letterGson = getLetterGson(letter);
            letters.add(letterGson);
        }
        videoGson.setLetters(letters);
        List<NumberGson> numbers = new ArrayList<>();
        for (Number number : video.getNumbers()) {
            NumberGson numberGson = getNumberGson(number);
            numbers.add(numberGson);
        }
        videoGson.setNumbers(numbers);
        List<WordGson> words = new ArrayList<>();
        for (Word word : video.getWords()) {
            WordGson wordGson = getWordGson(word);
            words.add(wordGson);
        }
        videoGson.setWords(words);
        videoGson.setTitle(video.getTitle());
        videoGson.setVideoFormat(video.getVideoFormat());
        videoGson.setThumbnailDownloadUrl("/video/" + video.getId() + "/thumbnail.png");
        return videoGson;
    }
}
Also used : Letter(ai.elimu.model.content.Letter) WordGson(ai.elimu.model.gson.content.WordGson) Word(ai.elimu.model.content.Word) Number(ai.elimu.model.content.Number) ArrayList(java.util.ArrayList) VideoGson(ai.elimu.model.gson.content.multimedia.VideoGson) LetterGson(ai.elimu.model.gson.content.LetterGson) NumberGson(ai.elimu.model.gson.content.NumberGson)

Example 4 with Word

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

the class JavaToGsonConverter method getAudioGson.

public static AudioGson getAudioGson(Audio audio) {
    if (audio == null) {
        return null;
    } else {
        AudioGson audioGson = new AudioGson();
        audioGson.setId(audio.getId());
        audioGson.setLocale(audio.getLocale());
        audioGson.setTimeLastUpdate(audio.getTimeLastUpdate());
        audioGson.setRevisionNumber(audio.getRevisionNumber());
        audioGson.setContentStatus(audio.getContentStatus());
        audioGson.setDownloadUrl("/audio/" + audio.getId() + "." + audio.getAudioFormat().toString().toLowerCase());
        audioGson.setDownloadSize(audio.getBytes().length / 1024);
        audioGson.setContentType(audio.getContentType());
        audioGson.setLiteracySkills(audio.getLiteracySkills());
        audioGson.setNumeracySkills(audio.getNumeracySkills());
        List<LetterGson> letters = new ArrayList<>();
        for (Letter letter : audio.getLetters()) {
            LetterGson letterGson = getLetterGson(letter);
            letters.add(letterGson);
        }
        audioGson.setLetters(letters);
        List<NumberGson> numbers = new ArrayList<>();
        for (Number number : audio.getNumbers()) {
            NumberGson numberGson = getNumberGson(number);
            numbers.add(numberGson);
        }
        audioGson.setNumbers(numbers);
        List<WordGson> words = new ArrayList<>();
        for (Word word : audio.getWords()) {
            WordGson wordGson = getWordGson(word);
            words.add(wordGson);
        }
        audioGson.setWords(words);
        audioGson.setTranscription(audio.getTranscription());
        audioGson.setAudioType(audio.getAudioFormat());
        return audioGson;
    }
}
Also used : Letter(ai.elimu.model.content.Letter) WordGson(ai.elimu.model.gson.content.WordGson) AudioGson(ai.elimu.model.gson.content.multimedia.AudioGson) Word(ai.elimu.model.content.Word) Number(ai.elimu.model.content.Number) ArrayList(java.util.ArrayList) LetterGson(ai.elimu.model.gson.content.LetterGson) NumberGson(ai.elimu.model.gson.content.NumberGson)

Example 5 with Word

use of ai.elimu.model.content.Word 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

Word (ai.elimu.model.content.Word)88 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)40 HashMap (java.util.HashMap)23 Emoji (ai.elimu.model.content.Emoji)22 ArrayList (java.util.ArrayList)20 Number (ai.elimu.model.content.Number)17 Letter (ai.elimu.model.content.Letter)15 Test (org.junit.Test)12 Image (ai.elimu.model.content.multimedia.Image)11 StoryBookParagraph (ai.elimu.model.content.StoryBookParagraph)9 JSONArray (org.json.JSONArray)9 JSONObject (org.json.JSONObject)9 Contributor (ai.elimu.model.Contributor)8 Language (ai.elimu.model.v2.enums.Language)8 IOException (java.io.IOException)8 LetterSoundCorrespondence (ai.elimu.model.content.LetterSoundCorrespondence)7 Audio (ai.elimu.model.content.multimedia.Audio)7 Contributor (ai.elimu.model.contributor.Contributor)7 WordContributionEvent (ai.elimu.model.contributor.WordContributionEvent)7 WordGson (ai.elimu.model.v2.gson.content.WordGson)7