Compare commits

..

No commits in common. "40e0988a11dc8800f2bc569315cb2150ee5ed422" and "373e6b4712be96d0d4175919be330c4b8b1f4cec" have entirely different histories.

6 changed files with 27 additions and 83 deletions

View File

@ -11,7 +11,7 @@ public class FileLoader {
public FileLoader() { public FileLoader() {
this.inputFile = null; this.inputFile = null;
} }
//KI erstellte Methode mit anpassungen //KI erstellte Methode
public File loadFileGUI() { public File loadFileGUI() {
try { try {
JFileChooser fileChooser = new JFileChooser(); JFileChooser fileChooser = new JFileChooser();
@ -30,7 +30,6 @@ public class FileLoader {
} }
} }
//Methode sucht das Datei Format für spätere Verwendung
public String getFileFormat(File file) { public String getFileFormat(File file) {
String fileName = file.getName(); String fileName = file.getName();
String fileFormat = fileName.contains(".") ? fileName.substring(fileName.lastIndexOf(".") + 1) : ""; String fileFormat = fileName.contains(".") ? fileName.substring(fileName.lastIndexOf(".") + 1) : "";

View File

@ -23,19 +23,18 @@ public class TextProcessing {
private boolean stemming; private boolean stemming;
private int maxWords; private int maxWords;
// für spätere verwendung mit umfangreichen anpassungen public boolean isStemming() {
// public boolean isStemming() { return stemming;
// return stemming; }
// }
// public int getMaxWords() {
// public int getMaxWords() { return maxWords;
// return maxWords; }
// }
// public void setStemming(boolean stemming) {
// public void setStemming(boolean stemming) { this.stemming = stemming;
// this.stemming = stemming; }
// }
//
public void setMaxWords(int maxWords) { public void setMaxWords(int maxWords) {
this.maxWords = maxWords; this.maxWords = maxWords;
} }

View File

@ -1,59 +0,0 @@
package domain;
import java.io.*;
import java.util.Map;
public class WordCloudCreator {
//Ki erstellte Methode wegen Zeitgründen und Krankheitsgründen, dennoch anpassungen in großen Maße waren notwendig
public void insertWordsIntoTemplate(Map<String, Integer> wordMap) {
File templateFile = new File("wordcloud.html"); // Template in project directory
File outputFile = new File("output.html"); // Output in project directory
if (!templateFile.exists()) {
throw new RuntimeException("Template file 'wordcloud.html' not found in project directory.");
}
try (BufferedReader reader = new BufferedReader(new FileReader(templateFile));
BufferedWriter writer = new BufferedWriter(new FileWriter(outputFile))) {
StringBuilder htmlContent = new StringBuilder();
String line;
// Read the HTML template
while ((line = reader.readLine()) != null) {
htmlContent.append(line).append("\n");
}
// Generate clickable word entries with font size based on frequency
StringBuilder wordEntries = new StringBuilder();
int id = 1;
for (Map.Entry<String, Integer> entry : wordMap.entrySet()) {
String word = entry.getKey();
int frequency = entry.getValue();
int fontSize = (int) ((float) 12 + frequency * 1.5); // Example: Base size 10px, increase by 2px per frequency
wordEntries.append(String.format(
"<span id=\"%d\" class=\"wrd\" style=\"font-size:%dpx;\">" +
"<a href=\"https://www.google.com/search?q=%s\" target=\"_blank\">%s</a>" +
"</span>\n",
id++, fontSize, word, word
));
}
// Replace placeholder inside the div
String updatedHtml = htmlContent.toString();
if (updatedHtml.contains("<!-- TODO: Hier die generierten Tags einsetzen -->")) {
updatedHtml = updatedHtml.replace("<!-- TODO: Hier die generierten Tags einsetzen -->", wordEntries);
} else {
throw new RuntimeException("Placeholder for tags not found in the template.");
}
// Write the updated HTML to the output file
writer.write(updatedHtml);
System.out.println("Output file 'output.html' created successfully!");
} catch (IOException e) {
throw new RuntimeException("Error processing HTML template", e);
}
}
}

View File

@ -60,17 +60,19 @@ public class WordCloudManager {
System.out.println(stopwordList); System.out.println(stopwordList);
} }
// für spätere Verwendung mit umfangreichen Änderungen im Code
// public void stemming(String approval) { public void stemming(String approval) {
// if(approval.equals("yes")) { if(approval.equals("yes")) {
// processing.setStemming(true); processing.setStemming(true);
// } }
// } }
public void maxWordsInList(int number) { public void maxWordsInList(int number) {
processing.setMaxWords(number); processing.setMaxWords(number);
} }
// ab hier noch nicht fertig.
public void tokenizingText() { public void tokenizingText() {
wordMap = (HashMap<String, Integer>) processing.tokenizingFile(processing.fileToTextString(filePath, fileFormat) wordMap = (HashMap<String, Integer>) processing.tokenizingFile(processing.fileToTextString(filePath, fileFormat)
, !stopwordList.isEmpty() ? stopwordList : null); , !stopwordList.isEmpty() ? stopwordList : null);
@ -78,6 +80,8 @@ public class WordCloudManager {
} }
public void cutWordsList() { public void cutWordsList() {
wordMap = (HashMap<String, Integer>) processing.maxShowWords(processing.sortList(wordMap)); wordMap = (HashMap<String, Integer>) processing.maxShowWords(processing.sortList(wordMap));
processing.sortList(wordMap); processing.sortList(wordMap);
System.out.println(wordMap.keySet() + "\n" + wordMap.values()); System.out.println(wordMap.keySet() + "\n" + wordMap.values());

View File

@ -1,7 +1,6 @@
package tui; package tui;
public class Main { public class Main {
//startet die GUI
public static void main(String[]args){ public static void main(String[]args){
new TUI(); new TUI();
} }

View File

@ -21,6 +21,8 @@ public class TUI {
} }
public void tui() { public void tui() {
while(isRunning) { while(isRunning) {
System.out.println("Welcome to Word Cloud.\nType number in the following Menu to access your targeted Option.\nMenu:\n\n(0) Load File\n(1) URL Path" + System.out.println("Welcome to Word Cloud.\nType number in the following Menu to access your targeted Option.\nMenu:\n\n(0) Load File\n(1) URL Path" +
"\n(2) Exit"); "\n(2) Exit");
@ -78,8 +80,8 @@ public class TUI {
case(3): case(3):
// Set Stemming // Set Stemming
System.out.println("Set Stemming: Input 'yes' or 'no'"); System.out.println("Set Stemming: Input 'yes' or 'no'");
// String stemmingOption = scan.nextLine(); String stemmingOption = scan.nextLine();
// wcm.stemming(stemmingOption); wcm.stemming(stemmingOption);
break; break;
case(4): case(4):
//Create WordCloud //Create WordCloud