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