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