Project copied
This commit is contained in:
207
src/main/java/gui/WordLevelTab.java
Normal file
207
src/main/java/gui/WordLevelTab.java
Normal file
@@ -0,0 +1,207 @@
|
||||
package gui;
|
||||
|
||||
import static alg.XML_processing.*;
|
||||
import static gui.GUIController.*;
|
||||
import static gui.Messages.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
||||
import javafx.application.HostServices;
|
||||
import javafx.scene.control.*;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.controlsfx.control.CheckComboBox;
|
||||
|
||||
import data.*;
|
||||
import javafx.collections.ListChangeListener;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.concurrent.Task;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
|
||||
@SuppressWarnings("Duplicates")
|
||||
public class WordLevelTab {
|
||||
public final static Logger logger = LogManager.getLogger(WordLevelTab.class);
|
||||
|
||||
public AnchorPane wordLevelAnalysisTabPane;
|
||||
|
||||
@FXML
|
||||
public Label selectedFiltersLabel;
|
||||
@FXML
|
||||
public Label solarFilters;
|
||||
|
||||
@FXML
|
||||
private CheckComboBox<String> taxonomyCCB;
|
||||
private ArrayList<String> taxonomy;
|
||||
|
||||
@FXML
|
||||
private Button computeB;
|
||||
|
||||
@FXML
|
||||
public ProgressBar ngramProgressBar;
|
||||
@FXML
|
||||
public Label progressLabel;
|
||||
|
||||
@FXML
|
||||
private Hyperlink helpH;
|
||||
|
||||
private Corpus corpus;
|
||||
private HashMap<String, HashSet<String>> solarFiltersMap;
|
||||
private HostServices hostService;
|
||||
|
||||
// after header scan
|
||||
private ObservableList<String> taxonomyCCBValues;
|
||||
private CorpusType currentCorpusType;
|
||||
private boolean useDb;
|
||||
|
||||
|
||||
public void init() {
|
||||
// taxonomy
|
||||
if (Tax.getCorpusTypesWithTaxonomy().contains(corpus.getCorpusType())) {
|
||||
taxonomyCCB.getItems().removeAll();
|
||||
taxonomyCCB.getItems().setAll(corpus.getTaxonomy());
|
||||
taxonomyCCB.getCheckModel().getCheckedItems().addListener((ListChangeListener<String>) c -> {
|
||||
taxonomy = new ArrayList<>();
|
||||
ObservableList<String> checkedItems = taxonomyCCB.getCheckModel().getCheckedItems();
|
||||
taxonomy.addAll(checkedItems);
|
||||
logger.info(String.format("Selected taxonomy: %s", StringUtils.join(checkedItems, ",")));
|
||||
});
|
||||
taxonomyCCB.getCheckModel().clearChecks();
|
||||
} else {
|
||||
taxonomyCCB.setDisable(true);
|
||||
}
|
||||
|
||||
computeB.setOnAction(e -> {
|
||||
compute();
|
||||
logger.info("compute button");
|
||||
});
|
||||
|
||||
helpH.setOnAction(e -> openHelpWebsite());
|
||||
}
|
||||
|
||||
private void openHelpWebsite(){
|
||||
hostService.showDocument(Messages.HELP_URL);
|
||||
}
|
||||
private void compute() {
|
||||
Filter filter = new Filter();
|
||||
filter.setNgramValue(1);
|
||||
filter.setCalculateFor(CalculateFor.WORD);
|
||||
filter.setTaxonomy(Tax.getTaxonomyCodes(taxonomy, corpus.getCorpusType()));
|
||||
filter.setAl(AnalysisLevel.WORD_LEVEL);
|
||||
filter.setSkipValue(0);
|
||||
filter.setMsd(new ArrayList<>());
|
||||
filter.setIsCvv(false);
|
||||
filter.setSolarFilters(solarFiltersMap);
|
||||
|
||||
String message = Validation.validateForStringLevel(filter);
|
||||
if (message == null) {
|
||||
// no errors
|
||||
logger.info("Executing: ", filter.toString());
|
||||
StatisticsNew statistic = new StatisticsNew(corpus, filter, useDb);
|
||||
execute(statistic);
|
||||
} else {
|
||||
logAlert(message);
|
||||
showAlert(Alert.AlertType.ERROR, "Prosim izpolnite polja:", message);
|
||||
}
|
||||
}
|
||||
|
||||
private void execute(StatisticsNew statistic) {
|
||||
logger.info("Started execution: ", statistic.getFilter());
|
||||
|
||||
Collection<File> corpusFiles = statistic.getCorpus().getDetectedCorpusFiles();
|
||||
|
||||
final Task<Void> task = new Task<Void>() {
|
||||
@SuppressWarnings("Duplicates")
|
||||
@Override
|
||||
protected Void call() throws Exception {
|
||||
long i = 0;
|
||||
for (File f : corpusFiles) {
|
||||
readXML(f.toString(), statistic);
|
||||
i++;
|
||||
this.updateProgress(i, corpusFiles.size());
|
||||
this.updateMessage(String.format(ONGOING_NOTIFICATION_ANALYZING_FILE_X_OF_Y, i, corpusFiles.size(), f.getName()));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
ngramProgressBar.progressProperty().bind(task.progressProperty());
|
||||
progressLabel.textProperty().bind(task.messageProperty());
|
||||
|
||||
task.setOnSucceeded(e -> {
|
||||
try {
|
||||
// first, we have to recalculate all occurrences to detailed statistics
|
||||
boolean successullySaved = statistic.saveResultNestedToDisk();
|
||||
|
||||
if (successullySaved) {
|
||||
showAlert(Alert.AlertType.INFORMATION, Messages.NOTIFICATION_ANALYSIS_COMPLETED);
|
||||
} else {
|
||||
showAlert(Alert.AlertType.INFORMATION, Messages.NOTIFICATION_ANALYSIS_COMPLETED_NO_RESULTS);
|
||||
}
|
||||
} catch (UnsupportedEncodingException e1) {
|
||||
showAlert(Alert.AlertType.ERROR, ERROR_WHILE_SAVING_RESULTS_TO_CSV);
|
||||
logger.error("Error while saving", e1);
|
||||
}
|
||||
|
||||
ngramProgressBar.progressProperty().unbind();
|
||||
ngramProgressBar.setStyle(Settings.FX_ACCENT_OK);
|
||||
progressLabel.textProperty().unbind();
|
||||
progressLabel.setText("");
|
||||
});
|
||||
|
||||
task.setOnFailed(e -> {
|
||||
showAlert(Alert.AlertType.ERROR, ERROR_WHILE_EXECUTING);
|
||||
logger.error("Error while executing", e);
|
||||
ngramProgressBar.progressProperty().unbind();
|
||||
ngramProgressBar.setProgress(0.0);
|
||||
ngramProgressBar.setStyle(Settings.FX_ACCENT_NOK);
|
||||
progressLabel.textProperty().unbind();
|
||||
progressLabel.setText("");
|
||||
});
|
||||
|
||||
final Thread thread = new Thread(task, "task");
|
||||
thread.setDaemon(true);
|
||||
thread.start();
|
||||
}
|
||||
|
||||
private void logAlert(String alert) {
|
||||
logger.info("alert: " + alert);
|
||||
}
|
||||
|
||||
|
||||
public void setCorpus(Corpus corpus) {
|
||||
this.corpus = corpus;
|
||||
|
||||
if (corpus.getCorpusType() != CorpusType.SOLAR) {
|
||||
setSelectedFiltersLabel(null);
|
||||
} else {
|
||||
setSelectedFiltersLabel("/");
|
||||
}
|
||||
}
|
||||
|
||||
public void setSelectedFiltersLabel(String content) {
|
||||
if (content != null) {
|
||||
solarFilters.setVisible(true);
|
||||
selectedFiltersLabel.setVisible(true);
|
||||
selectedFiltersLabel.setText(content);
|
||||
} else {
|
||||
solarFilters.setVisible(false);
|
||||
selectedFiltersLabel.setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void setSolarFiltersMap(HashMap<String, HashSet<String>> solarFiltersMap) {
|
||||
this.solarFiltersMap = solarFiltersMap;
|
||||
}
|
||||
|
||||
public void setHostServices(HostServices hostServices){
|
||||
this.hostService = hostServices;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user