implement sortList as extra selection in menu

main
Daniel Fromm 2025-05-13 10:55:55 +02:00
parent 59857d1173
commit f256a6eacc
3 changed files with 32 additions and 4 deletions

View File

@ -23,6 +23,7 @@ public class TextProcessing {
private boolean stemming = false; private boolean stemming = false;
private int maxWords = 0; private int maxWords = 0;
private Set<String> stopwordList = new HashSet<>(); private Set<String> stopwordList = new HashSet<>();
private boolean sortList = false;
//Extract text from file with supported format //Extract text from file with supported format
public String formatToText(File file, String format) { public String formatToText(File file, String format) {
@ -133,9 +134,14 @@ public class TextProcessing {
} }
} }
tokenStream.end(); tokenStream.end();
if (maxWords > 0) { if (maxWords > 0 || sortList) {
Map<String, Integer> sortedWords; Map<String, Integer> sortedWords;
if(maxWords > 0) {
sortedWords = maxShowWords(sortList(words), maxWords); sortedWords = maxShowWords(sortList(words), maxWords);
}
else {
sortedWords = sortList(words);
}
return sortedWords; return sortedWords;
} }
} }
@ -152,4 +158,12 @@ public class TextProcessing {
public void setMaxWords(int maxWords) { public void setMaxWords(int maxWords) {
this.maxWords = maxWords; this.maxWords = maxWords;
} }
public void setSortList(boolean sortList) {
this.sortList = sortList;
}
public int getMaxWords() {
return maxWords;
}
} }

View File

@ -65,6 +65,12 @@ public class WordCloudManager {
} }
} }
public void setSorting(boolean sort) {
if(tp.getMaxWords() == 0) {
tp.setSortList(sort);
}
}
public boolean createWordCloud() { public boolean createWordCloud() {
if(!(fl.getFilePath() == null)) { if(!(fl.getFilePath() == null)) {
if (wcm.insertWordsIntoTemplate(tp.tokenizingFile(tp.formatToText(fl.getFilePath(), fl.getFileFormat())))) { if (wcm.insertWordsIntoTemplate(tp.tokenizingFile(tp.formatToText(fl.getFilePath(), fl.getFileFormat())))) {

View File

@ -64,7 +64,7 @@ public class TUI {
public void fileMenu() { public void fileMenu() {
while(fMenu) { while(fMenu) {
System.out.println("(0) Load Stopwords\n(1) Add to Stopwords\n(2) Set Max Words in HTML\n" + System.out.println("(0) Load Stopwords\n(1) Add to Stopwords\n(2) Set Max Words in HTML\n" +
"(3) Activate German stemming\n(4) Create WordCloud and Exit"); "(3) Activate German stemming\n(4) Sort List?\n(5) Create WordCloud and Exit");
option = Integer.parseInt(scan.nextLine()); option = Integer.parseInt(scan.nextLine());
switch(option) { switch(option) {
case (0): case (0):
@ -90,7 +90,7 @@ public class TUI {
break; break;
case(2): case(2):
// Set number of max words // Set number of max words
System.out.println("How much max words do you want? "); System.out.println("How much max words do you want? \nList will be sorted after highest frequenzy.");
int number = Integer.parseInt(scan.nextLine()); int number = Integer.parseInt(scan.nextLine());
wcm.setMaxWords(number); wcm.setMaxWords(number);
break; break;
@ -106,6 +106,14 @@ public class TUI {
} }
break; break;
case(4): case(4):
//Sort list
System.out.println("Sort list for highest frequenzy? 'yes' or 'no'");
String sorting = scan.nextLine();
if(sorting.equals("yes")) {
wcm.setSorting(true);
}
break;
case(5):
//Create WordCloud and exit program //Create WordCloud and exit program
if(wcm.createWordCloud()) { if(wcm.createWordCloud()) {
System.out.println("HTML File created!\n"); System.out.println("HTML File created!\n");