parent
39624fa4f2
commit
10666b4453
@ -1,260 +1,260 @@
|
|||||||
package gui;
|
//package gui;
|
||||||
|
//
|
||||||
import static alg.XML_processing.*;
|
//import static alg.XML_processing.*;
|
||||||
import static gui.GUIController.*;
|
//import static gui.GUIController.*;
|
||||||
|
//
|
||||||
import java.io.File;
|
//import java.io.File;
|
||||||
import java.io.UnsupportedEncodingException;
|
//import java.io.UnsupportedEncodingException;
|
||||||
import java.util.*;
|
//import java.util.*;
|
||||||
|
//
|
||||||
import javafx.application.HostServices;
|
//import javafx.application.HostServices;
|
||||||
import javafx.scene.control.*;
|
//import javafx.scene.control.*;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
//import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.logging.log4j.LogManager;
|
//import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
//import org.apache.logging.log4j.Logger;
|
||||||
import org.controlsfx.control.CheckComboBox;
|
//import org.controlsfx.control.CheckComboBox;
|
||||||
|
//
|
||||||
import data.*;
|
//import data.*;
|
||||||
import javafx.collections.ListChangeListener;
|
//import javafx.collections.ListChangeListener;
|
||||||
import javafx.collections.ObservableList;
|
//import javafx.collections.ObservableList;
|
||||||
import javafx.concurrent.Task;
|
//import javafx.concurrent.Task;
|
||||||
import javafx.fxml.FXML;
|
//import javafx.fxml.FXML;
|
||||||
import javafx.scene.layout.AnchorPane;
|
//import javafx.scene.layout.AnchorPane;
|
||||||
|
//
|
||||||
@SuppressWarnings("Duplicates")
|
//@SuppressWarnings("Duplicates")
|
||||||
public class WordFormationTab {
|
//public class WordFormationTab {
|
||||||
public final static Logger logger = LogManager.getLogger(WordFormationTab.class);
|
// public final static Logger logger = LogManager.getLogger(WordFormationTab.class);
|
||||||
|
//
|
||||||
public AnchorPane wordAnalysisTabPane;
|
// public AnchorPane wordAnalysisTabPane;
|
||||||
|
//
|
||||||
@FXML
|
// @FXML
|
||||||
public Label selectedFiltersLabel;
|
// public Label selectedFiltersLabel;
|
||||||
@FXML
|
// @FXML
|
||||||
public Label solarFilters;
|
// public Label solarFilters;
|
||||||
|
//
|
||||||
@FXML
|
// @FXML
|
||||||
private CheckComboBox<String> taxonomyCCB;
|
// private CheckComboBox<String> taxonomyCCB;
|
||||||
private ArrayList<Taxonomy> taxonomy;
|
// private ArrayList<Taxonomy> taxonomy;
|
||||||
|
//
|
||||||
@FXML
|
// @FXML
|
||||||
private TextField minimalOccurrencesTF;
|
// private TextField minimalOccurrencesTF;
|
||||||
private Integer minimalOccurrences;
|
// private Integer minimalOccurrences;
|
||||||
|
//
|
||||||
@FXML
|
// @FXML
|
||||||
private TextField minimalTaxonomyTF;
|
// private TextField minimalTaxonomyTF;
|
||||||
private Integer minimalTaxonomy;
|
// private Integer minimalTaxonomy;
|
||||||
|
//
|
||||||
@FXML
|
// @FXML
|
||||||
private Button computeB;
|
// private Button computeB;
|
||||||
|
//
|
||||||
@FXML
|
// @FXML
|
||||||
public ProgressBar ngramProgressBar;
|
// public ProgressBar ngramProgressBar;
|
||||||
@FXML
|
// @FXML
|
||||||
public Label progressLabel;
|
// public Label progressLabel;
|
||||||
|
//
|
||||||
@FXML
|
// @FXML
|
||||||
private Hyperlink helpH;
|
// private Hyperlink helpH;
|
||||||
|
//
|
||||||
private Corpus corpus;
|
// private Corpus corpus;
|
||||||
private HashMap<String, HashSet<String>> solarFiltersMap;
|
// private HashMap<String, HashSet<String>> solarFiltersMap;
|
||||||
private HostServices hostService;
|
// private HostServices hostService;
|
||||||
|
//
|
||||||
// after header scan
|
// // after header scan
|
||||||
private ObservableList<String> taxonomyCCBValues;
|
// private ObservableList<String> taxonomyCCBValues;
|
||||||
private CorpusType currentCorpusType;
|
// private CorpusType currentCorpusType;
|
||||||
private boolean useDb;
|
// private boolean useDb;
|
||||||
|
//
|
||||||
|
//
|
||||||
public void init() {
|
// public void init() {
|
||||||
// taxonomy
|
// // taxonomy
|
||||||
if (Tax.getCorpusTypesWithTaxonomy().contains(corpus.getCorpusType())) {
|
// if (Tax.getCorpusTypesWithTaxonomy().contains(corpus.getCorpusType())) {
|
||||||
taxonomyCCB.getItems().removeAll();
|
// taxonomyCCB.getItems().removeAll();
|
||||||
taxonomyCCB.getItems().setAll(corpus.getObservableListTaxonomy());
|
// taxonomyCCB.getItems().setAll(corpus.getObservableListTaxonomy());
|
||||||
taxonomyCCB.getCheckModel().getCheckedItems().addListener((ListChangeListener<String>) c -> {
|
// taxonomyCCB.getCheckModel().getCheckedItems().addListener((ListChangeListener<String>) c -> {
|
||||||
taxonomy = new ArrayList<>();
|
// taxonomy = new ArrayList<>();
|
||||||
ObservableList<String> checkedItems = taxonomyCCB.getCheckModel().getCheckedItems();
|
// ObservableList<String> checkedItems = taxonomyCCB.getCheckModel().getCheckedItems();
|
||||||
ArrayList<Taxonomy> checkedItemsTaxonomy = Taxonomy.convertStringListToTaxonomyList(checkedItems, corpus);
|
// ArrayList<Taxonomy> checkedItemsTaxonomy = Taxonomy.convertStringListToTaxonomyList(checkedItems, corpus);
|
||||||
taxonomy.addAll(checkedItemsTaxonomy);
|
// taxonomy.addAll(checkedItemsTaxonomy);
|
||||||
logger.info(String.format("Selected taxonomy: %s", StringUtils.join(checkedItems, ",")));
|
// logger.info(String.format("Selected taxonomy: %s", StringUtils.join(checkedItems, ",")));
|
||||||
});
|
// });
|
||||||
taxonomyCCB.getCheckModel().clearChecks();
|
// taxonomyCCB.getCheckModel().clearChecks();
|
||||||
} else {
|
// } else {
|
||||||
taxonomyCCB.setDisable(true);
|
// taxonomyCCB.setDisable(true);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
// set default values
|
// // set default values
|
||||||
minimalOccurrencesTF.setText("1");
|
// minimalOccurrencesTF.setText("1");
|
||||||
minimalOccurrences = 1;
|
// minimalOccurrences = 1;
|
||||||
|
//
|
||||||
minimalTaxonomyTF.setText("1");
|
// minimalTaxonomyTF.setText("1");
|
||||||
minimalTaxonomy = 1;
|
// minimalTaxonomy = 1;
|
||||||
|
//
|
||||||
minimalOccurrencesTF.focusedProperty().addListener((observable, oldValue, newValue) -> {
|
// minimalOccurrencesTF.focusedProperty().addListener((observable, oldValue, newValue) -> {
|
||||||
if (!newValue) {
|
// if (!newValue) {
|
||||||
// focus lost
|
// // focus lost
|
||||||
String value = minimalOccurrencesTF.getText();
|
// String value = minimalOccurrencesTF.getText();
|
||||||
if (!ValidationUtil.isEmpty(value)) {
|
// if (!ValidationUtil.isEmpty(value)) {
|
||||||
if (!ValidationUtil.isNumber(value)) {
|
// if (!ValidationUtil.isNumber(value)) {
|
||||||
logAlert("minimalOccurrencesTF: " + I18N.get("message.WARNING_ONLY_NUMBERS_ALLOWED"));
|
// logAlert("minimalOccurrencesTF: " + I18N.get("message.WARNING_ONLY_NUMBERS_ALLOWED"));
|
||||||
GUIController.showAlert(Alert.AlertType.ERROR, I18N.get("message.WARNING_ONLY_NUMBERS_ALLOWED"));
|
// GUIController.showAlert(Alert.AlertType.ERROR, I18N.get("message.WARNING_ONLY_NUMBERS_ALLOWED"));
|
||||||
} else {
|
// } else {
|
||||||
minimalOccurrences = Integer.parseInt(value);
|
// minimalOccurrences = Integer.parseInt(value);
|
||||||
}
|
// }
|
||||||
} else {
|
// } else {
|
||||||
minimalOccurrencesTF.setText("1");
|
// minimalOccurrencesTF.setText("1");
|
||||||
minimalOccurrences = 1;
|
// minimalOccurrences = 1;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
|
//
|
||||||
minimalTaxonomyTF.focusedProperty().addListener((observable, oldValue, newValue) -> {
|
// minimalTaxonomyTF.focusedProperty().addListener((observable, oldValue, newValue) -> {
|
||||||
if (!newValue) {
|
// if (!newValue) {
|
||||||
// focus lost
|
// // focus lost
|
||||||
String value = minimalTaxonomyTF.getText();
|
// String value = minimalTaxonomyTF.getText();
|
||||||
if (!ValidationUtil.isEmpty(value)) {
|
// if (!ValidationUtil.isEmpty(value)) {
|
||||||
if (!ValidationUtil.isNumber(value)) {
|
// if (!ValidationUtil.isNumber(value)) {
|
||||||
logAlert("minimalTaxonomyTF: " + I18N.get("message.WARNING_ONLY_NUMBERS_ALLOWED"));
|
// logAlert("minimalTaxonomyTF: " + I18N.get("message.WARNING_ONLY_NUMBERS_ALLOWED"));
|
||||||
GUIController.showAlert(Alert.AlertType.ERROR, I18N.get("message.WARNING_ONLY_NUMBERS_ALLOWED"));
|
// GUIController.showAlert(Alert.AlertType.ERROR, I18N.get("message.WARNING_ONLY_NUMBERS_ALLOWED"));
|
||||||
} else {
|
// } else {
|
||||||
minimalTaxonomy = Integer.parseInt(value);
|
// minimalTaxonomy = Integer.parseInt(value);
|
||||||
}
|
// }
|
||||||
} else {
|
// } else {
|
||||||
minimalTaxonomyTF.setText("1");
|
// minimalTaxonomyTF.setText("1");
|
||||||
minimalTaxonomy = 1;
|
// minimalTaxonomy = 1;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
|
//
|
||||||
computeB.setOnAction(e -> {
|
// computeB.setOnAction(e -> {
|
||||||
compute();
|
// compute();
|
||||||
logger.info("compute button");
|
// logger.info("compute button");
|
||||||
});
|
// });
|
||||||
|
//
|
||||||
helpH.setOnAction(e -> openHelpWebsite());
|
// helpH.setOnAction(e -> openHelpWebsite());
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
private void compute() {
|
// private void compute() {
|
||||||
Filter filter = new Filter();
|
// Filter filter = new Filter();
|
||||||
filter.setNgramValue(1);
|
// filter.setNgramValue(1);
|
||||||
filter.setCalculateFor(CalculateFor.MORPHOSYNTACTIC_PROPERTY);
|
// filter.setCalculateFor(CalculateFor.MORPHOSYNTACTIC_PROPERTY);
|
||||||
filter.setTaxonomy(taxonomy);
|
// filter.setTaxonomy(taxonomy);
|
||||||
filter.setAl(AnalysisLevel.STRING_LEVEL);
|
// filter.setAl(AnalysisLevel.STRING_LEVEL);
|
||||||
filter.setSkipValue(0);
|
// filter.setSkipValue(0);
|
||||||
filter.setMsd(new ArrayList<>());
|
// filter.setMsd(new ArrayList<>());
|
||||||
filter.setIsCvv(false);
|
// filter.setIsCvv(false);
|
||||||
filter.setSolarFilters(solarFiltersMap);
|
// filter.setSolarFilters(solarFiltersMap);
|
||||||
filter.setMinimalOccurrences(minimalOccurrences);
|
// filter.setMinimalOccurrences(minimalOccurrences);
|
||||||
filter.setMinimalTaxonomy(minimalTaxonomy);
|
// filter.setMinimalTaxonomy(minimalTaxonomy);
|
||||||
|
//
|
||||||
String message = Validation.validateForStringLevel(filter);
|
// String message = Validation.validateForStringLevel(filter);
|
||||||
if (message == null) {
|
// if (message == null) {
|
||||||
// no errors
|
// // no errors
|
||||||
logger.info("Executing: ", filter.toString());
|
// logger.info("Executing: ", filter.toString());
|
||||||
StatisticsNew statistic = new StatisticsNew(corpus, filter, useDb);
|
// StatisticsNew statistic = new StatisticsNew(corpus, filter, useDb);
|
||||||
execute(statistic);
|
// execute(statistic);
|
||||||
} else {
|
// } else {
|
||||||
logAlert(message);
|
// logAlert(message);
|
||||||
showAlert(Alert.AlertType.ERROR, "Prosim izpolnite polja:", message);
|
// showAlert(Alert.AlertType.ERROR, "Prosim izpolnite polja:", message);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
private void openHelpWebsite(){
|
// private void openHelpWebsite(){
|
||||||
hostService.showDocument(Messages.HELP_URL);
|
// hostService.showDocument(Messages.HELP_URL);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
private void execute(StatisticsNew statistic) {
|
// private void execute(StatisticsNew statistic) {
|
||||||
logger.info("Started execution: ", statistic.getFilter());
|
// logger.info("Started execution: ", statistic.getFilter());
|
||||||
|
//
|
||||||
Collection<File> corpusFiles = statistic.getCorpus().getDetectedCorpusFiles();
|
// Collection<File> corpusFiles = statistic.getCorpus().getDetectedCorpusFiles();
|
||||||
|
//
|
||||||
final Task<Void> task = new Task<Void>() {
|
// final Task<Void> task = new Task<Void>() {
|
||||||
@SuppressWarnings("Duplicates")
|
// @SuppressWarnings("Duplicates")
|
||||||
@Override
|
// @Override
|
||||||
protected Void call() throws Exception {
|
// protected Void call() throws Exception {
|
||||||
int i = 0;
|
// int i = 0;
|
||||||
Date startTime = new Date();
|
// Date startTime = new Date();
|
||||||
Date previousTime = new Date();
|
// Date previousTime = new Date();
|
||||||
for (File f : corpusFiles) {
|
// for (File f : corpusFiles) {
|
||||||
readXML(f.toString(), statistic);
|
// readXML(f.toString(), statistic);
|
||||||
i++;
|
// i++;
|
||||||
this.updateProgress(i, corpusFiles.size());
|
// this.updateProgress(i, corpusFiles.size());
|
||||||
this.updateMessage(String.format(I18N.get("message.ONGOING_NOTIFICATION_ANALYZING_FILE_X_OF_Y"), i, corpusFiles.size(), f.getName()));
|
// this.updateMessage(String.format(I18N.get("message.ONGOING_NOTIFICATION_ANALYZING_FILE_X_OF_Y"), i, corpusFiles.size(), f.getName()));
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
return null;
|
// return null;
|
||||||
}
|
// }
|
||||||
};
|
// };
|
||||||
|
//
|
||||||
ngramProgressBar.progressProperty().bind(task.progressProperty());
|
// ngramProgressBar.progressProperty().bind(task.progressProperty());
|
||||||
progressLabel.textProperty().bind(task.messageProperty());
|
// progressLabel.textProperty().bind(task.messageProperty());
|
||||||
|
//
|
||||||
task.setOnSucceeded(e -> {
|
// task.setOnSucceeded(e -> {
|
||||||
try {
|
// try {
|
||||||
// first, we have to recalculate all occurrences to detailed statistics
|
// // first, we have to recalculate all occurrences to detailed statistics
|
||||||
boolean successullySaved = statistic.recalculateAndSaveResultToDisk();
|
// boolean successullySaved = statistic.recalculateAndSaveResultToDisk();
|
||||||
|
//
|
||||||
if (successullySaved) {
|
// if (successullySaved) {
|
||||||
showAlert(Alert.AlertType.INFORMATION, I18N.get("message.NOTIFICATION_ANALYSIS_COMPLETED"));
|
// showAlert(Alert.AlertType.INFORMATION, I18N.get("message.NOTIFICATION_ANALYSIS_COMPLETED"));
|
||||||
} else {
|
// } else {
|
||||||
showAlert(Alert.AlertType.INFORMATION, I18N.get("message.NOTIFICATION_ANALYSIS_COMPLETED_NO_RESULTS"));
|
// showAlert(Alert.AlertType.INFORMATION, I18N.get("message.NOTIFICATION_ANALYSIS_COMPLETED_NO_RESULTS"));
|
||||||
}
|
// }
|
||||||
} catch (UnsupportedEncodingException e1) {
|
// } catch (UnsupportedEncodingException e1) {
|
||||||
showAlert(Alert.AlertType.ERROR, I18N.get("message.ERROR_WHILE_SAVING_RESULTS_TO_CSV"));
|
// showAlert(Alert.AlertType.ERROR, I18N.get("message.ERROR_WHILE_SAVING_RESULTS_TO_CSV"));
|
||||||
logger.error("Error while saving", e1);
|
// logger.error("Error while saving", e1);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
ngramProgressBar.progressProperty().unbind();
|
// ngramProgressBar.progressProperty().unbind();
|
||||||
ngramProgressBar.setStyle(Settings.FX_ACCENT_OK);
|
// ngramProgressBar.setStyle(Settings.FX_ACCENT_OK);
|
||||||
progressLabel.textProperty().unbind();
|
// progressLabel.textProperty().unbind();
|
||||||
progressLabel.setText("");
|
// progressLabel.setText("");
|
||||||
});
|
// });
|
||||||
|
//
|
||||||
task.setOnFailed(e -> {
|
// task.setOnFailed(e -> {
|
||||||
showAlert(Alert.AlertType.ERROR, I18N.get("message.ERROR_WHILE_EXECUTING"));
|
// showAlert(Alert.AlertType.ERROR, I18N.get("message.ERROR_WHILE_EXECUTING"));
|
||||||
logger.error("Error while executing", e);
|
// logger.error("Error while executing", e);
|
||||||
ngramProgressBar.progressProperty().unbind();
|
// ngramProgressBar.progressProperty().unbind();
|
||||||
ngramProgressBar.setProgress(0.0);
|
// ngramProgressBar.setProgress(0.0);
|
||||||
ngramProgressBar.setStyle(Settings.FX_ACCENT_NOK);
|
// ngramProgressBar.setStyle(Settings.FX_ACCENT_NOK);
|
||||||
progressLabel.textProperty().unbind();
|
// progressLabel.textProperty().unbind();
|
||||||
progressLabel.setText("");
|
// progressLabel.setText("");
|
||||||
});
|
// });
|
||||||
|
//
|
||||||
final Thread thread = new Thread(task, "task");
|
// final Thread thread = new Thread(task, "task");
|
||||||
thread.setDaemon(true);
|
// thread.setDaemon(true);
|
||||||
thread.start();
|
// thread.start();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
private void logAlert(String alert) {
|
// private void logAlert(String alert) {
|
||||||
logger.info("alert: " + alert);
|
// logger.info("alert: " + alert);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
public void setCorpus(Corpus corpus) {
|
// public void setCorpus(Corpus corpus) {
|
||||||
this.corpus = corpus;
|
// this.corpus = corpus;
|
||||||
|
//
|
||||||
if (corpus.getCorpusType() != CorpusType.SOLAR) {
|
// if (corpus.getCorpusType() != CorpusType.SOLAR) {
|
||||||
setSelectedFiltersLabel(null);
|
// setSelectedFiltersLabel(null);
|
||||||
} else {
|
// } else {
|
||||||
setSelectedFiltersLabel("/");
|
// setSelectedFiltersLabel("/");
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public void setSelectedFiltersLabel(String content) {
|
// public void setSelectedFiltersLabel(String content) {
|
||||||
if (content != null) {
|
// if (content != null) {
|
||||||
solarFilters.setVisible(true);
|
// solarFilters.setVisible(true);
|
||||||
selectedFiltersLabel.setVisible(true);
|
// selectedFiltersLabel.setVisible(true);
|
||||||
selectedFiltersLabel.setText(content);
|
// selectedFiltersLabel.setText(content);
|
||||||
} else {
|
// } else {
|
||||||
solarFilters.setVisible(false);
|
// solarFilters.setVisible(false);
|
||||||
selectedFiltersLabel.setVisible(false);
|
// selectedFiltersLabel.setVisible(false);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public void setSolarFiltersMap(HashMap<String, HashSet<String>> solarFiltersMap) {
|
// public void setSolarFiltersMap(HashMap<String, HashSet<String>> solarFiltersMap) {
|
||||||
this.solarFiltersMap = solarFiltersMap;
|
// this.solarFiltersMap = solarFiltersMap;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public void setHostServices(HostServices hostServices){
|
// public void setHostServices(HostServices hostServices){
|
||||||
this.hostService = hostServices;
|
// this.hostService = hostServices;
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
Loading…
Reference in new issue