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 int maxWords = 0;
private Set<String> stopwordList = new HashSet<>();
private boolean sortList = false;
//Extract text from file with supported format
public String formatToText(File file, String format) {
@ -133,9 +134,14 @@ public class TextProcessing {
}
}
tokenStream.end();
if (maxWords > 0) {
if (maxWords > 0 || sortList) {
Map<String, Integer> sortedWords;
sortedWords = maxShowWords(sortList(words), maxWords);
if(maxWords > 0) {
sortedWords = maxShowWords(sortList(words), maxWords);
}
else {
sortedWords = sortList(words);
}
return sortedWords;
}
}
@ -152,4 +158,12 @@ public class TextProcessing {
public void setMaxWords(int 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() {
if(!(fl.getFilePath() == null)) {
if (wcm.insertWordsIntoTemplate(tp.tokenizingFile(tp.formatToText(fl.getFilePath(), fl.getFileFormat())))) {

View File

@ -64,7 +64,7 @@ public class TUI {
public void fileMenu() {
while(fMenu) {
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());
switch(option) {
case (0):
@ -90,7 +90,7 @@ public class TUI {
break;
case(2):
// 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());
wcm.setMaxWords(number);
break;
@ -106,6 +106,14 @@ public class TUI {
}
break;
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
if(wcm.createWordCloud()) {
System.out.println("HTML File created!\n");