refactored Method name and added cutted Hashmap feature. Added new filter for filechooser #4
|
@ -51,7 +51,10 @@ public class FileManager {
|
|||
public File loadFileGUI() {
|
||||
try {
|
||||
JFileChooser fileChooser = new JFileChooser();
|
||||
fileChooser.setFileFilter(new FileNameExtensionFilter("PDF Files", "pdf"));
|
||||
fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("PDF Files", "pdf"));
|
||||
fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("Text Files", "txt"));
|
||||
fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("Word Documents", "docx"));
|
||||
fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("PowerPoint Presentations", "pptx"));
|
||||
int result = fileChooser.showOpenDialog(null);
|
||||
|
||||
if (result == JFileChooser.APPROVE_OPTION) {
|
||||
|
@ -63,25 +66,24 @@ public class FileManager {
|
|||
}
|
||||
}
|
||||
|
||||
public boolean processFile(File inputFile){
|
||||
boolean success = false;
|
||||
public HashMap tokenizingText(File inputFile){
|
||||
HashMap<String, Integer> filteredWords = new HashMap<>();
|
||||
try {
|
||||
PDDocument document = null;
|
||||
HashMap<String, Integer> filteredWords = new HashMap<>();
|
||||
if(inputFile != null) {
|
||||
document = PDDocument.load(inputFile);
|
||||
PDFTextStripper pdfStripper = new PDFTextStripper();
|
||||
String text = pdfStripper.getText(document);
|
||||
String splittedText = "[,\\s\\.:/!§$%&/()=?+*~#.;_<>^°]";
|
||||
|
||||
//Tokenizing der Wörter
|
||||
String splittedText = "[,\\s\\.:/!§$%&/()=?+*~#.;_<>^°\"']";
|
||||
String[] textWords = text.split(splittedText);
|
||||
for(String word : textWords){
|
||||
// if(Character.isLetter(word.charAt(0)) && Character.isLetter((word.charAt(word.length() - 1)))) {
|
||||
if (filteredWords.containsKey(word)) {
|
||||
filteredWords.compute(word, (k, counter) -> counter + 1);
|
||||
}
|
||||
// }
|
||||
else {
|
||||
filteredWords.put(word, 0);
|
||||
filteredWords.put(word, 1);
|
||||
}
|
||||
}
|
||||
for(Map.Entry e : filteredWords.entrySet()){
|
||||
|
@ -91,11 +93,22 @@ public class FileManager {
|
|||
document.close();
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return success;
|
||||
return filteredWords;
|
||||
}
|
||||
|
||||
public HashMap maxShowWords(int number, HashMap<String, Integer> words) {
|
||||
HashMap <String, Integer> cuttedHashmap = new HashMap<>();
|
||||
int index = number;
|
||||
for (String word : words.keySet()) {
|
||||
if(index > 0) {
|
||||
cuttedHashmap.put(word, words.get(word));
|
||||
}
|
||||
index--;
|
||||
}
|
||||
return cuttedHashmap;
|
||||
}
|
||||
|
||||
public void saveFile(){}
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
package domain;
|
||||
|
||||
public class PictureManager {
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import domain.PictureManager;
|
|||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class WordCloudManager {
|
||||
FileManager fileManager;
|
||||
|
@ -17,10 +18,14 @@ public class WordCloudManager {
|
|||
}
|
||||
|
||||
public boolean loadFileGUI() {
|
||||
boolean success = false;
|
||||
File inputFile = fileManager.loadFileGUI();
|
||||
success = fileManager.processFile(inputFile);
|
||||
return success;
|
||||
HashMap wordMap = fileManager.tokenizingText(inputFile);
|
||||
if(wordMap == null) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public void loadFilePath() {
|
||||
|
|
|
@ -32,6 +32,8 @@ public class TUI {
|
|||
//Load File GUI
|
||||
if(wcm.loadFileGUI()) {
|
||||
System.out.println("File loaded successful!\n");
|
||||
} else {
|
||||
System.out.println("File cannot be loaded!\n");
|
||||
}
|
||||
break;
|
||||
case (2):
|
||||
|
|
Loading…
Reference in New Issue