Search in sources :

Example 16 with Emoji

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

the class EmojiEditController 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 17 with Emoji

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

the class EmojiCsvExportController method handleRequest.

@RequestMapping(value = "/emojis.csv", method = RequestMethod.GET)
public void handleRequest(HttpServletResponse response, OutputStream outputStream) throws IOException {
    logger.info("handleRequest");
    List<Emoji> emojis = emojiDao.readAllOrdered();
    logger.info("emojis.size(): " + emojis.size());
    CSVFormat csvFormat = CSVFormat.DEFAULT.withHeader("id", "glyph", "unicode_version", "unicode_emoji_version", "word_ids", "word_texts");
    StringWriter stringWriter = new StringWriter();
    CSVPrinter csvPrinter = new CSVPrinter(stringWriter, csvFormat);
    for (Emoji emoji : emojis) {
        logger.info("emoji.getGlyph(): \"" + emoji.getGlyph() + "\"");
        JSONArray wordIdsJsonArray = new JSONArray();
        int index = 0;
        for (Word word : emoji.getWords()) {
            wordIdsJsonArray.put(index, word.getId());
            index++;
        }
        JSONArray wordTextsJsonArray = new JSONArray();
        index = 0;
        for (Word word : emoji.getWords()) {
            wordTextsJsonArray.put(index, word.getText());
            index++;
        }
        csvPrinter.printRecord(emoji.getId(), emoji.getGlyph(), emoji.getUnicodeVersion(), emoji.getUnicodeEmojiVersion(), wordIdsJsonArray, wordTextsJsonArray);
        csvPrinter.flush();
    }
    String csvFileContent = stringWriter.toString();
    response.setContentType("text/csv");
    byte[] bytes = csvFileContent.getBytes();
    response.setContentLength(bytes.length);
    try {
        outputStream.write(bytes);
        outputStream.flush();
        outputStream.close();
    } catch (IOException ex) {
        logger.error(ex);
    }
}
Also used : CSVPrinter(org.apache.commons.csv.CSVPrinter) Word(ai.elimu.model.content.Word) StringWriter(java.io.StringWriter) JSONArray(org.json.JSONArray) Emoji(ai.elimu.model.content.Emoji) CSVFormat(org.apache.commons.csv.CSVFormat) IOException(java.io.IOException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 18 with Emoji

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

the class EmojiCreateController method handleRequest.

@RequestMapping(method = RequestMethod.GET)
public String handleRequest(Model model) {
    logger.info("handleRequest");
    Emoji emoji = new Emoji();
    model.addAttribute("emoji", emoji);
    return "content/emoji/create";
}
Also used : Emoji(ai.elimu.model.content.Emoji) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 19 with Emoji

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

the class NumberEditController 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 20 with Emoji

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

the class StoryBookEditController 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