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();
}
}
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";
}
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;
}
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";
}
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;
}
Aggregations