Search in sources :

Example 6 with Emoji

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

the class EmojiCreateController method handleSubmit.

@RequestMapping(method = RequestMethod.POST)
public String handleSubmit(@Valid Emoji emoji, BindingResult result, Model model) {
    logger.info("handleSubmit");
    Emoji existingEmoji = emojiDao.readByGlyph(emoji.getGlyph());
    if (existingEmoji != null) {
        result.rejectValue("glyph", "NonUnique");
    }
    if (emoji.getUnicodeVersion() > 9) {
        result.rejectValue("glyph", "emoji.unicode.version");
    }
    if (result.hasErrors()) {
        model.addAttribute("emoji", emoji);
        return "content/emoji/create";
    } else {
        emoji.setTimeLastUpdate(Calendar.getInstance());
        emojiDao.create(emoji);
        return "redirect:/content/emoji/list#" + emoji.getId();
    }
}
Also used : Emoji(ai.elimu.model.content.Emoji) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with Emoji

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

the class EmojiEditController method handleAddContentLabelRequest.

@RequestMapping(value = "/{id}/add-content-label", method = RequestMethod.POST)
@ResponseBody
public String handleAddContentLabelRequest(HttpServletRequest request, @PathVariable Long id) {
    logger.info("handleAddContentLabelRequest");
    logger.info("id: " + id);
    Emoji emoji = emojiDao.read(id);
    String wordIdParameter = request.getParameter("wordId");
    logger.info("wordIdParameter: " + wordIdParameter);
    if (StringUtils.isNotBlank(wordIdParameter)) {
        Long wordId = Long.valueOf(wordIdParameter);
        Word word = wordDao.read(wordId);
        Set<Word> words = emoji.getWords();
        if (!words.contains(word)) {
            words.add(word);
            emoji.setRevisionNumber(emoji.getRevisionNumber() + 1);
            emojiDao.update(emoji);
        }
    }
    return "success";
}
Also used : Word(ai.elimu.model.content.Word) Emoji(ai.elimu.model.content.Emoji) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 8 with Emoji

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

the class WordCreateController 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 9 with Emoji

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

the class WordEditController method handleRequest.

@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public String handleRequest(HttpSession session, Model model, @PathVariable Long id) {
    logger.info("handleRequest");
    Word word = wordDao.read(id);
    if (word.getLetterSoundCorrespondences().isEmpty()) {
        autoSelectLetterSoundCorrespondences(word);
    // TODO: display information message to the Contributor that the letter-sound correspondences were auto-selected, and that they should be verified
    }
    model.addAttribute("word", word);
    model.addAttribute("timeStart", System.currentTimeMillis());
    // 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));
    List<Audio> audios = audioDao.readAll(word);
    model.addAttribute("audios", audios);
    // Generate Audio for this Word (if it has not been done already)
    if (audios.isEmpty()) {
        Calendar timeStart = Calendar.getInstance();
        Language language = Language.valueOf(ConfigHelper.getProperty("content.language"));
        try {
            byte[] audioBytes = GoogleCloudTextToSpeechHelper.synthesizeText(word.getText(), language);
            logger.info("audioBytes: " + audioBytes);
            if (audioBytes != null) {
                Audio audio = new Audio();
                audio.setTimeLastUpdate(Calendar.getInstance());
                audio.setContentType(AudioFormat.MP3.getContentType());
                audio.setWord(word);
                audio.setTitle("word_" + word.getText());
                audio.setTranscription(word.getText());
                audio.setBytes(audioBytes);
                // TODO: Convert from byte[] to File, and extract audio duration
                audio.setDurationMs(null);
                audio.setAudioFormat(AudioFormat.MP3);
                audioDao.create(audio);
                audios.add(audio);
                model.addAttribute("audios", audios);
                AudioContributionEvent audioContributionEvent = new AudioContributionEvent();
                audioContributionEvent.setContributor((Contributor) session.getAttribute("contributor"));
                audioContributionEvent.setTime(Calendar.getInstance());
                audioContributionEvent.setAudio(audio);
                audioContributionEvent.setRevisionNumber(audio.getRevisionNumber());
                audioContributionEvent.setComment("Google Cloud Text-to-Speech (🤖 auto-generated comment)️");
                audioContributionEvent.setTimeSpentMs(System.currentTimeMillis() - timeStart.getTimeInMillis());
                audioContributionEvent.setPlatform(Platform.WEBAPP);
                audioContributionEventDao.create(audioContributionEvent);
            }
        } catch (Exception ex) {
            logger.error(ex);
        }
    }
    // 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);
    // TODO: labeled Videos
    // Look up StoryBook Paragraphs that contain this Word
    List<StoryBookParagraph> storyBookParagraphsContainingWord = storyBookParagraphDao.readAllContainingWord(word.getText());
    model.addAttribute("storyBookParagraphsContainingWord", storyBookParagraphsContainingWord);
    return "content/word/edit";
}
Also used : Word(ai.elimu.model.content.Word) Calendar(java.util.Calendar) StoryBookParagraph(ai.elimu.model.content.StoryBookParagraph) Image(ai.elimu.model.content.multimedia.Image) Language(ai.elimu.model.v2.enums.Language) Emoji(ai.elimu.model.content.Emoji) AudioContributionEvent(ai.elimu.model.contributor.AudioContributionEvent) Audio(ai.elimu.model.content.multimedia.Audio) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with Emoji

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

the class VideoEditController 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)

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