11package ai .elimu .web .content .word ;
22
33import ai .elimu .dao .EmojiDao ;
4+ import ai .elimu .dao .StoryBookParagraphDao ;
45import ai .elimu .dao .WordDao ;
56import ai .elimu .entity .content .Emoji ;
7+ import ai .elimu .entity .content .StoryBookParagraph ;
68import ai .elimu .entity .content .Word ;
9+ import ai .elimu .model .v2 .enums .Language ;
10+ import ai .elimu .util .ConfigHelper ;
11+ import ai .elimu .util .WordFrequencyHelper ;
712
13+ import java .util .ArrayList ;
814import java .util .HashMap ;
915import java .util .List ;
1016import java .util .Map ;
@@ -26,6 +32,8 @@ public class WordListController {
2632
2733 private final EmojiDao emojiDao ;
2834
35+ private final StoryBookParagraphDao storyBookParagraphDao ;
36+
2937 @ GetMapping
3038 public String handleRequest (Model model ) {
3139 log .info ("handleRequest" );
@@ -42,6 +50,17 @@ public String handleRequest(Model model) {
4250 }
4351 model .addAttribute ("maxUsageCount" , maxUsageCount );
4452
53+ // Extract letter frequency distribution from storybook paragraphs
54+ List <String > wordsInParagraphs = new ArrayList <>();
55+ for (StoryBookParagraph storyBookParagraph : storyBookParagraphDao .readAll ()) {
56+ for (String word : storyBookParagraph .getOriginalText ().split (" " )) {
57+ wordsInParagraphs .add (word );
58+ }
59+ }
60+ Language language = Language .valueOf (ConfigHelper .getProperty ("content.language" ));
61+ Map <String , Integer > wordFrequencyMap = WordFrequencyHelper .getWordFrequency (wordsInParagraphs , language );
62+ model .addAttribute ("wordFrequencyMap" , wordFrequencyMap );
63+
4564 return "content/word/list" ;
4665 }
4766
0 commit comments