use of ai.elimu.model.v2.enums.Language in project webapp by elimu-ai.
the class CustomDispatcherServlet method initWebApplicationContext.
@Override
protected WebApplicationContext initWebApplicationContext() {
logger.info("initWebApplicationContext");
WebApplicationContext webApplicationContext = super.initWebApplicationContext();
// Database migration
logger.info("Performing database migration...");
new DbMigrationHelper().performDatabaseMigration(webApplicationContext);
if (EnvironmentContextLoaderListener.env == Environment.DEV) {
// To ease development, pre-populate database with educational content extracted from the test server
// Lookup the language of the educational content from the config file
Language language = Language.valueOf(ConfigHelper.getProperty("content.language"));
logger.info("language: " + language);
// Import the educational content
logger.info("Performing database content import...");
new DbContentImportHelper().performDatabaseContentImport(Environment.TEST, language, webApplicationContext);
createJpaSchemaExport();
}
return webApplicationContext;
}
use of ai.elimu.model.v2.enums.Language in project webapp by elimu-ai.
the class WordCreationsPendingController method handleRequest.
@RequestMapping(method = RequestMethod.GET)
public String handleRequest(Model model) {
logger.info("handleRequest");
List<String> paragraphs = new ArrayList<>();
for (StoryBookParagraph storyBookParagraph : storyBookParagraphDao.readAll()) {
paragraphs.add(storyBookParagraph.getOriginalText());
}
logger.info("paragraphs.size(): " + paragraphs.size());
Language language = Language.valueOf(ConfigHelper.getProperty("content.language"));
Map<String, Integer> wordFrequencyMap = WordFrequencyHelper.getWordFrequency(paragraphs, language);
model.addAttribute("wordFrequencyMap", wordFrequencyMap);
logger.info("wordFrequencyMap.size(): " + wordFrequencyMap.size());
// Remove Words that have already been added
Iterator<String> wordTextIterator = wordFrequencyMap.keySet().iterator();
while (wordTextIterator.hasNext()) {
String wordText = wordTextIterator.next();
Word existingWord = wordDao.readByText(wordText);
if (existingWord != null) {
wordTextIterator.remove();
}
}
int maxUsageCount = 0;
for (Integer usageCount : wordFrequencyMap.values()) {
if (usageCount > maxUsageCount) {
maxUsageCount = usageCount;
}
}
model.addAttribute("maxUsageCount", maxUsageCount);
return "content/word/pending";
}
use of ai.elimu.model.v2.enums.Language in project webapp by elimu-ai.
the class ParagraphWordScheduler method execute.
// Every hour
@Scheduled(cron = "00 00 * * * *")
public synchronized void execute() {
logger.info("execute");
Language language = Language.valueOf(ConfigHelper.getProperty("content.language"));
List<StoryBookParagraph> storyBookParagraphs = storyBookParagraphDao.readAll();
logger.info("storyBookParagraphs.size(): " + storyBookParagraphs.size());
for (StoryBookParagraph storyBookParagraph : storyBookParagraphs) {
List<String> wordsInOriginalText = WordExtractionHelper.getWords(storyBookParagraph.getOriginalText(), language);
logger.info("wordsInOriginalText.size(): " + wordsInOriginalText.size());
// Look for matches of existing Words in the paragraph's original text
List<Word> words = new ArrayList<>();
for (String wordInOriginalText : wordsInOriginalText) {
logger.info("wordInOriginalText: \"" + wordInOriginalText + "\"");
wordInOriginalText = wordInOriginalText.toLowerCase();
logger.info("wordInOriginalText (lower-case): \"" + wordInOriginalText + "\"");
Word word = wordDao.readByText(wordInOriginalText);
logger.info("word: " + word);
words.add(word);
}
logger.info("words.size(): " + words.size());
storyBookParagraph.setWords(words);
// Update the paragraph's list of Words in the database
storyBookParagraphDao.update(storyBookParagraph);
}
// Refresh REST API cache
storyBooksJsonService.refreshStoryBooksJSONArray();
logger.info("execute complete");
}
use of ai.elimu.model.v2.enums.Language in project KaellyBot by Kaysoro.
the class LanguageCommand method request.
@Override
public void request(MessageCreateEvent event, Message message, Matcher m, Language lg) {
Optional<discord4j.core.object.entity.Guild> guild = message.getGuild().blockOptional();
Optional<MessageChannel> channel = message.getChannel().blockOptional();
if (guild.isPresent() && channel.isPresent())
if (m.group(2) != null) {
// Ajouts
String channelName = ((GuildMessageChannel) channel.get()).getName();
if (isUserHasEnoughRights(message)) {
List<Language> langs = new ArrayList<>();
for (Language lang : Language.values()) if (m.group(2).trim().toUpperCase().equals(lang.getAbrev()))
langs.add(lang);
if (langs.size() == 1) {
if (m.group(1) == null) {
Guild.getGuild(guild.get()).setLanguage(langs.get(0));
final Language LG = langs.get(0);
message.getChannel().flatMap(chan -> chan.createMessage(guild.get().getName() + " " + Translator.getLabel(LG, "lang.request.1") + " " + langs.get(0))).subscribe();
} else {
ChannelLanguage chan = ChannelLanguage.getChannelLanguages().get(channel.get().getId().asLong());
if (chan != null) {
if (chan.getLang().equals(langs.get(0))) {
chan.removeToDatabase();
final Language LG = Translator.getLanguageFrom(channel.get());
message.getChannel().flatMap(salon -> salon.createMessage(channelName + " " + Translator.getLabel(LG, "lang.request.2") + " " + Guild.getGuild(guild.get()).getLanguage())).subscribe();
} else {
chan.setLanguage(langs.get(0));
final Language LG = langs.get(0);
message.getChannel().flatMap(salon -> salon.createMessage(channelName + " " + Translator.getLabel(LG, "lang.request.1") + " " + chan.getLang())).subscribe();
}
} else {
final Language LG = langs.get(0);
final ChannelLanguage CHAN = new ChannelLanguage(langs.get(0), channel.get().getId().asLong());
CHAN.addToDatabase();
message.getChannel().flatMap(salon -> salon.createMessage(channelName + " " + Translator.getLabel(LG, "lang.request.1") + " " + CHAN.getLang())).subscribe();
}
}
} else if (langs.isEmpty())
notFoundLang.throwException(message, this, lg);
else
tooMuchLangs.throwException(message, this, lg);
} else
BasicDiscordException.NO_ENOUGH_RIGHTS.throwException(message, this, lg);
} else {
// Consultation
String text = "**" + guild.get().getName() + "** " + Translator.getLabel(lg, "lang.request.3") + " " + Guild.getGuild(guild.get()).getLanguage() + ".";
ChannelLanguage chanLang = ChannelLanguage.getChannelLanguages().get(channel.get().getId().asLong());
if (chanLang != null)
text += "\nLe salon *" + ((GuildMessageChannel) channel.get()).getName() + "* " + Translator.getLabel(lg, "lang.request.3") + " " + chanLang.getLang() + ".";
final String TEXT = text;
message.getChannel().flatMap(salon -> salon.createMessage(TEXT)).subscribe();
}
}
use of ai.elimu.model.v2.enums.Language in project KaellyBot by Kaysoro.
the class AbstractCommand method request.
@Override
public final void request(MessageCreateEvent event, Message message) {
Language lg = Translator.getLanguageFrom(message.getChannel().block());
try {
Matcher m = getMatcher(message);
boolean isFound = m.find();
// Caché si la fonction est désactivée/réservée aux admin et que l'auteur n'est pas super-admin
if ((!isPublic() || isAdmin()) && message.getAuthor().map(user -> user.getId().asLong() != Constants.authorId).orElse(false))
return;
// S'il s'agit d'une demande d'aide...
if (message.getContent().matches(Pattern.quote(getPrefix(message)) + getName() + "\\s+help")) {
message.getChannel().flatMap(chan -> chan.createMessage(helpDetailed(lg, getPrefix(message)))).subscribe();
return;
}
// La commande est trouvée
if (isFound) {
// Mais n'est pas utilisable en MP
MessageChannel channel = message.getChannel().block();
if (!isUsableInMP() && channel instanceof PrivateChannel) {
BasicDiscordException.NOT_USABLE_IN_MP.throwException(message, this, lg);
return;
} else // Mais est désactivée par la guilde
if (!(channel instanceof PrivateChannel) && message.getAuthor().map(user -> user.getId().asLong() != Constants.authorId).orElse(false) && isForbidden(Guild.getGuild(message.getGuild().block()))) {
BasicDiscordException.COMMAND_FORBIDDEN.throwException(message, this, lg);
return;
}
} else // Mais est mal utilisée
if (message.getContent().startsWith(getPrefix(message) + getName())) {
badUse.throwException(message, this, lg);
return;
}
if (isFound)
request(event, message, m, lg);
} catch (Exception e) {
BasicDiscordException.UNKNOWN_ERROR.throwException(message, this, lg);
Reporter.report(e);
LOG.error("request", e);
}
}
Aggregations