use of ai.elimu.model.content.Word in project webapp by elimu-ai.
the class SyllableHelperTest method testGetTriSyllables_languageEN.
@Test
public void testGetTriSyllables_languageEN() {
Word word = new Word();
word.setText("grandmother");
List<String> syllables = SyllableHelper.getSyllables(word, Language.ENG);
assertThat(syllables.get(0), is("grand"));
assertThat(syllables.get(1), is("moth"));
assertThat(syllables.get(2), is("er"));
}
use of ai.elimu.model.content.Word in project webapp by elimu-ai.
the class ImageCreateController method handleSubmit.
@RequestMapping(method = RequestMethod.POST)
public String handleSubmit(HttpSession session, /*@Valid*/
Image image, @RequestParam("bytes") MultipartFile multipartFile, BindingResult result, Model model) {
logger.info("handleSubmit");
Contributor contributor = (Contributor) session.getAttribute("contributor");
if (StringUtils.isBlank(image.getTitle())) {
result.rejectValue("title", "NotNull");
} else {
Image existingImage = imageDao.read(image.getTitle(), image.getLocale());
if (existingImage != null) {
result.rejectValue("title", "NonUnique");
}
}
try {
byte[] bytes = multipartFile.getBytes();
if (multipartFile.isEmpty() || (bytes == null) || (bytes.length == 0)) {
result.rejectValue("bytes", "NotNull");
} else {
String originalFileName = multipartFile.getOriginalFilename();
logger.info("originalFileName: " + originalFileName);
if (originalFileName.toLowerCase().endsWith(".png")) {
image.setImageFormat(ImageFormat.PNG);
} else if (originalFileName.toLowerCase().endsWith(".jpg") || originalFileName.toLowerCase().endsWith(".jpeg")) {
image.setImageFormat(ImageFormat.JPG);
} else if (originalFileName.toLowerCase().endsWith(".gif")) {
image.setImageFormat(ImageFormat.GIF);
} else {
result.rejectValue("bytes", "typeMismatch");
}
if (image.getImageFormat() != null) {
String contentType = multipartFile.getContentType();
logger.info("contentType: " + contentType);
image.setContentType(contentType);
image.setBytes(bytes);
if (image.getImageFormat() != ImageFormat.GIF) {
int width = ImageHelper.getWidth(bytes);
logger.info("width: " + width + "px");
if (width < ImageHelper.MINIMUM_WIDTH) {
result.rejectValue("bytes", "image.too.small");
image.setBytes(null);
} else {
if (width > ImageHelper.MINIMUM_WIDTH) {
bytes = ImageHelper.scaleImage(bytes, ImageHelper.MINIMUM_WIDTH);
image.setBytes(bytes);
}
}
}
}
}
} catch (IOException e) {
logger.error(e);
}
if (result.hasErrors()) {
model.addAttribute("contentLicenses", ContentLicense.values());
model.addAttribute("literacySkills", LiteracySkill.values());
model.addAttribute("numeracySkills", NumeracySkill.values());
return "content/multimedia/image/create";
} else {
image.setTitle(image.getTitle().toLowerCase());
int[] dominantColor = ImageColorHelper.getDominantColor(image.getBytes());
image.setDominantColor("rgb(" + dominantColor[0] + "," + dominantColor[1] + "," + dominantColor[2] + ")");
image.setTimeLastUpdate(Calendar.getInstance());
imageDao.create(image);
// TODO: store RevisionEvent
// Label Image with Word of matching title
Word matchingWord = wordDao.readByText(contributor.getLocale(), image.getTitle());
if (matchingWord != null) {
Set<Word> labeledWords = new HashSet<>();
if (!labeledWords.contains(matchingWord)) {
labeledWords.add(matchingWord);
image.setWords(labeledWords);
imageDao.update(image);
}
}
if (EnvironmentContextLoaderListener.env == Environment.PROD) {
String text = URLEncoder.encode(contributor.getFirstName() + " just added a new Image:\n" + "• Language: \"" + image.getLocale().getLanguage() + "\"\n" + "• Title: \"" + image.getTitle() + "\"\n" + "See ") + "http://elimu.ai/content/multimedia/image/edit/" + image.getId();
String iconUrl = contributor.getImageUrl();
String imageUrl = "http://elimu.ai/image/" + image.getId() + "." + image.getImageFormat().toString().toLowerCase();
SlackApiHelper.postMessage(SlackApiHelper.getChannelId(Team.CONTENT_CREATION), text, iconUrl, imageUrl);
}
return "redirect:/content/multimedia/image/list#" + image.getId();
}
}
use of ai.elimu.model.content.Word in project webapp by elimu-ai.
the class NumberCreateController method handleRequest.
@RequestMapping(method = RequestMethod.GET)
public String handleRequest(HttpSession session, Model model) {
logger.info("handleRequest");
Number number = new Number();
model.addAttribute("number", number);
Contributor contributor = (Contributor) session.getAttribute("contributor");
List<Word> words = wordDao.readAllOrdered(contributor.getLocale());
model.addAttribute("words", words);
return "content/number/create";
}
use of ai.elimu.model.content.Word in project webapp by elimu-ai.
the class NumberEditController method handleRequest.
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public String handleRequest(HttpSession session, Model model, @PathVariable Long id) {
logger.info("handleRequest");
Number number = numberDao.read(id);
model.addAttribute("number", number);
Contributor contributor = (Contributor) session.getAttribute("contributor");
List<Word> words = wordDao.readAllOrdered(contributor.getLocale());
model.addAttribute("words", words);
return "content/number/edit";
}
use of ai.elimu.model.content.Word in project webapp by elimu-ai.
the class NumberListController method getNumberWords.
private List<Word> getNumberWords(Locale locale, String... words) {
List<Word> numberWords = new ArrayList<>();
for (String word : words) {
Word numberWord = wordDao.readByText(locale, word);
numberWords.add(numberWord);
}
return numberWords;
}
Aggregations