full-project #7
|
@ -11,7 +11,7 @@ public class FileLoader {
|
||||||
public FileLoader() {
|
public FileLoader() {
|
||||||
this.inputFile = null;
|
this.inputFile = null;
|
||||||
}
|
}
|
||||||
//KI erstellte Methode
|
//KI erstellte Methode mit anpassungen
|
||||||
public File loadFileGUI() {
|
public File loadFileGUI() {
|
||||||
try {
|
try {
|
||||||
JFileChooser fileChooser = new JFileChooser();
|
JFileChooser fileChooser = new JFileChooser();
|
||||||
|
@ -30,6 +30,7 @@ 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) : "";
|
||||||
|
|
|
@ -23,18 +23,19 @@ public class TextProcessing {
|
||||||
private boolean stemming;
|
private boolean stemming;
|
||||||
private int maxWords;
|
private int maxWords;
|
||||||
|
|
||||||
public boolean isStemming() {
|
// für spätere verwendung mit umfangreichen anpassungen
|
||||||
return stemming;
|
// public boolean isStemming() {
|
||||||
}
|
// return stemming;
|
||||||
|
// }
|
||||||
public int getMaxWords() {
|
//
|
||||||
return maxWords;
|
// public int getMaxWords() {
|
||||||
}
|
// return maxWords;
|
||||||
|
// }
|
||||||
public void setStemming(boolean stemming) {
|
//
|
||||||
this.stemming = stemming;
|
// public void setStemming(boolean stemming) {
|
||||||
}
|
// this.stemming = stemming;
|
||||||
|
// }
|
||||||
|
//
|
||||||
public void setMaxWords(int maxWords) {
|
public void setMaxWords(int maxWords) {
|
||||||
this.maxWords = maxWords;
|
this.maxWords = maxWords;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,59 @@
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -60,19 +60,17 @@ 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);
|
||||||
|
@ -80,8 +78,6 @@ 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());
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
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();
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,8 +21,6 @@ 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");
|
||||||
|
@ -80,8 +78,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
|
||||||
|
|
Loading…
Reference in New Issue