package domain; import java.io.*; import java.util.Map; public class WordCloudCreator { private int maxFontSize = 70; public boolean insertWordsIntoTemplate(Map wordMap) { File templateFile = new File("wordcloud.html"); // Template in project directory File outputFile = new File("createdHTML.html"); // Output in project directory try (BufferedReader reader = new BufferedReader(new FileReader(templateFile)); BufferedWriter writer = new BufferedWriter(new FileWriter(outputFile))) { StringBuilder htmlContent = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { htmlContent.append(line).append("\n"); } //AI generated lines below // Generated clickable word entries with font size based on frequency StringBuilder wordEntries = new StringBuilder(); int id = 1; for (Map.Entry entry : wordMap.entrySet()) { String word = entry.getKey(); int frequency = entry.getValue(); int fontSize = Math.min(10 + frequency * 2, maxFontSize); // Example: Base size 10px, increase by 2px per frequency wordEntries.append(String.format( "" + "%s" + "\n", id++, fontSize, word, word )); } // Replace placeholder inside the div String updatedHtml = htmlContent.toString(); if (updatedHtml.contains("")) { updatedHtml = updatedHtml.replace("", wordEntries); } else { throw new RuntimeException("Placeholder for tags not found in the template."); } // Write the updated HTML to the output file writer.write(updatedHtml); return true; } catch (IOException e) { throw new RuntimeException("Error processing HTML template", e); } } }