use of ai.elimu.model.content.StoryBookParagraph 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.content.StoryBookParagraph in project webapp by elimu-ai.
the class StoryBooksJsonService method getStoryBooksJSONArray.
@Cacheable("storyBooks")
public JSONArray getStoryBooksJSONArray() {
logger.info("getStoryBooksJSONArray");
Date dateStart = new Date();
JSONArray storyBooksJsonArray = new JSONArray();
for (StoryBook storyBook : storyBookDao.readAllOrdered()) {
StoryBookGson storyBookGson = JpaToGsonConverter.getStoryBookGson(storyBook);
// Add chapters
List<StoryBookChapterGson> storyBookChapterGsons = new ArrayList<>();
for (StoryBookChapter storyBookChapter : storyBookChapterDao.readAll(storyBook)) {
StoryBookChapterGson storyBookChapterGson = JpaToGsonConverter.getStoryBookChapterGson(storyBookChapter);
// Add paragraphs
List<StoryBookParagraphGson> storyBookParagraphGsons = new ArrayList<>();
for (StoryBookParagraph storyBookParagraph : storyBookParagraphDao.readAll(storyBookChapter)) {
StoryBookParagraphGson storyBookParagraphGson = JpaToGsonConverter.getStoryBookParagraphGson(storyBookParagraph);
storyBookParagraphGsons.add(storyBookParagraphGson);
}
storyBookChapterGson.setStoryBookParagraphs(storyBookParagraphGsons);
storyBookChapterGsons.add(storyBookChapterGson);
}
storyBookGson.setStoryBookChapters(storyBookChapterGsons);
String json = new Gson().toJson(storyBookGson);
storyBooksJsonArray.put(new JSONObject(json));
}
Date dateEnd = new Date();
logger.info("getStoryBooksJSONArray duration: " + (dateEnd.getTime() - dateStart.getTime()) + " ms");
return storyBooksJsonArray;
}
use of ai.elimu.model.content.StoryBookParagraph 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.content.StoryBookParagraph in project webapp by elimu-ai.
the class StringToStoryBookParagraphConverter method convert.
/**
* Convert StoryBookParagraph id to StoryBookParagraph entity
*/
public StoryBookParagraph convert(String id) {
if (StringUtils.isBlank(id)) {
return null;
} else {
Long storyBookParagraphId = Long.parseLong(id);
StoryBookParagraph storyBookParagraph = storyBookParagraphDao.read(storyBookParagraphId);
return storyBookParagraph;
}
}
Aggregations