Search in sources :

Example 21 with Emoji

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

the class WordListController 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 22 with Emoji

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

the class WordEditController method handleSubmit.

@RequestMapping(value = "/{id}", method = RequestMethod.POST)
public String handleSubmit(HttpServletRequest request, HttpSession session, @Valid Word word, BindingResult result, Model model) {
    logger.info("handleSubmit");
    Word existingWord = wordDao.readByText(word.getText());
    if ((existingWord != null) && !existingWord.getId().equals(word.getId())) {
        result.rejectValue("text", "NonUnique");
    }
    if (StringUtils.containsAny(word.getText(), " ")) {
        result.rejectValue("text", "WordSpace");
    }
    if (result.hasErrors()) {
        model.addAttribute("word", word);
        model.addAttribute("timeStart", request.getParameter("timeStart"));
        // TODO: sort by letter(s) text
        model.addAttribute("letterSoundCorrespondences", letterSoundCorrespondenceDao.readAllOrderedByUsage());
        model.addAttribute("rootWords", wordDao.readAllOrdered());
        model.addAttribute("emojisByWordId", getEmojisByWordId());
        model.addAttribute("wordTypes", WordType.values());
        model.addAttribute("spellingConsistencies", SpellingConsistency.values());
        model.addAttribute("wordContributionEvents", wordContributionEventDao.readAll(word));
        model.addAttribute("wordPeerReviewEvents", wordPeerReviewEventDao.readAll(word));
        model.addAttribute("audios", audioDao.readAll(word));
        // Look up variants of the same wordByTextMatch
        model.addAttribute("wordInflections", wordDao.readInflections(word));
        // Look up Multimedia content that has been labeled with this Word
        // TODO: labeled Audios
        List<Emoji> labeledEmojis = emojiDao.readAllLabeled(word);
        model.addAttribute("labeledEmojis", labeledEmojis);
        List<Image> labeledImages = imageDao.readAllLabeled(word);
        model.addAttribute("labeledImages", labeledImages);
        return "content/word/edit";
    } else {
        word.setTimeLastUpdate(Calendar.getInstance());
        word.setRevisionNumber(word.getRevisionNumber() + 1);
        wordDao.update(word);
        WordContributionEvent wordContributionEvent = new WordContributionEvent();
        wordContributionEvent.setContributor((Contributor) session.getAttribute("contributor"));
        wordContributionEvent.setTime(Calendar.getInstance());
        wordContributionEvent.setWord(word);
        wordContributionEvent.setRevisionNumber(word.getRevisionNumber());
        wordContributionEvent.setComment(StringUtils.abbreviate(request.getParameter("contributionComment"), 1000));
        wordContributionEvent.setTimeSpentMs(System.currentTimeMillis() - Long.valueOf(request.getParameter("timeStart")));
        wordContributionEvent.setPlatform(Platform.WEBAPP);
        wordContributionEventDao.create(wordContributionEvent);
        String contentUrl = "http://" + EnvironmentContextLoaderListener.PROPERTIES.getProperty("content.language").toLowerCase() + ".elimu.ai/content/word/edit/" + word.getId();
        DiscordHelper.sendChannelMessage("Word edited: " + contentUrl, "\"" + word.getText() + "\"", "Comment: \"" + wordContributionEvent.getComment() + "\"", null, null);
        // Note: updating the list of Words in StoryBookParagraphs is handled by the ParagraphWordScheduler
        // Delete syllables that are actual words
        Syllable syllable = syllableDao.readByText(word.getText());
        if (syllable != null) {
            syllableDao.delete(syllable);
        }
        return "redirect:/content/word/list#" + word.getId();
    }
}
Also used : Word(ai.elimu.model.content.Word) Emoji(ai.elimu.model.content.Emoji) WordContributionEvent(ai.elimu.model.contributor.WordContributionEvent) Image(ai.elimu.model.content.multimedia.Image) Syllable(ai.elimu.model.content.Syllable) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 23 with Emoji

use of ai.elimu.model.content.Emoji 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 24 with Emoji

use of ai.elimu.model.content.Emoji 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 25 with Emoji

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

the class EmojisRestController method handleGetRequest.

@RequestMapping(method = RequestMethod.GET)
public String handleGetRequest(HttpServletRequest request) {
    logger.info("handleGetRequest");
    JSONArray emojisJsonArray = new JSONArray();
    for (Emoji emoji : emojiDao.readAllOrdered()) {
        EmojiGson emojiGson = JpaToGsonConverter.getEmojiGson(emoji);
        String json = new Gson().toJson(emojiGson);
        emojisJsonArray.put(new JSONObject(json));
    }
    String jsonResponse = emojisJsonArray.toString();
    logger.info("jsonResponse: " + jsonResponse);
    return jsonResponse;
}
Also used : EmojiGson(ai.elimu.model.v2.gson.content.EmojiGson) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) Emoji(ai.elimu.model.content.Emoji) EmojiGson(ai.elimu.model.v2.gson.content.EmojiGson) Gson(com.google.gson.Gson) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Emoji (ai.elimu.model.content.Emoji)25 Word (ai.elimu.model.content.Word)22 HashMap (java.util.HashMap)13 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)10 JSONArray (org.json.JSONArray)3 StoryBookParagraph (ai.elimu.model.content.StoryBookParagraph)2 Image (ai.elimu.model.content.multimedia.Image)2 WordContributionEvent (ai.elimu.model.contributor.WordContributionEvent)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 CSVFormat (org.apache.commons.csv.CSVFormat)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 StoryBookLearningEvent (ai.elimu.model.analytics.StoryBookLearningEvent)1 Letter (ai.elimu.model.content.Letter)1 LetterSoundCorrespondence (ai.elimu.model.content.LetterSoundCorrespondence)1 Number (ai.elimu.model.content.Number)1 Sound (ai.elimu.model.content.Sound)1 StoryBook (ai.elimu.model.content.StoryBook)1 StoryBookChapter (ai.elimu.model.content.StoryBookChapter)1 Syllable (ai.elimu.model.content.Syllable)1