Search in sources :

Example 6 with StoryBook

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));
}
Also used : StoryBook(ai.elimu.model.content.StoryBook) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 7 with StoryBook

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();
    }
}
Also used : StoryBook(ai.elimu.model.content.StoryBook) Contributor(ai.elimu.model.Contributor) Image(ai.elimu.model.content.multimedia.Image) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with StoryBook

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";
}
Also used : StoryBook(ai.elimu.model.content.StoryBook) Contributor(ai.elimu.model.Contributor) Image(ai.elimu.model.content.multimedia.Image) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with StoryBook

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";
}
Also used : StoryBook(ai.elimu.model.content.StoryBook) Contributor(ai.elimu.model.Contributor) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with StoryBook

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;
}
Also used : StoryBook(ai.elimu.model.content.StoryBook) ArrayList(java.util.ArrayList) Image(ai.elimu.model.content.multimedia.Image)

Aggregations

StoryBook (ai.elimu.model.content.StoryBook)13 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 Contributor (ai.elimu.model.Contributor)5 Image (ai.elimu.model.content.multimedia.Image)5 ArrayList (java.util.ArrayList)4 Locale (ai.elimu.model.enums.Locale)3 HashMap (java.util.HashMap)3 Test (org.junit.Test)3 Scheduled (org.springframework.scheduling.annotation.Scheduled)3 Word (ai.elimu.model.content.Word)2 Letter (ai.elimu.model.content.Letter)1 Syllable (ai.elimu.model.content.Syllable)1 StoryBookGson (ai.elimu.model.gson.content.StoryBookGson)1 Gson (com.google.gson.Gson)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1