Search in sources :

Example 76 with Word

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

the class WordPeerReviewsController method getEmojisByWordId.

private Map<Long, String> getEmojisByWordId() {
    logger.info("getEmojisByWordId");
    Map<Long, String> emojisByWordId = new HashMap<>();
    for (Word word : wordDao.readAll()) {
        String emojiGlyphs = "";
        List<Emoji> emojis = emojiDao.readAllLabeled(word);
        for (Emoji emoji : emojis) {
            emojiGlyphs += emoji.getGlyph();
        }
        if (StringUtils.isNotBlank(emojiGlyphs)) {
            emojisByWordId.put(word.getId(), emojiGlyphs);
        }
    }
    return emojisByWordId;
}
Also used : Word(ai.elimu.model.content.Word) HashMap(java.util.HashMap) Emoji(ai.elimu.model.content.Emoji)

Example 77 with Word

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

the class WordCreationsPendingController method handleRequest.

@RequestMapping(method = RequestMethod.GET)
public String handleRequest(Model model) {
    logger.info("handleRequest");
    List<String> paragraphs = new ArrayList<>();
    for (StoryBookParagraph storyBookParagraph : storyBookParagraphDao.readAll()) {
        paragraphs.add(storyBookParagraph.getOriginalText());
    }
    logger.info("paragraphs.size(): " + paragraphs.size());
    Language language = Language.valueOf(ConfigHelper.getProperty("content.language"));
    Map<String, Integer> wordFrequencyMap = WordFrequencyHelper.getWordFrequency(paragraphs, language);
    model.addAttribute("wordFrequencyMap", wordFrequencyMap);
    logger.info("wordFrequencyMap.size(): " + wordFrequencyMap.size());
    // Remove Words that have already been added
    Iterator<String> wordTextIterator = wordFrequencyMap.keySet().iterator();
    while (wordTextIterator.hasNext()) {
        String wordText = wordTextIterator.next();
        Word existingWord = wordDao.readByText(wordText);
        if (existingWord != null) {
            wordTextIterator.remove();
        }
    }
    int maxUsageCount = 0;
    for (Integer usageCount : wordFrequencyMap.values()) {
        if (usageCount > maxUsageCount) {
            maxUsageCount = usageCount;
        }
    }
    model.addAttribute("maxUsageCount", maxUsageCount);
    return "content/word/pending";
}
Also used : Word(ai.elimu.model.content.Word) Language(ai.elimu.model.v2.enums.Language) ArrayList(java.util.ArrayList) StoryBookParagraph(ai.elimu.model.content.StoryBookParagraph) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 78 with Word

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

the class ImageListController method getEmojisByWordId.

private Map<Long, String> getEmojisByWordId() {
    logger.info("getEmojisByWordId");
    Map<Long, String> emojisByWordId = new HashMap<>();
    for (Word word : wordDao.readAll()) {
        String emojiGlyphs = "";
        List<Emoji> emojis = emojiDao.readAllLabeled(word);
        for (Emoji emoji : emojis) {
            emojiGlyphs += emoji.getGlyph();
        }
        if (StringUtils.isNotBlank(emojiGlyphs)) {
            emojisByWordId.put(word.getId(), emojiGlyphs);
        }
    }
    return emojisByWordId;
}
Also used : Word(ai.elimu.model.content.Word) HashMap(java.util.HashMap) Emoji(ai.elimu.model.content.Emoji)

Example 79 with Word

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");
    wordDao.create(wordDog);
    Word wordCat = new Word();
    wordCat.setText("cat");
    wordDao.create(wordCat);
    List<Image> images = imageDao.readAllLabeled(wordCat);
    assertThat(images.size(), is(0));
    Set<Word> words = new HashSet<>();
    words.add(wordCat);
    Image image = new Image();
    image.setTitle("image");
    image.setWords(words);
    imageDao.create(image);
    images = imageDao.readAllLabeled(wordDog);
    assertThat(images.size(), is(0));
    images = imageDao.readAllLabeled(wordCat);
    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);
    assertThat(images.size(), is(1));
    assertThat(images.get(0).getWords().size(), is(2));
}
Also used : Word(ai.elimu.model.content.Word) Image(ai.elimu.model.content.multimedia.Image) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 80 with Word

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));
}
Also used : Word(ai.elimu.model.content.Word) Number(ai.elimu.model.content.Number) ArrayList(java.util.ArrayList) Test(org.junit.Test)

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