Search in sources :

Example 21 with Language

use of ai.elimu.model.v2.enums.Language in project KaellyBot by Kaysoro.

the class RSSCommand method request.

@Override
public boolean request(IMessage message) {
    if (super.request(message)) {
        Language lg = Translator.getLanguageFrom(message.getChannel());
        // On check si la personne a bien les droits pour exécuter cette commande
        if (isUserHasEnoughRights(message)) {
            Matcher m = getMatcher(message);
            m.find();
            String value = m.group(1);
            if (value.matches("\\s+true") || value.matches("\\s+0") || value.matches("\\s+on")) {
                if (!RSSFinder.getRSSFinders().containsKey(message.getChannel().getStringID())) {
                    new RSSFinder(message.getGuild().getStringID(), message.getChannel().getStringID()).addToDatabase();
                    Message.sendText(message.getChannel(), Translator.getLabel(lg, "rss.request.1").replace("{game.url}", Translator.getLabel(lg, "game.url")));
                } else
                    rssFound.throwException(message, this, lg);
            } else if (value.matches("\\s+false") || value.matches("\\s+1") || value.matches("\\s+off"))
                if (RSSFinder.getRSSFinders().containsKey(message.getChannel().getStringID())) {
                    RSSFinder.getRSSFinders().get(message.getChannel().getStringID()).removeToDatabase();
                    Message.sendText(message.getChannel(), Translator.getLabel(lg, "rss.request.2").replace("{game.url}", Translator.getLabel(lg, "game.url")));
                } else
                    rssNotFound.throwException(message, this, lg);
            else
                new BadUseCommandDiscordException().throwException(message, this, lg);
        } else
            noEnoughRights.throwException(message, this, lg);
    }
    return false;
}
Also used : Language(enums.Language) Matcher(java.util.regex.Matcher) RSSFinder(finders.RSSFinder)

Example 22 with Language

use of ai.elimu.model.v2.enums.Language in project KaellyBot by Kaysoro.

the class TwitterCommand method request.

@Override
public boolean request(IMessage message) {
    if (super.request(message)) {
        Language lg = Translator.getLanguageFrom(message.getChannel());
        // On check si la personne a bien les droits pour exécuter cette commande
        if (isUserHasEnoughRights(message)) {
            Matcher m = getMatcher(message);
            m.find();
            String value = m.group(1);
            if (value.matches("\\s+true") || value.matches("\\s+0") || value.matches("\\s+on")) {
                if (!TwitterFinder.getTwitterChannels().containsKey(message.getChannel().getLongID())) {
                    new TwitterFinder(message.getGuild().getLongID(), message.getChannel().getLongID()).addToDatabase();
                    Message.sendText(message.getChannel(), Translator.getLabel(lg, "twitter.request.1").replace("{twitter.name}", Translator.getLabel(lg, "twitter.name")));
                } else
                    twitterFound.throwException(message, this, lg);
            } else if (value.matches("\\s+false") || value.matches("\\s+1") || value.matches("\\s+off")) {
                if (TwitterFinder.getTwitterChannels().containsKey(message.getChannel().getLongID())) {
                    TwitterFinder.getTwitterChannels().get(message.getChannel().getLongID()).removeToDatabase();
                    Message.sendText(message.getChannel(), Translator.getLabel(lg, "twitter.request.2").replace("{twitter.name}", Translator.getLabel(lg, "twitter.name")));
                } else
                    twitterNotFound.throwException(message, this, lg);
            } else
                new BadUseCommandDiscordException().throwException(message, this, lg);
        } else
            noEnoughRights.throwException(message, this, lg);
    }
    return false;
}
Also used : Language(enums.Language) Matcher(java.util.regex.Matcher) TwitterFinder(finders.TwitterFinder)

Example 23 with Language

use of ai.elimu.model.v2.enums.Language in project webapp by elimu-ai.

the class LetterUsageCountScheduler method execute.

// At 06:15 every day
@Scheduled(cron = "00 15 06 * * *")
public synchronized void execute() {
    logger.info("execute");
    logger.info("Calculating usage count for Letters");
    Map<String, Integer> letterFrequencyMap = new HashMap<>();
    Language language = Language.valueOf(ConfigHelper.getProperty("content.language"));
    List<StoryBook> storyBooks = storyBookDao.readAllOrdered();
    logger.info("storyBooks.size(): " + storyBooks.size());
    for (StoryBook storyBook : storyBooks) {
        logger.info("storyBook.getTitle(): " + storyBook.getTitle());
        List<String> paragraphs = new ArrayList<>();
        List<StoryBookChapter> storyBookChapters = storyBookChapterDao.readAll(storyBook);
        for (StoryBookChapter storyBookChapter : storyBookChapters) {
            List<StoryBookParagraph> storyBookParagraphs = storyBookParagraphDao.readAll(storyBookChapter);
            for (StoryBookParagraph storyBookParagraph : storyBookParagraphs) {
                paragraphs.add(storyBookParagraph.getOriginalText());
            }
        }
        Map<String, Integer> letterFrequencyMapForBook = LetterFrequencyHelper.getLetterFrequency(paragraphs, language);
        letterFrequencyMapForBook.keySet().forEach(letterText -> letterFrequencyMap.put(letterText, letterFrequencyMap.getOrDefault(letterText, 0) + letterFrequencyMapForBook.get(letterText)));
    }
    logger.info("letterFrequencyMap: " + letterFrequencyMap);
    for (String letterText : letterFrequencyMap.keySet()) {
        Letter existingLetter = letterDao.readByText(letterText);
        if (existingLetter != null) {
            existingLetter.setUsageCount(letterFrequencyMap.get(letterText));
            letterDao.update(existingLetter);
        }
    }
    logger.info("execute complete");
}
Also used : StoryBookChapter(ai.elimu.model.content.StoryBookChapter) StoryBook(ai.elimu.model.content.StoryBook) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StoryBookParagraph(ai.elimu.model.content.StoryBookParagraph) Letter(ai.elimu.model.content.Letter) Language(ai.elimu.model.v2.enums.Language) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 24 with Language

use of ai.elimu.model.v2.enums.Language in project webapp by elimu-ai.

the class WordUsageCountScheduler method execute.

// At 06:00 every day
@Scheduled(cron = "00 00 06 * * *")
public synchronized void execute() {
    logger.info("execute");
    logger.info("Calculating usage count for Words");
    Map<String, Integer> wordFrequencyMap = new HashMap<>();
    Language language = Language.valueOf(ConfigHelper.getProperty("content.language"));
    List<StoryBook> storyBooks = storyBookDao.readAllOrdered();
    logger.info("storyBooks.size(): " + storyBooks.size());
    for (StoryBook storyBook : storyBooks) {
        logger.info("storyBook.getTitle(): " + storyBook.getTitle());
        List<String> paragraphs = new ArrayList<>();
        List<StoryBookChapter> storyBookChapters = storyBookChapterDao.readAll(storyBook);
        for (StoryBookChapter storyBookChapter : storyBookChapters) {
            List<StoryBookParagraph> storyBookParagraphs = storyBookParagraphDao.readAll(storyBookChapter);
            for (StoryBookParagraph storyBookParagraph : storyBookParagraphs) {
                paragraphs.add(storyBookParagraph.getOriginalText());
            }
        }
        Map<String, Integer> wordFrequencyMapForBook = WordFrequencyHelper.getWordFrequency(paragraphs, language);
        wordFrequencyMapForBook.keySet().forEach(word -> wordFrequencyMap.put(word, wordFrequencyMap.getOrDefault(word, 0) + wordFrequencyMapForBook.get(word)));
    }
    for (String key : wordFrequencyMap.keySet()) {
        String wordLowerCase = key.toLowerCase();
        logger.info("wordLowerCase: \"" + wordLowerCase + "\"");
        Word word = wordDao.readByText(wordLowerCase);
        if (word != null) {
            word.setUsageCount(wordFrequencyMap.get(wordLowerCase));
            wordDao.update(word);
        }
    }
    logger.info("execute complete");
}
Also used : StoryBookChapter(ai.elimu.model.content.StoryBookChapter) StoryBook(ai.elimu.model.content.StoryBook) Word(ai.elimu.model.content.Word) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StoryBookParagraph(ai.elimu.model.content.StoryBookParagraph) Language(ai.elimu.model.v2.enums.Language) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 25 with Language

use of ai.elimu.model.v2.enums.Language 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) {
    logger.info("handleRequest");
    StoryBook storyBook = storyBookDao.read(id);
    model.addAttribute("storyBook", storyBook);
    model.addAttribute("timeStart", System.currentTimeMillis());
    model.addAttribute("contentLicenses", ContentLicense.values());
    List<Image> coverImages = imageDao.readAllOrdered();
    model.addAttribute("coverImages", coverImages);
    model.addAttribute("readingLevels", ReadingLevel.values());
    List<StoryBookChapter> storyBookChapters = storyBookChapterDao.readAll(storyBook);
    model.addAttribute("storyBookChapters", storyBookChapters);
    // Map<StoryBookChapter.id, List<StoryBookParagraph>>
    Map<Long, List<StoryBookParagraph>> paragraphsPerStoryBookChapterMap = new HashMap<>();
    for (StoryBookChapter storyBookChapter : storyBookChapters) {
        paragraphsPerStoryBookChapterMap.put(storyBookChapter.getId(), storyBookParagraphDao.readAll(storyBookChapter));
    }
    model.addAttribute("paragraphsPerStoryBookChapterMap", paragraphsPerStoryBookChapterMap);
    List<String> paragraphs = new ArrayList<>();
    for (StoryBookChapter storyBookChapter : storyBookChapters) {
        List<StoryBookParagraph> storyBookParagraphs = storyBookParagraphDao.readAll(storyBookChapter);
        for (StoryBookParagraph storyBookParagraph : storyBookParagraphs) {
            paragraphs.add(storyBookParagraph.getOriginalText());
        }
    }
    model.addAttribute("storyBookContributionEvents", storyBookContributionEventDao.readAll(storyBook));
    model.addAttribute("storyBookPeerReviewEvents", storyBookPeerReviewEventDao.readAll(storyBook));
    Language language = Language.valueOf(ConfigHelper.getProperty("content.language"));
    Map<String, Integer> wordFrequencyMap = WordFrequencyHelper.getWordFrequency(paragraphs, language);
    model.addAttribute("wordFrequencyMap", wordFrequencyMap);
    Map<String, Word> wordMap = new HashMap<>();
    for (Word word : wordDao.readAllOrdered()) {
        wordMap.put(word.getText(), word);
    }
    model.addAttribute("wordMap", wordMap);
    model.addAttribute("emojisByWordId", getEmojisByWordId());
    Map<String, Integer> letterFrequencyMap = LetterFrequencyHelper.getLetterFrequency(paragraphs, language);
    model.addAttribute("letterFrequencyMap", letterFrequencyMap);
    Map<String, Letter> letterMap = new HashMap<>();
    for (Letter letter : letterDao.readAllOrdered()) {
        letterMap.put(letter.getText(), letter);
    }
    model.addAttribute("letterMap", letterMap);
    return "content/storybook/edit";
}
Also used : StoryBookChapter(ai.elimu.model.content.StoryBookChapter) StoryBook(ai.elimu.model.content.StoryBook) Word(ai.elimu.model.content.Word) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StoryBookParagraph(ai.elimu.model.content.StoryBookParagraph) Image(ai.elimu.model.content.multimedia.Image) Letter(ai.elimu.model.content.Letter) Language(ai.elimu.model.v2.enums.Language) ArrayList(java.util.ArrayList) List(java.util.List) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Language (enums.Language)43 Matcher (java.util.regex.Matcher)27 ArrayList (java.util.ArrayList)19 IOException (java.io.IOException)13 Language (ai.elimu.model.v2.enums.Language)12 StoryBookParagraph (ai.elimu.model.content.StoryBookParagraph)10 Word (ai.elimu.model.content.Word)10 HashMap (java.util.HashMap)7 StoryBook (ai.elimu.model.content.StoryBook)6 StoryBookChapter (ai.elimu.model.content.StoryBookChapter)6 ChannelLanguage (data.ChannelLanguage)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 Letter (ai.elimu.model.content.Letter)5 List (java.util.List)5 Image (ai.elimu.model.content.multimedia.Image)4 AbstractCommand (commands.model.AbstractCommand)4 Command (commands.model.Command)4 Guild (data.Guild)4 Scheduled (org.springframework.scheduling.annotation.Scheduled)4 Audio (ai.elimu.model.content.multimedia.Audio)3