use of ai.elimu.model.content.StoryBook in project webapp by elimu-ai.
the class WordFrequencyHelperTest method testGetWordFrequency.
@Test
public void testGetWordFrequency() {
StoryBook storyBook = new StoryBook();
List<String> paragraphs = new ArrayList<>();
paragraphs.add("\"Mom,\" called Lebo. \"Come and look. These clothes are all too small for me!\"");
paragraphs.add("\"Look at my skirt. It's too small,\" said Lebo.");
storyBook.setParagraphs(paragraphs);
Map<String, Integer> wordFrequencyMap = WordFrequencyHelper.getWordFrequency(storyBook);
assertThat(wordFrequencyMap.get("Lebo"), is(2));
assertThat(wordFrequencyMap.get("too"), is(2));
assertThat(wordFrequencyMap.get("small"), is(2));
assertThat(wordFrequencyMap.get("Mom"), is(1));
assertThat(wordFrequencyMap.get("called"), is(1));
}
use of ai.elimu.model.content.StoryBook in project webapp by elimu-ai.
the class StoryBookEditController method handleSubmit.
@RequestMapping(value = "/{id}", method = RequestMethod.POST)
public String handleSubmit(HttpSession session, @Valid StoryBook storyBook, BindingResult result, Model model, HttpServletRequest request) {
logger.info("handleSubmit");
Contributor contributor = (Contributor) session.getAttribute("contributor");
StoryBook existingStoryBook = storyBookDao.readByTitle(storyBook.getLocale(), storyBook.getTitle());
if ((existingStoryBook != null) && !existingStoryBook.getId().equals(storyBook.getId())) {
result.rejectValue("title", "NonUnique");
}
if (result.hasErrors()) {
model.addAttribute("storyBook", storyBook);
model.addAttribute("contentLicenses", ContentLicense.values());
List<Image> coverImages = imageDao.readAllOrdered(contributor.getLocale());
model.addAttribute("coverImages", coverImages);
model.addAttribute("gradeLevels", GradeLevel.values());
Map<String, Integer> wordFrequencyMap = WordFrequencyHelper.getWordFrequency(storyBook);
model.addAttribute("wordFrequencyMap", wordFrequencyMap);
Map<String, Integer> letterFrequencyMap = LetterFrequencyHelper.getLetterFrequency(storyBook);
model.addAttribute("letterFrequencyMap", letterFrequencyMap);
return "content/storybook/edit";
} else {
storyBook.setTimeLastUpdate(Calendar.getInstance());
storyBook.setRevisionNumber(storyBook.getRevisionNumber() + 1);
storyBookDao.update(storyBook);
if (EnvironmentContextLoaderListener.env == Environment.PROD) {
String text = URLEncoder.encode(contributor.getFirstName() + " just edited a StoryBook:\n" + "• Language: \"" + storyBook.getLocale().getLanguage() + "\"\n" + "• Title: \"" + storyBook.getTitle() + "\"\n" + "• Grade level: " + storyBook.getGradeLevel() + "\n" + "• Paragraphs: " + storyBook.getParagraphs() + "\n" + "See ") + "http://elimu.ai/content/storybook/edit/" + storyBook.getId();
String iconUrl = contributor.getImageUrl();
SlackApiHelper.postMessage(SlackApiHelper.getChannelId(Team.CONTENT_CREATION), text, iconUrl, null);
}
return "redirect:/content/storybook/list#" + storyBook.getId();
}
}
use of ai.elimu.model.content.StoryBook in project webapp by elimu-ai.
the class StoryBookEditController method handleRequest.
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public String handleRequest(Model model, @PathVariable Long id, HttpSession session) {
logger.info("handleRequest");
Contributor contributor = (Contributor) session.getAttribute("contributor");
StoryBook storyBook = storyBookDao.read(id);
model.addAttribute("storyBook", storyBook);
model.addAttribute("contentLicenses", ContentLicense.values());
List<Image> coverImages = imageDao.readAllOrdered(contributor.getLocale());
model.addAttribute("coverImages", coverImages);
model.addAttribute("gradeLevels", GradeLevel.values());
Map<String, Integer> wordFrequencyMap = WordFrequencyHelper.getWordFrequency(storyBook);
model.addAttribute("wordFrequencyMap", wordFrequencyMap);
Map<String, Integer> letterFrequencyMap = LetterFrequencyHelper.getLetterFrequency(storyBook);
model.addAttribute("letterFrequencyMap", letterFrequencyMap);
return "content/storybook/edit";
}
use of ai.elimu.model.content.StoryBook in project webapp by elimu-ai.
the class StoryBookListController method handleRequest.
@RequestMapping(method = RequestMethod.GET)
public String handleRequest(Model model, HttpSession session) {
logger.info("handleRequest");
Contributor contributor = (Contributor) session.getAttribute("contributor");
// To ease development/testing, auto-generate StoryBooks
List<StoryBook> storyBooksGenerated = generateStoryBooks(contributor.getLocale());
for (StoryBook storyBook : storyBooksGenerated) {
StoryBook existingStoryBook = storyBookDao.readByTitle(storyBook.getLocale(), storyBook.getTitle());
if (existingStoryBook == null) {
storyBookDao.create(storyBook);
}
}
List<StoryBook> storyBooks = storyBookDao.readAllOrdered(contributor.getLocale());
model.addAttribute("storyBooks", storyBooks);
return "content/storybook/list";
}
use of ai.elimu.model.content.StoryBook in project webapp by elimu-ai.
the class StoryBookListController method generateStoryBooks.
private List<StoryBook> generateStoryBooks(Locale locale) {
List<StoryBook> storyBooks = new ArrayList<>();
StoryBook storyBook = new StoryBook();
storyBook.setLocale(locale.EN);
storyBook.setTimeLastUpdate(Calendar.getInstance());
storyBook.setTitle("Too Small");
Image coverImage = imageDao.read("M_ASP_55_Too_small_Page_02_Image_0001", locale);
storyBook.setCoverImage(coverImage);
storyBook.setGradeLevel(GradeLevel.LEVEL3);
List<String> paragraphs = new ArrayList<>();
paragraphs.add("\"Mom,\" called Lebo. \"Come and look. These clothes are all too small for me!\"");
paragraphs.add("\"Let me see,\" said Mom.");
paragraphs.add("\"Look at my skirt. It's too small,\" said Lebo.");
paragraphs.add("\"Yes, it is,\" said Mom. \"Nomsa can have your skirt.\"");
paragraphs.add("\"Look at my jeans. They are too small,\" said Lebo.");
paragraphs.add("\"Yes, they are,\" said Mom. \"Nomsa can have your jeans.");
paragraphs.add("\"Look at my T-shirt. It's too small,\" said Lebo.");
paragraphs.add("\"Yes, it is,\" said Mom. \"Nomsa can have your T-shirt.");
paragraphs.add("\"Look at my jersey. It is too small,\" said Lebo.");
paragraphs.add("\"Yes, it is,\" said Mom. \"We will give your jersey to Nomsa.\"");
paragraphs.add("\"Look at my raincoat. It's too small,\" said Lebo.");
paragraphs.add("\"Yes, it is. Nomsa can have your raincoat,\" said Mom.");
paragraphs.add("\"Look at my socks. They are too small,\" said Lebo.");
paragraphs.add("\"Yes, they certainly are,\" said Mom. \"Nomsa can have your socks.\"");
paragraphs.add("\"Look at my shoes. They are too small,\" said Lebo.");
paragraphs.add("\"Yes, they are,\" said Mom. \"Nomsa can have your shoes.\"");
paragraphs.add("\"Now you have lots of clothes,\" said Lebo.");
paragraphs.add("\"Oh, no, I don't,\" said Nomsa.");
paragraphs.add("\"These clothes are all too BIG for me!\"");
storyBook.setParagraphs(paragraphs);
storyBooks.add(storyBook);
return storyBooks;
}
Aggregations