2018-06-19 07:15:37 +00:00
|
|
|
package gui;
|
|
|
|
|
|
|
|
import static alg.XML_processing.*;
|
|
|
|
import static gui.GUIController.*;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
2019-01-07 11:55:11 +00:00
|
|
|
import alg.XML_processing;
|
2018-06-19 07:15:37 +00:00
|
|
|
import javafx.application.HostServices;
|
2019-01-07 11:55:11 +00:00
|
|
|
import javafx.beans.InvalidationListener;
|
|
|
|
import javafx.beans.Observable;
|
2019-01-16 09:51:05 +00:00
|
|
|
import javafx.beans.binding.StringBinding;
|
2019-01-07 11:55:11 +00:00
|
|
|
import javafx.beans.property.ReadOnlyDoubleWrapper;
|
2018-12-13 07:35:36 +00:00
|
|
|
import javafx.beans.value.ChangeListener;
|
|
|
|
import javafx.beans.value.ObservableValue;
|
2019-01-16 09:51:05 +00:00
|
|
|
import javafx.scene.image.ImageView;
|
2018-11-20 08:52:16 +00:00
|
|
|
import javafx.scene.layout.AnchorPane;
|
2018-06-19 07:15:37 +00:00
|
|
|
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.FXCollections;
|
|
|
|
import javafx.collections.ListChangeListener;
|
|
|
|
import javafx.collections.ObservableList;
|
|
|
|
import javafx.concurrent.Task;
|
|
|
|
import javafx.fxml.FXML;
|
|
|
|
import javafx.scene.control.*;
|
|
|
|
import javafx.scene.layout.Pane;
|
|
|
|
|
|
|
|
@SuppressWarnings("Duplicates")
|
|
|
|
public class StringAnalysisTabNew2 {
|
|
|
|
public final static Logger logger = LogManager.getLogger(StringAnalysisTabNew2.class);
|
|
|
|
|
2018-11-20 08:52:16 +00:00
|
|
|
@FXML
|
|
|
|
public AnchorPane stringAnalysisTabPaneNew2;
|
|
|
|
|
2018-06-19 07:15:37 +00:00
|
|
|
@FXML
|
2019-01-11 12:00:42 +00:00
|
|
|
public TextArea selectedFiltersTextArea;
|
2018-12-13 07:35:36 +00:00
|
|
|
|
2018-06-19 07:15:37 +00:00
|
|
|
@FXML
|
|
|
|
public Label solarFilters;
|
|
|
|
|
2018-12-13 07:35:36 +00:00
|
|
|
@FXML
|
|
|
|
public Label calculateForL;
|
|
|
|
|
|
|
|
@FXML
|
|
|
|
public Label alsoVisualizeL;
|
|
|
|
|
|
|
|
@FXML
|
|
|
|
public Label displayTaxonomyL;
|
|
|
|
|
|
|
|
@FXML
|
|
|
|
public Label dataLimitL;
|
|
|
|
|
|
|
|
@FXML
|
|
|
|
public Label msdL;
|
|
|
|
|
|
|
|
@FXML
|
|
|
|
public Label taxonomyL;
|
|
|
|
|
|
|
|
@FXML
|
|
|
|
public Label minimalOccurrencesL;
|
|
|
|
|
|
|
|
@FXML
|
|
|
|
public Label minimalTaxonomyL;
|
|
|
|
|
|
|
|
@FXML
|
|
|
|
public Label skipValueL;
|
|
|
|
|
|
|
|
@FXML
|
|
|
|
public Label slowSpeedWarning1L;
|
|
|
|
|
|
|
|
@FXML
|
|
|
|
public Label slowSpeedWarning2L;
|
|
|
|
|
|
|
|
@FXML
|
|
|
|
public Label ngramValueL;
|
|
|
|
|
|
|
|
@FXML
|
|
|
|
public Label notePunctuationsL;
|
|
|
|
|
|
|
|
@FXML
|
|
|
|
public Label collocabilityL;
|
|
|
|
|
2018-12-13 13:12:05 +00:00
|
|
|
@FXML
|
2019-01-16 09:51:05 +00:00
|
|
|
public ImageView calculateForI;
|
2018-12-13 13:12:05 +00:00
|
|
|
|
|
|
|
@FXML
|
2019-01-16 09:51:05 +00:00
|
|
|
public ImageView alsoVisualizeI;
|
2018-12-13 13:12:05 +00:00
|
|
|
|
|
|
|
@FXML
|
2019-01-16 09:51:05 +00:00
|
|
|
public ImageView displayTaxonomyI;
|
2018-12-13 13:12:05 +00:00
|
|
|
|
|
|
|
@FXML
|
2019-01-16 09:51:05 +00:00
|
|
|
public ImageView msdI;
|
2018-12-13 13:12:05 +00:00
|
|
|
|
|
|
|
@FXML
|
2019-01-16 09:51:05 +00:00
|
|
|
public ImageView taxonomyI;
|
2018-12-13 13:12:05 +00:00
|
|
|
|
|
|
|
@FXML
|
2019-01-16 09:51:05 +00:00
|
|
|
public ImageView minimalOccurrencesI;
|
2018-12-13 13:12:05 +00:00
|
|
|
|
|
|
|
@FXML
|
2019-01-16 09:51:05 +00:00
|
|
|
public ImageView minimalTaxonomyI;
|
2018-12-13 13:12:05 +00:00
|
|
|
|
|
|
|
@FXML
|
2019-01-16 09:51:05 +00:00
|
|
|
public ImageView skipValueI;
|
2018-12-13 13:12:05 +00:00
|
|
|
|
|
|
|
@FXML
|
2019-01-16 09:51:05 +00:00
|
|
|
public ImageView ngramValueI;
|
2018-12-13 13:12:05 +00:00
|
|
|
|
|
|
|
@FXML
|
2019-01-16 09:51:05 +00:00
|
|
|
public ImageView notePunctuationsI;
|
2018-12-13 13:12:05 +00:00
|
|
|
|
|
|
|
@FXML
|
2019-01-16 09:51:05 +00:00
|
|
|
public ImageView collocabilityI;
|
2018-12-13 07:35:36 +00:00
|
|
|
|
2018-06-19 07:15:37 +00:00
|
|
|
@FXML
|
|
|
|
private TextField msdTF;
|
|
|
|
private ArrayList<Pattern> msd;
|
|
|
|
private ArrayList<String> msdStrings;
|
|
|
|
|
2018-08-22 07:11:14 +00:00
|
|
|
@FXML
|
|
|
|
private CheckComboBox<String> alsoVisualizeCCB;
|
|
|
|
private ArrayList<String> alsoVisualize;
|
|
|
|
|
2018-06-19 07:15:37 +00:00
|
|
|
@FXML
|
|
|
|
private CheckComboBox<String> taxonomyCCB;
|
2018-11-26 12:41:35 +00:00
|
|
|
private ArrayList<Taxonomy> taxonomy;
|
2018-12-13 13:12:05 +00:00
|
|
|
//
|
|
|
|
// @FXML
|
|
|
|
// private CheckBox calculatecvvCB;
|
|
|
|
// private boolean calculateCvv;
|
2018-06-19 07:15:37 +00:00
|
|
|
|
2018-12-13 13:12:05 +00:00
|
|
|
// @FXML
|
|
|
|
// private TextField stringLengthTF;
|
|
|
|
// private Integer stringLength;
|
2018-06-19 07:15:37 +00:00
|
|
|
|
|
|
|
@FXML
|
|
|
|
private ComboBox<String> calculateForCB;
|
|
|
|
private CalculateFor calculateFor;
|
|
|
|
|
2018-10-24 08:36:07 +00:00
|
|
|
@FXML
|
|
|
|
private CheckComboBox<String> collocabilityCCB;
|
|
|
|
private ArrayList<Collocability> collocability;
|
|
|
|
|
2018-06-19 07:15:37 +00:00
|
|
|
@FXML
|
|
|
|
private ComboBox<String> ngramValueCB;
|
|
|
|
private Integer ngramValue;
|
|
|
|
|
|
|
|
@FXML
|
|
|
|
private ComboBox<String> skipValueCB;
|
|
|
|
private Integer skipValue;
|
|
|
|
|
2018-07-23 07:14:46 +00:00
|
|
|
@FXML
|
|
|
|
private CheckBox notePunctuationsChB;
|
|
|
|
private boolean notePunctuations;
|
|
|
|
|
2018-08-22 07:11:14 +00:00
|
|
|
@FXML
|
|
|
|
private CheckBox displayTaxonomyChB;
|
|
|
|
private boolean displayTaxonomy;
|
|
|
|
|
2018-07-31 06:58:17 +00:00
|
|
|
@FXML
|
|
|
|
private TextField minimalOccurrencesTF;
|
|
|
|
private Integer minimalOccurrences;
|
|
|
|
|
|
|
|
@FXML
|
|
|
|
private TextField minimalTaxonomyTF;
|
|
|
|
private Integer minimalTaxonomy;
|
|
|
|
|
2018-06-19 07:15:37 +00:00
|
|
|
@FXML
|
|
|
|
private Pane paneWords;
|
|
|
|
|
|
|
|
@FXML
|
|
|
|
private Button computeNgramsB;
|
|
|
|
|
2018-12-13 07:35:36 +00:00
|
|
|
@FXML
|
|
|
|
private Button changeLanguageB;
|
|
|
|
|
2018-06-29 10:53:29 +00:00
|
|
|
@FXML
|
|
|
|
private Button cancel;
|
|
|
|
|
2018-06-19 07:15:37 +00:00
|
|
|
@FXML
|
|
|
|
public ProgressBar ngramProgressBar;
|
|
|
|
@FXML
|
|
|
|
public Label progressLabel;
|
|
|
|
|
|
|
|
@FXML
|
|
|
|
private Hyperlink helpH;
|
|
|
|
|
|
|
|
private enum MODE {
|
|
|
|
LETTER,
|
|
|
|
WORD
|
|
|
|
}
|
|
|
|
|
|
|
|
private MODE currentMode;
|
|
|
|
|
|
|
|
private Corpus corpus;
|
|
|
|
private HashMap<String, HashSet<String>> solarFiltersMap;
|
|
|
|
private Filter filter;
|
|
|
|
private boolean useDb;
|
|
|
|
private HostServices hostService;
|
2018-12-13 07:35:36 +00:00
|
|
|
private ListChangeListener<String> taxonomyListener;
|
|
|
|
private ListChangeListener<String> alsoVisualizeListener;
|
|
|
|
private ListChangeListener<String> collocabilityListener;
|
|
|
|
private ChangeListener<String> calculateForListener;
|
|
|
|
|
|
|
|
// private static final ObservableList<String> N_GRAM_COMPUTE_FOR_WORDS = FXCollections.observableArrayList("lema", "različnica", "oblikoskladenjska oznaka");
|
|
|
|
// private static final ObservableList<String> N_GRAM_COMPUTE_FOR_LETTERS = FXCollections.observableArrayList("lema", "različnica");
|
|
|
|
// private static final ObservableList<String> N_GRAM_COMPUTE_FOR_WORDS_ORTH = FXCollections.observableArrayList("različnica");
|
2018-08-10 09:08:01 +00:00
|
|
|
// private static final ObservableList<String> N_GRAM_COMPUTE_FOR_WORDS_GOS = FXCollections.observableArrayList("lema", "različnica", "oblikoskladenjska oznaka", "normalizirana različnica");
|
2018-12-13 07:35:36 +00:00
|
|
|
// private static final ObservableList<String> alsoVisualizeItemsLemma = FXCollections.observableArrayList("besedna vrsta", "oblikoskladenjska oznaka");
|
|
|
|
// private static final ObservableList<String> alsoVisualizeItemsWord = FXCollections.observableArrayList("lema", "besedna vrsta", "oblikoskladenjska oznaka");
|
|
|
|
// private static final ObservableList<String> alsoVisualizeItemsWordGos = FXCollections.observableArrayList("lema", "besedna vrsta", "oblikoskladenjska oznaka", "normalizirana različnica");
|
|
|
|
// private static final ObservableList<String> alsoVisualizeItemsNormalizedWord = FXCollections.observableArrayList("lema", "besedna vrsta", "oblikoskladenjska oznaka");
|
|
|
|
// private static final ObservableList<String> alsoVisualizeItemsMsd = FXCollections.observableArrayList("besedna vrsta");
|
2018-11-08 10:37:16 +00:00
|
|
|
private static final ObservableList<String> COLLOCABILITY_ITEMS = FXCollections.observableArrayList("Dice", "t-score", "MI", "MI3", "logDice", "simple LL");
|
2018-12-13 07:35:36 +00:00
|
|
|
// private static final ObservableList<String> alsoVisualizeItemsEmpty = FXCollections.observableArrayList();
|
|
|
|
|
|
|
|
// private static final ObservableList<String> N_GRAM_COMPUTE_FOR_LETTERS = FXCollections.observableArrayList("lema", "različnica");
|
|
|
|
private static final String [] N_GRAM_COMPUTE_FOR_WORDS_ARRAY = {"calculateFor.WORD", "calculateFor.LEMMA", "calculateFor.MORPHOSYNTACTIC_SPECS"};
|
|
|
|
private static final ArrayList<String> N_GRAM_COMPUTE_FOR_WORDS = new ArrayList<>(Arrays.asList(N_GRAM_COMPUTE_FOR_WORDS_ARRAY));
|
|
|
|
// private static final ObservableList<String> N_GRAM_COMPUTE_FOR_WORDS_ORTH = FXCollections.observableArrayList("različnica");
|
|
|
|
private static final String [] N_GRAM_COMPUTE_FOR_WORDS_ORTH_ARRAY = {"calculateFor.WORD"};
|
|
|
|
private static final ArrayList<String> N_GRAM_COMPUTE_FOR_WORDS_ORTH = new ArrayList<>(Arrays.asList(N_GRAM_COMPUTE_FOR_WORDS_ORTH_ARRAY));
|
|
|
|
// private static final ObservableList<String> N_GRAM_COMPUTE_FOR_WORDS_GOS = FXCollections.observableArrayList("lema", "različnica", "normalizirana različnica");
|
|
|
|
private static final String [] N_GRAM_COMPUTE_FOR_WORDS_GOS_ARRAY = {"calculateFor.WORD", "calculateFor.LEMMA", "calculateFor.MORPHOSYNTACTIC_SPECS", "calculateFor.NORMALIZED_WORD"};
|
|
|
|
private static final ArrayList<String> N_GRAM_COMPUTE_FOR_WORDS_GOS = new ArrayList<>(Arrays.asList(N_GRAM_COMPUTE_FOR_WORDS_GOS_ARRAY));
|
|
|
|
// private static final ObservableList<String> alsoVisualizeItemsLemma = FXCollections.observableArrayList("besedna vrsta", "oblikoskladenjska oznaka");
|
|
|
|
private static final String [] ALSO_VISUALIZE_ITEMS_LEMMA_ARRAY = {"calculateFor.WORD_TYPE", "calculateFor.MORPHOSYNTACTIC_SPECS"};
|
|
|
|
private static final ArrayList<String> ALSO_VISUALIZE_ITEMS_LEMMA = new ArrayList<>(Arrays.asList(ALSO_VISUALIZE_ITEMS_LEMMA_ARRAY));
|
|
|
|
// private static final ObservableList<String> alsoVisualizeItemsWord = FXCollections.observableArrayList("lema", "besedna vrsta", "oblikoskladenjska oznaka");
|
|
|
|
private static final String [] ALSO_VISUALIZE_ITEMS_WORDS_ARRAY = {"calculateFor.LEMMA", "calculateFor.WORD_TYPE", "calculateFor.MORPHOSYNTACTIC_SPECS"};
|
|
|
|
private static final ArrayList<String> ALSO_VISUALIZE_ITEMS_WORDS = new ArrayList<>(Arrays.asList(ALSO_VISUALIZE_ITEMS_WORDS_ARRAY));
|
|
|
|
// private static final ObservableList<String> alsoVisualizeItemsWordGos = FXCollections.observableArrayList("lema", "besedna vrsta", "oblikoskladenjska oznaka", "normalizirana različnica");
|
|
|
|
private static final String [] ALSO_VISUALIZE_ITEMS_WORDS_GOS_ARRAY = {"calculateFor.LEMMA", "calculateFor.WORD_TYPE", "calculateFor.MORPHOSYNTACTIC_SPECS", "calculateFor.NORMALIZED_WORD"};
|
|
|
|
private static final ArrayList<String> ALSO_VISUALIZE_ITEMS_WORDS_GOS = new ArrayList<>(Arrays.asList(ALSO_VISUALIZE_ITEMS_WORDS_GOS_ARRAY));
|
|
|
|
// private static final ObservableList<String> alsoVisualizeItemsNormalizedWord = FXCollections.observableArrayList("lema", "besedna vrsta", "oblikoskladenjska oznaka");
|
|
|
|
private static final String [] ALSO_VISUALIZE_ITEMS_NORMALIZED_WORDS_ARRAY = {"calculateFor.LEMMA", "calculateFor.WORD_TYPE", "calculateFor.MORPHOSYNTACTIC_SPECS"};
|
|
|
|
private static final ArrayList<String> ALSO_VISUALIZE_ITEMS_NORMALIZED_WORDS = new ArrayList<>(Arrays.asList(ALSO_VISUALIZE_ITEMS_NORMALIZED_WORDS_ARRAY));
|
|
|
|
// private static final ObservableList<String> alsoVisualizeItemsMsd = FXCollections.observableArrayList("besedna vrsta");
|
|
|
|
private static final String [] ALSO_VISUALIZE_ITEMS_MSD_ARRAY = {"calculateFor.WORD_TYPE"};
|
|
|
|
private static final ArrayList<String> ALSO_VISUALIZE_ITEMS_MSD = new ArrayList<>(Arrays.asList(ALSO_VISUALIZE_ITEMS_MSD_ARRAY));
|
|
|
|
// private static final ObservableList<String> alsoVisualizeItemsEmpty = FXCollections.observableArrayList();
|
|
|
|
private static final String [] ALSO_VISUALIZE_ITEMS_EMPTY_ARRAY = {};
|
|
|
|
private static final ArrayList<String> ALSO_VISUALIZE_ITEMS_EMPTY = new ArrayList<>(Arrays.asList(ALSO_VISUALIZE_ITEMS_EMPTY_ARRAY));
|
2018-06-19 07:15:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
// TODO: pass observables for taxonomy based on header scan
|
|
|
|
// after header scan
|
|
|
|
private ObservableList<String> taxonomyCCBValues;
|
|
|
|
private CorpusType currentCorpusType;
|
|
|
|
|
|
|
|
public void init() {
|
2018-11-20 08:52:16 +00:00
|
|
|
// add CSS style
|
|
|
|
stringAnalysisTabPaneNew2.getStylesheets().add("style.css");
|
|
|
|
stringAnalysisTabPaneNew2.getStyleClass().add("root");
|
|
|
|
|
2018-12-13 07:35:36 +00:00
|
|
|
manageTranslations();
|
|
|
|
|
2018-06-19 07:15:37 +00:00
|
|
|
currentMode = MODE.WORD;
|
|
|
|
toggleMode(currentMode);
|
|
|
|
|
|
|
|
// ngram value CB
|
|
|
|
ngramValueCB.valueProperty().addListener((observable, oldValue, newValue) -> {
|
|
|
|
if (newValue.equals("nivo črk")) {
|
|
|
|
ngramValue = 0;
|
|
|
|
toggleMode(MODE.LETTER);
|
|
|
|
} else {
|
|
|
|
ngramValue = Integer.valueOf(newValue);
|
|
|
|
toggleMode(MODE.WORD);
|
|
|
|
}
|
|
|
|
|
|
|
|
// skip only on ngrams of more than one word
|
|
|
|
if (ngramValue > 1) {
|
|
|
|
skipValueCB.setDisable(false);
|
|
|
|
} else {
|
|
|
|
skipValueCB.getSelectionModel().select(0);
|
|
|
|
skipValue = 0;
|
|
|
|
skipValueCB.setDisable(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.info("ngramValueCB:", ngramValue);
|
|
|
|
});
|
|
|
|
|
|
|
|
// set first n-gram value to 2 at index 0
|
|
|
|
ngramValueCB.getSelectionModel().select(0); // selected index
|
|
|
|
ngramValue = 2; // actual value at that index
|
|
|
|
|
2018-07-31 06:58:17 +00:00
|
|
|
// set default values
|
|
|
|
minimalOccurrencesTF.setText("1");
|
|
|
|
minimalOccurrences = 1;
|
|
|
|
|
|
|
|
minimalTaxonomyTF.setText("1");
|
|
|
|
minimalTaxonomy = 1;
|
|
|
|
|
2018-11-20 08:52:16 +00:00
|
|
|
minimalTaxonomyTF.setDisable(true);
|
|
|
|
|
2018-08-28 09:41:19 +00:00
|
|
|
notePunctuations = false;
|
2018-07-23 07:14:46 +00:00
|
|
|
// set
|
|
|
|
notePunctuationsChB.selectedProperty().addListener((observable, oldValue, newValue) -> {
|
|
|
|
notePunctuations = newValue;
|
|
|
|
logger.info("note punctuations: ", notePunctuations);
|
|
|
|
});
|
2019-01-07 11:55:11 +00:00
|
|
|
notePunctuationsChB.setSelected(false);
|
2018-12-13 07:35:36 +00:00
|
|
|
notePunctuationsChB.setTooltip(new Tooltip(I18N.get("message.TOOLTIP_readNotePunctuationsChB")));
|
2018-07-23 07:14:46 +00:00
|
|
|
|
2018-08-22 07:11:14 +00:00
|
|
|
displayTaxonomy = false;
|
2018-12-01 09:50:11 +00:00
|
|
|
displayTaxonomyChB.setSelected(false);
|
2018-08-22 07:11:14 +00:00
|
|
|
// set
|
2018-11-20 08:52:16 +00:00
|
|
|
|
2019-01-07 11:55:11 +00:00
|
|
|
if (Tax.getCorpusTypesWithTaxonomy().contains(corpus.getCorpusType()) && corpus.getObservableListTaxonomy().size() > 0) {
|
2018-12-01 09:50:11 +00:00
|
|
|
displayTaxonomyChB.setDisable(false);
|
|
|
|
displayTaxonomyChB.selectedProperty().addListener((observable, oldValue, newValue) -> {
|
|
|
|
displayTaxonomy = newValue;
|
|
|
|
if (displayTaxonomy) {
|
|
|
|
minimalTaxonomyTF.setDisable(false);
|
|
|
|
} else {
|
|
|
|
minimalTaxonomyTF.setDisable(true);
|
|
|
|
|
|
|
|
minimalTaxonomyTF.setText("1");
|
|
|
|
minimalTaxonomy = 1;
|
|
|
|
}
|
|
|
|
logger.info("display taxonomy: ", displayTaxonomy);
|
|
|
|
});
|
2018-12-13 07:35:36 +00:00
|
|
|
displayTaxonomyChB.setTooltip(new Tooltip(I18N.get("message.TOOLTIP_readDisplayTaxonomyChB")));
|
2018-12-01 09:50:11 +00:00
|
|
|
} else {
|
|
|
|
displayTaxonomyChB.setDisable(true);
|
|
|
|
}
|
2018-08-22 07:11:14 +00:00
|
|
|
|
2018-12-13 07:35:36 +00:00
|
|
|
if (calculateForListener != null){
|
|
|
|
calculateForCB.valueProperty().removeListener(calculateForListener);
|
|
|
|
}
|
|
|
|
|
2018-06-19 07:15:37 +00:00
|
|
|
// calculateForCB
|
2018-12-13 07:35:36 +00:00
|
|
|
calculateForListener = new ChangeListener<String>() {
|
|
|
|
boolean ignoreCode = false;
|
|
|
|
@Override
|
|
|
|
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
|
|
|
|
if (ignoreCode) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
boolean languageChanged = newValue == null;
|
|
|
|
ArrayList<Integer> checkedIndices = new ArrayList<>();
|
|
|
|
checkedIndices.addAll(alsoVisualizeCCB.getCheckModel().getCheckedIndices());
|
|
|
|
if (languageChanged) {
|
|
|
|
ignoreCode = true;
|
|
|
|
if (corpus.getCorpusType() == CorpusType.GOS) {
|
|
|
|
newValue = I18N.getTranslatedValue(oldValue, N_GRAM_COMPUTE_FOR_WORDS_GOS);
|
|
|
|
calculateForCB.getSelectionModel().select(newValue);
|
|
|
|
} else {
|
|
|
|
newValue = I18N.getTranslatedValue(oldValue, N_GRAM_COMPUTE_FOR_WORDS);
|
|
|
|
calculateForCB.getSelectionModel().select(newValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
// override if orth mode, allow only word
|
|
|
|
if (corpus.isGosOrthMode()) {
|
|
|
|
newValue = I18N.getTranslatedValue(oldValue, N_GRAM_COMPUTE_FOR_WORDS_ORTH);
|
|
|
|
calculateForCB.getSelectionModel().select(newValue);
|
|
|
|
}
|
|
|
|
ignoreCode = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
calculateFor = CalculateFor.factory(newValue);
|
|
|
|
|
|
|
|
if (alsoVisualizeListener != null) {
|
|
|
|
alsoVisualizeCCB.getCheckModel().getCheckedItems().removeListener(alsoVisualizeListener);
|
|
|
|
}
|
|
|
|
|
|
|
|
alsoVisualizeCCB.getCheckModel().clearChecks();
|
|
|
|
alsoVisualizeCCB.getItems().removeAll();
|
|
|
|
if (newValue.equals(CalculateFor.LEMMA.toString())) {
|
|
|
|
alsoVisualizeCCB.getItems().setAll(I18N.translatedObservableList(ALSO_VISUALIZE_ITEMS_LEMMA));
|
|
|
|
} else if (newValue.equals(CalculateFor.WORD.toString())) {
|
|
|
|
if (corpus.getCorpusType() == CorpusType.GOS)
|
|
|
|
alsoVisualizeCCB.getItems().setAll(I18N.translatedObservableList(ALSO_VISUALIZE_ITEMS_WORDS_GOS));
|
|
|
|
else
|
|
|
|
alsoVisualizeCCB.getItems().setAll(I18N.translatedObservableList(ALSO_VISUALIZE_ITEMS_WORDS));
|
|
|
|
} else if (newValue.equals(CalculateFor.NORMALIZED_WORD.toString())) {
|
|
|
|
alsoVisualizeCCB.getItems().setAll(I18N.translatedObservableList(ALSO_VISUALIZE_ITEMS_NORMALIZED_WORDS));
|
|
|
|
} else if (newValue.equals(CalculateFor.MORPHOSYNTACTIC_SPECS.toString())) {
|
|
|
|
alsoVisualizeCCB.getItems().setAll(I18N.translatedObservableList(ALSO_VISUALIZE_ITEMS_MSD));
|
|
|
|
} else {
|
|
|
|
alsoVisualizeCCB.getItems().setAll(I18N.translatedObservableList(ALSO_VISUALIZE_ITEMS_EMPTY));
|
|
|
|
}
|
|
|
|
// alsoVisualizeCCB.getCheckModel().getCheckedItems().addListener((ListChangeListener<String>) c -> {
|
|
|
|
// alsoVisualize = new ArrayList<>();
|
|
|
|
// ObservableList<String> checkedItems = alsoVisualizeCCB.getCheckModel().getCheckedItems();
|
|
|
|
// alsoVisualize.addAll(checkedItems);
|
|
|
|
// logger.info(String.format("Selected also visualize items: %s", StringUtils.join(checkedItems, ",")));
|
|
|
|
// });
|
|
|
|
// alsoVisualizeCCB.getCheckModel().clearChecks();
|
|
|
|
|
|
|
|
alsoVisualizeListener = new ListChangeListener<String>() {
|
|
|
|
@Override
|
|
|
|
public void onChanged(Change<? extends String> c) {
|
|
|
|
alsoVisualize = new ArrayList<>();
|
|
|
|
ObservableList<String> checkedItems = alsoVisualizeCCB.getCheckModel().getCheckedItems();
|
|
|
|
alsoVisualize.addAll(checkedItems);
|
|
|
|
logger.info(String.format("Selected also visualize items: %s", StringUtils.join(checkedItems, ",")));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
// alsoVisualizeCCB.getCheckModel().clearChecks();
|
|
|
|
// alsoVisualizeCCB.getItems().removeAll();
|
|
|
|
// alsoVisualizeCCB.getItems().setAll(I18N.translatedObservableList(ALSO_VISUALIZE_ITEMS_WORDS));
|
|
|
|
|
|
|
|
alsoVisualizeCCB.getCheckModel().getCheckedItems().addListener(alsoVisualizeListener);
|
|
|
|
|
|
|
|
if (languageChanged) {
|
|
|
|
for (int i : checkedIndices) {
|
|
|
|
alsoVisualizeCCB.getCheckModel().check(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.info("calculateForCB:", calculateFor.toString());
|
2018-08-22 07:11:14 +00:00
|
|
|
}
|
2018-12-13 07:35:36 +00:00
|
|
|
};
|
2018-08-22 07:11:14 +00:00
|
|
|
|
2018-12-13 07:35:36 +00:00
|
|
|
calculateForCB.valueProperty().addListener(calculateForListener);
|
2018-06-19 07:15:37 +00:00
|
|
|
|
|
|
|
calculateForCB.getSelectionModel().select(0);
|
|
|
|
|
2018-10-24 08:36:07 +00:00
|
|
|
// collocabilityCCB
|
2018-12-13 07:35:36 +00:00
|
|
|
if (collocabilityListener != null){
|
|
|
|
collocabilityCCB.getCheckModel().getCheckedItems().removeListener(collocabilityListener);
|
|
|
|
}
|
2018-10-24 08:36:07 +00:00
|
|
|
|
2018-12-13 07:35:36 +00:00
|
|
|
collocabilityListener = new ListChangeListener<String>() {
|
|
|
|
@Override
|
|
|
|
public void onChanged(Change<? extends String> c) {
|
|
|
|
collocability = new ArrayList<>();
|
|
|
|
ObservableList<Collocability> checkedItems = FXCollections.observableArrayList();
|
|
|
|
for (String el : collocabilityCCB.getCheckModel().getCheckedItems()) {
|
|
|
|
checkedItems.add(Collocability.factory(el));
|
|
|
|
}
|
|
|
|
collocability.addAll(checkedItems);
|
|
|
|
logger.info(String.format("Selected collocabilities: %s", StringUtils.join(collocabilityCCB.getCheckModel().getCheckedItems(), ",")));
|
2018-10-24 08:36:07 +00:00
|
|
|
}
|
2018-12-13 07:35:36 +00:00
|
|
|
};
|
|
|
|
|
2018-10-24 08:36:07 +00:00
|
|
|
collocabilityCCB.getCheckModel().clearChecks();
|
2018-12-13 07:35:36 +00:00
|
|
|
collocabilityCCB.getItems().removeAll();
|
|
|
|
collocabilityCCB.getItems().setAll(FXCollections.observableArrayList(COLLOCABILITY_ITEMS));
|
|
|
|
|
|
|
|
collocabilityCCB.getCheckModel().getCheckedItems().addListener(collocabilityListener);
|
|
|
|
// collocabilityCCB.getCheckModel().getCheckedItems().addListener((ListChangeListener<String>) c -> {
|
|
|
|
// collocability = new ArrayList<>();
|
|
|
|
// ObservableList<Collocability> checkedItems = FXCollections.observableArrayList();
|
|
|
|
// for (String el : collocabilityCCB.getCheckModel().getCheckedItems()) {
|
|
|
|
// checkedItems.add(Collocability.factory(el));
|
|
|
|
// }
|
|
|
|
// collocability.addAll(checkedItems);
|
|
|
|
// logger.info(String.format("Selected collocabilities: %s", StringUtils.join(collocabilityCCB.getCheckModel().getCheckedItems(), ",")));
|
|
|
|
// });
|
|
|
|
|
2018-10-24 08:36:07 +00:00
|
|
|
|
2018-06-19 07:15:37 +00:00
|
|
|
// msd
|
|
|
|
msdTF.focusedProperty().addListener((observable, oldValue, newValue) -> {
|
|
|
|
if (!newValue) {
|
|
|
|
// focus lost
|
|
|
|
String value = msdTF.getText();
|
|
|
|
logger.info("msdTf: ", value);
|
|
|
|
|
|
|
|
if (!ValidationUtil.isEmpty(value)) {
|
|
|
|
ArrayList<String> msdTmp = new ArrayList<>(Arrays.asList(value.split(" ")));
|
|
|
|
|
|
|
|
int nOfRequiredMsdTokens = ngramValue == 0 ? 1 : ngramValue;
|
|
|
|
if (msdTmp.size() != nOfRequiredMsdTokens) {
|
2018-12-13 07:35:36 +00:00
|
|
|
String msg = String.format(I18N.get("message.WARNING_MISMATCHED_NGRAM_AND_TOKENS_VALUES"), nOfRequiredMsdTokens, msdTmp.size());
|
2018-06-19 07:15:37 +00:00
|
|
|
logAlert(msg);
|
|
|
|
showAlert(Alert.AlertType.ERROR, msg);
|
|
|
|
}
|
|
|
|
msd = new ArrayList<>();
|
|
|
|
msdStrings = new ArrayList<>();
|
|
|
|
for (String msdToken : msdTmp) {
|
|
|
|
msd.add(Pattern.compile(msdToken));
|
|
|
|
msdStrings.add(msdToken);
|
|
|
|
}
|
|
|
|
logger.info(String.format("msd accepted (%d)", msd.size()));
|
|
|
|
|
|
|
|
} else if (!ValidationUtil.isEmpty(newValue)) {
|
|
|
|
msd = new ArrayList<>();
|
|
|
|
msdStrings = new ArrayList<>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
msdTF.setText("");
|
|
|
|
msd = new ArrayList<>();
|
|
|
|
|
2018-12-13 07:35:36 +00:00
|
|
|
if (alsoVisualizeListener != null){
|
|
|
|
alsoVisualizeCCB.getCheckModel().getCheckedItems().removeListener(alsoVisualizeListener);
|
|
|
|
}
|
|
|
|
|
|
|
|
alsoVisualizeListener = new ListChangeListener<String>() {
|
|
|
|
@Override
|
|
|
|
public void onChanged(Change<? extends String> c) {
|
|
|
|
alsoVisualize = new ArrayList<>();
|
|
|
|
ObservableList<String> checkedItems = alsoVisualizeCCB.getCheckModel().getCheckedItems();
|
|
|
|
alsoVisualize.addAll(checkedItems);
|
|
|
|
logger.info(String.format("Selected also visualize items: %s", StringUtils.join(checkedItems, ",")));
|
|
|
|
}
|
|
|
|
};
|
2018-08-22 07:11:14 +00:00
|
|
|
alsoVisualizeCCB.getCheckModel().clearChecks();
|
2018-12-13 07:35:36 +00:00
|
|
|
alsoVisualizeCCB.getItems().removeAll();
|
2018-12-13 13:12:05 +00:00
|
|
|
if (corpus.getCorpusType() != CorpusType.GOS){
|
|
|
|
alsoVisualizeCCB.getItems().setAll(I18N.translatedObservableList(ALSO_VISUALIZE_ITEMS_WORDS));
|
|
|
|
} else {
|
|
|
|
alsoVisualizeCCB.getItems().setAll(I18N.translatedObservableList(ALSO_VISUALIZE_ITEMS_WORDS_GOS));
|
|
|
|
}
|
2018-12-13 07:35:36 +00:00
|
|
|
|
|
|
|
alsoVisualizeCCB.getCheckModel().getCheckedItems().addListener(alsoVisualizeListener);
|
2018-08-22 07:11:14 +00:00
|
|
|
|
2018-06-19 07:15:37 +00:00
|
|
|
// taxonomy
|
2019-01-07 11:55:11 +00:00
|
|
|
if (Tax.getCorpusTypesWithTaxonomy().contains(corpus.getCorpusType()) && corpus.getObservableListTaxonomy().size() > 0) {
|
|
|
|
taxonomyCCB.setDisable(false);
|
|
|
|
} else {
|
|
|
|
taxonomyCCB.setDisable(true);
|
|
|
|
}
|
2018-12-13 07:35:36 +00:00
|
|
|
|
2019-01-07 11:55:11 +00:00
|
|
|
if (taxonomyListener != null){
|
|
|
|
taxonomyCCB.getCheckModel().getCheckedItems().removeListener(taxonomyListener);
|
|
|
|
}
|
2018-11-26 12:41:35 +00:00
|
|
|
|
2019-01-07 11:55:11 +00:00
|
|
|
taxonomyListener = new ListChangeListener<String>() {
|
|
|
|
boolean changing = true;
|
2018-11-26 12:41:35 +00:00
|
|
|
|
2019-01-07 11:55:11 +00:00
|
|
|
@Override
|
|
|
|
public void onChanged(ListChangeListener.Change<? extends String> c){
|
|
|
|
if(changing) {
|
|
|
|
ObservableList<String> checkedItems = taxonomyCCB.getCheckModel().getCheckedItems();
|
|
|
|
// ArrayList<Taxonomy> checkedItemsTaxonomy = Taxonomy.convertStringListToTaxonomyList(checkedItems);
|
|
|
|
//
|
|
|
|
// Taxonomy.modifyingTaxonomy(taxonomy, checkedItemsTaxonomy, corpus);
|
|
|
|
ArrayList<Taxonomy> checkedItemsTaxonomy = Taxonomy.modifyingTaxonomy(taxonomy, checkedItems, corpus);
|
2018-11-26 12:41:35 +00:00
|
|
|
|
2019-01-07 11:55:11 +00:00
|
|
|
taxonomy = new ArrayList<>();
|
|
|
|
taxonomy.addAll(checkedItemsTaxonomy);
|
2018-11-26 12:41:35 +00:00
|
|
|
|
2019-01-07 11:55:11 +00:00
|
|
|
taxonomyCCB.getItems().removeAll();
|
|
|
|
taxonomyCCB.getItems().setAll(corpus.getObservableListTaxonomy());
|
2018-11-26 12:41:35 +00:00
|
|
|
|
2019-01-07 11:55:11 +00:00
|
|
|
// taxonomyCCB.getCheckModel().clearChecks();
|
|
|
|
changing = false;
|
|
|
|
taxonomyCCB.getCheckModel().clearChecks();
|
|
|
|
for (Taxonomy t : checkedItemsTaxonomy) {
|
|
|
|
taxonomyCCB.getCheckModel().check(t.toLongNameString());
|
2018-11-26 12:41:35 +00:00
|
|
|
}
|
2019-01-07 11:55:11 +00:00
|
|
|
changing = true;
|
|
|
|
logger.info(String.format("Selected taxonomy: %s", StringUtils.join(checkedItems, ",")));
|
2018-11-26 12:41:35 +00:00
|
|
|
}
|
2019-01-07 11:55:11 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
taxonomyCCB.getCheckModel().clearChecks();
|
2018-12-13 07:35:36 +00:00
|
|
|
|
2019-01-07 11:55:11 +00:00
|
|
|
taxonomyCCB.getItems().removeAll();
|
|
|
|
taxonomyCCB.getItems().setAll(corpus.getObservableListTaxonomy());
|
|
|
|
|
|
|
|
taxonomyCCB.getCheckModel().getCheckedItems().addListener(taxonomyListener);
|
2018-06-19 07:15:37 +00:00
|
|
|
|
|
|
|
// skip
|
|
|
|
skipValueCB.valueProperty().addListener((observable, oldValue, newValue) -> {
|
|
|
|
skipValue = Integer.valueOf(newValue);
|
|
|
|
logger.info("Skip " + skipValue);
|
|
|
|
});
|
|
|
|
|
|
|
|
skipValueCB.getSelectionModel().select(0);
|
|
|
|
skipValue = 0;
|
|
|
|
|
|
|
|
// cvv
|
2018-12-13 13:12:05 +00:00
|
|
|
// calculatecvvCB.selectedProperty().addListener((observable, oldValue, newValue) -> {
|
|
|
|
// calculateCvv = newValue;
|
|
|
|
// logger.info("calculate cvv: " + calculateCvv);
|
|
|
|
// });
|
2018-06-19 07:15:37 +00:00
|
|
|
|
2018-12-13 13:12:05 +00:00
|
|
|
// calculatecvvCB.setSelected(false);
|
2018-06-19 07:15:37 +00:00
|
|
|
|
|
|
|
// string length
|
2018-12-13 13:12:05 +00:00
|
|
|
// stringLengthTF.focusedProperty().addListener((observable, oldValue, newValue) -> {
|
|
|
|
// if (!newValue) {
|
|
|
|
// // focus lost
|
|
|
|
// String value = stringLengthTF.getText();
|
|
|
|
// if (!ValidationUtil.isEmpty(value)) {
|
|
|
|
// if (!ValidationUtil.isNumber(value)) {
|
|
|
|
// logAlert("stringlengthTf: " + I18N.get("message.WARNING_ONLY_NUMBERS_ALLOWED"));
|
|
|
|
// GUIController.showAlert(Alert.AlertType.ERROR, I18N.get("message.WARNING_ONLY_NUMBERS_ALLOWED"));
|
|
|
|
// }
|
|
|
|
// stringLength = Integer.parseInt(value);
|
|
|
|
// } else {
|
|
|
|
// GUIController.showAlert(Alert.AlertType.ERROR, I18N.get("message.WARNING_MISSING_STRING_LENGTH"));
|
|
|
|
// stringLengthTF.setText("1");
|
|
|
|
// logAlert(I18N.get("message.WARNING_MISSING_STRING_LENGTH"));
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// });
|
2018-06-19 07:15:37 +00:00
|
|
|
|
2018-07-31 06:58:17 +00:00
|
|
|
minimalOccurrencesTF.focusedProperty().addListener((observable, oldValue, newValue) -> {
|
|
|
|
if (!newValue) {
|
|
|
|
// focus lost
|
|
|
|
String value = minimalOccurrencesTF.getText();
|
|
|
|
if (!ValidationUtil.isEmpty(value)) {
|
|
|
|
if (!ValidationUtil.isNumber(value)) {
|
2018-12-13 07:35:36 +00:00
|
|
|
logAlert("minimalOccurrencesTF: " + I18N.get("message.WARNING_ONLY_NUMBERS_ALLOWED"));
|
|
|
|
GUIController.showAlert(Alert.AlertType.ERROR, I18N.get("message.WARNING_ONLY_NUMBERS_ALLOWED"));
|
2018-07-31 06:58:17 +00:00
|
|
|
} else {
|
|
|
|
minimalOccurrences = Integer.parseInt(value);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
minimalOccurrencesTF.setText("1");
|
|
|
|
minimalOccurrences = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
minimalTaxonomyTF.focusedProperty().addListener((observable, oldValue, newValue) -> {
|
|
|
|
if (!newValue) {
|
|
|
|
// focus lost
|
|
|
|
String value = minimalTaxonomyTF.getText();
|
|
|
|
if (!ValidationUtil.isEmpty(value)) {
|
|
|
|
if (!ValidationUtil.isNumber(value)) {
|
2018-12-13 07:35:36 +00:00
|
|
|
logAlert("minimalTaxonomyTF: " + I18N.get("message.WARNING_ONLY_NUMBERS_ALLOWED"));
|
|
|
|
GUIController.showAlert(Alert.AlertType.ERROR, I18N.get("message.WARNING_ONLY_NUMBERS_ALLOWED"));
|
2018-07-31 06:58:17 +00:00
|
|
|
} else {
|
|
|
|
minimalTaxonomy = Integer.parseInt(value);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
minimalTaxonomyTF.setText("1");
|
|
|
|
minimalTaxonomy = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-12-13 07:35:36 +00:00
|
|
|
changeLanguageB.setOnAction(e -> {
|
|
|
|
if (I18N.getLocale() == new Locale.Builder().setLanguage("sl").setRegion("SI").build()){
|
|
|
|
I18N.setLocale(Locale.ENGLISH);
|
|
|
|
} else {
|
|
|
|
I18N.setLocale(new Locale.Builder().setLanguage("sl").setRegion("SI").build());
|
|
|
|
}
|
|
|
|
Messages.reload();
|
|
|
|
Messages.updateChooseCorpusL();
|
|
|
|
logger.info("change language");
|
|
|
|
});
|
|
|
|
|
2018-06-19 07:15:37 +00:00
|
|
|
computeNgramsB.setOnAction(e -> {
|
|
|
|
compute();
|
|
|
|
logger.info("compute button");
|
|
|
|
});
|
|
|
|
|
|
|
|
helpH.setOnAction(e -> openHelpWebsite());
|
2018-06-29 10:53:29 +00:00
|
|
|
|
|
|
|
cancel.setVisible(false);
|
2018-06-19 07:15:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* case a: values for combo boxes can change after a corpus change
|
|
|
|
* <ul>
|
|
|
|
* <li>different corpus type - reset all fields so no old values remain</li>
|
|
|
|
* <li>same corpus type, different subset - keep</li>
|
|
|
|
* </ul>
|
|
|
|
* <p>
|
|
|
|
* case b: values for combo boxes can change after a header scan
|
|
|
|
* <ul>
|
|
|
|
* <li>at first, fields are populated by corpus type defaults</li>
|
|
|
|
* <li>after, with gathered data</li>
|
|
|
|
* </ul>
|
|
|
|
* <p></p>
|
|
|
|
* ngrams: 1
|
|
|
|
* calculateFor: word
|
|
|
|
* msd:
|
|
|
|
* taxonomy:
|
|
|
|
* skip: 0
|
|
|
|
* iscvv: false
|
|
|
|
* string length: 1
|
|
|
|
*/
|
2018-08-31 05:57:58 +00:00
|
|
|
// public void populateFields() {
|
|
|
|
// // corpus changed if: current one is null (this is first run of the app)
|
|
|
|
// // or if currentCorpus != gui's corpus
|
|
|
|
// boolean corpusChanged = currentCorpusType == null
|
|
|
|
// || currentCorpusType != corpus.getCorpusType();
|
|
|
|
//
|
|
|
|
// // keep ngram value if set
|
|
|
|
// if (ngramValue == null) {
|
|
|
|
// ngramValueCB.getSelectionModel().select("1");
|
|
|
|
// ngramValue = 1;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// // TODO: check for GOS, GIGAFIDA, SOLAR...
|
|
|
|
// // refresh and:
|
|
|
|
// // TODO if current value != null && is in new calculateFor ? keep : otherwise reset
|
|
|
|
// if (calculateFor == null) {
|
|
|
|
// calculateForCB.getSelectionModel().select(calculateForCB.getItems().get(0));
|
|
|
|
// calculateFor = CalculateFor.factory(calculateForCB.getItems().get(0));
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if (!filter.hasMsd()) {
|
|
|
|
// // if current corpus doesn't have msd data, disable this field
|
|
|
|
// msd = new ArrayList<>();
|
|
|
|
// msdTF.setText("");
|
|
|
|
// msdTF.setDisable(true);
|
|
|
|
// logger.info("no msd data");
|
|
|
|
// } else {
|
|
|
|
// if (ValidationUtil.isEmpty(msd)
|
|
|
|
// || (!ValidationUtil.isEmpty(msd) && corpusChanged)) {
|
|
|
|
// // msd has not been set previously
|
|
|
|
// // or msd has been set but the corpus changed -> reset
|
|
|
|
// msd = new ArrayList<>();
|
|
|
|
// msdTF.setText("");
|
|
|
|
// msdTF.setDisable(false);
|
|
|
|
// logger.info("msd reset");
|
|
|
|
// } else if (!ValidationUtil.isEmpty(msd) && !corpusChanged) {
|
|
|
|
// // if msd has been set, but corpus type remained the same, we can keep any set msd value
|
|
|
|
// msdTF.setText(StringUtils.join(msdStrings, " "));
|
|
|
|
// msdTF.setDisable(false);
|
|
|
|
// logger.info("msd kept");
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// // TODO: taxonomy: refresh and keep if in new taxonomy, otherwise empty (no selection)
|
|
|
|
//
|
|
|
|
// // keep skip value
|
|
|
|
// if (skipValue == null) {
|
|
|
|
// skipValueCB.getSelectionModel().select("0");
|
|
|
|
// skipValue = 0;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// // keep calculateCvv
|
|
|
|
// calculatecvvCB.setSelected(calculateCvv);
|
|
|
|
//
|
|
|
|
// // keep string length if set
|
|
|
|
// if (stringLength != null) {
|
|
|
|
// stringLengthTF.setText(String.valueOf(stringLength));
|
|
|
|
// } else {
|
|
|
|
// stringLengthTF.setText("1");
|
|
|
|
// stringLength = 1;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// // TODO: trigger on rescan
|
|
|
|
// if ((currentCorpusType != null && currentCorpusType != corpus.getCorpusType())) {
|
|
|
|
// // user changed corpus (by type) or by selection & triggered a rescan of headers
|
|
|
|
// // see if we read taxonomy from headers, otherwise use default values for given corpus
|
2019-01-07 11:55:11 +00:00
|
|
|
// ObservableList<String> tax = corpus.getObservableListTaxonomy();
|
2018-08-31 05:57:58 +00:00
|
|
|
// taxonomyCCBValues = tax != null ? tax : Taxonomy.getDefaultForComboBox(corpus.getCorpusType());
|
|
|
|
//
|
|
|
|
// currentCorpusType = corpus.getCorpusType();
|
|
|
|
// // setTaxonomyIsDirty(false);
|
|
|
|
// } else {
|
|
|
|
//
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// // see if we read taxonomy from headers, otherwise use default values for given corpus
|
2019-01-07 11:55:11 +00:00
|
|
|
// ObservableList<String> tax = corpus.getObservableListTaxonomy();
|
2018-08-31 05:57:58 +00:00
|
|
|
// taxonomyCCBValues = tax != null ? tax : Taxonomy.getDefaultForComboBox(corpus.getCorpusType());
|
|
|
|
// taxonomyCCB.getItems().addAll(taxonomyCCBValues);
|
|
|
|
//
|
|
|
|
// }
|
2019-01-16 09:51:05 +00:00
|
|
|
private void addTooltipToImage(ImageView image, StringBinding stringBinding){
|
|
|
|
Tooltip tooltip = new Tooltip();
|
|
|
|
tooltip.textProperty().bind(stringBinding);
|
|
|
|
Tooltip.install(image, tooltip);
|
|
|
|
}
|
2018-06-19 07:15:37 +00:00
|
|
|
|
2018-12-13 07:35:36 +00:00
|
|
|
private void manageTranslations(){
|
|
|
|
helpH.textProperty().bind(I18N.createStringBinding("hyperlink.help"));
|
|
|
|
changeLanguageB.textProperty().bind(I18N.createStringBinding("button.language"));
|
|
|
|
computeNgramsB.textProperty().bind(I18N.createStringBinding("button.computeNgrams"));
|
|
|
|
cancel.textProperty().bind(I18N.createStringBinding("button.cancel"));
|
|
|
|
|
|
|
|
calculateForL.textProperty().bind(I18N.createStringBinding("label.calculateFor"));
|
|
|
|
alsoVisualizeL.textProperty().bind(I18N.createStringBinding("label.alsoVisualize"));
|
|
|
|
displayTaxonomyL.textProperty().bind(I18N.createStringBinding("label.displayTaxonomy"));
|
|
|
|
// writeMsdAtTheEndL.textProperty().bind(I18N.createStringBinding("label.writeMsdAtTheEnd"));
|
|
|
|
skipValueL.textProperty().bind(I18N.createStringBinding("label.skipValue"));
|
|
|
|
slowSpeedWarning1L.textProperty().bind(I18N.createStringBinding("label.slowSpeedWarning"));
|
|
|
|
slowSpeedWarning2L.textProperty().bind(I18N.createStringBinding("label.slowSpeedWarning"));
|
|
|
|
ngramValueL.textProperty().bind(I18N.createStringBinding("label.ngramValue"));
|
|
|
|
notePunctuationsL.textProperty().bind(I18N.createStringBinding("label.notePunctuations"));
|
|
|
|
collocabilityL.textProperty().bind(I18N.createStringBinding("label.collocability"));
|
|
|
|
|
|
|
|
dataLimitL.textProperty().bind(I18N.createStringBinding("label.dataLimit"));
|
|
|
|
msdL.textProperty().bind(I18N.createStringBinding("label.msd"));
|
|
|
|
taxonomyL.textProperty().bind(I18N.createStringBinding("label.taxonomy"));
|
|
|
|
minimalOccurrencesL.textProperty().bind(I18N.createStringBinding("label.minimalOccurrences"));
|
|
|
|
minimalTaxonomyL.textProperty().bind(I18N.createStringBinding("label.minimalTaxonomy"));
|
|
|
|
solarFilters.textProperty().bind(I18N.createStringBinding("label.solarFilters"));
|
|
|
|
|
2019-01-16 09:51:05 +00:00
|
|
|
addTooltipToImage(calculateForI, I18N.createStringBinding("label.wordSet.calculateForH"));
|
|
|
|
addTooltipToImage(alsoVisualizeI, I18N.createStringBinding("label.wordSet.alsoVisualizeH"));
|
|
|
|
addTooltipToImage(displayTaxonomyI, I18N.createStringBinding("label.wordSet.displayTaxonomyH"));
|
|
|
|
addTooltipToImage(skipValueI, I18N.createStringBinding("label.wordSet.skipValueH"));
|
|
|
|
addTooltipToImage(ngramValueI, I18N.createStringBinding("label.wordSet.ngramValueH"));
|
|
|
|
addTooltipToImage(notePunctuationsI, I18N.createStringBinding("label.wordSet.notePunctuationsH"));
|
|
|
|
addTooltipToImage(collocabilityI, I18N.createStringBinding("label.wordSet.collocabilityH"));
|
|
|
|
|
|
|
|
addTooltipToImage(msdI, I18N.createStringBinding("label.wordSet.msdH"));
|
|
|
|
addTooltipToImage(taxonomyI, I18N.createStringBinding("label.wordSet.taxonomyH"));
|
|
|
|
addTooltipToImage(minimalOccurrencesI, I18N.createStringBinding("label.wordSet.minimalOccurrencesH"));
|
|
|
|
addTooltipToImage(minimalTaxonomyI, I18N.createStringBinding("label.wordSet.minimalTaxonomyH"));
|
2018-12-13 07:35:36 +00:00
|
|
|
}
|
|
|
|
|
2018-06-19 07:15:37 +00:00
|
|
|
/**
|
|
|
|
* Toggles visibility for panes which hold fields for skipgram value (not applicable when calculating for letters) etc.,
|
|
|
|
* sets combobox values to what is applicable ...
|
|
|
|
*
|
|
|
|
* @param mode
|
|
|
|
*/
|
|
|
|
public void toggleMode(MODE mode) {
|
|
|
|
if (mode == null) {
|
|
|
|
mode = currentMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.info("mode: ", mode.toString());
|
|
|
|
|
|
|
|
if (mode == MODE.WORD) {
|
|
|
|
paneWords.setVisible(true);
|
2018-12-13 13:12:05 +00:00
|
|
|
// paneLetters.setVisible(false);
|
2018-08-10 09:08:01 +00:00
|
|
|
// if (corpus.getCorpusType() == CorpusType.GOS)
|
|
|
|
// calculateForCB.getItems().setAll(N_GRAM_COMPUTE_FOR_WORDS_GOS);
|
|
|
|
// else
|
2018-12-13 07:35:36 +00:00
|
|
|
if (corpus.getCorpusType() == CorpusType.GOS) {
|
|
|
|
calculateForCB.itemsProperty().unbind();
|
|
|
|
calculateForCB.itemsProperty().bind(I18N.createObjectBinding(N_GRAM_COMPUTE_FOR_WORDS_GOS));
|
2018-06-19 07:15:37 +00:00
|
|
|
} else {
|
2018-12-13 07:35:36 +00:00
|
|
|
calculateForCB.itemsProperty().unbind();
|
|
|
|
calculateForCB.itemsProperty().bind(I18N.createObjectBinding(N_GRAM_COMPUTE_FOR_WORDS));
|
2018-06-19 07:15:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// override if orth mode, allow only word
|
|
|
|
if (corpus.isGosOrthMode()) {
|
2018-12-13 07:35:36 +00:00
|
|
|
calculateForCB.itemsProperty().unbind();
|
|
|
|
calculateForCB.itemsProperty().bind(I18N.createObjectBinding(N_GRAM_COMPUTE_FOR_WORDS_ORTH));
|
2018-06-19 07:15:37 +00:00
|
|
|
msdTF.setDisable(true);
|
|
|
|
} else {
|
|
|
|
msdTF.setDisable(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void compute() {
|
|
|
|
Filter filter = new Filter();
|
|
|
|
filter.setNgramValue(ngramValue);
|
|
|
|
filter.setCalculateFor(calculateFor);
|
2018-11-26 12:41:35 +00:00
|
|
|
filter.setTaxonomy(taxonomy);
|
2018-08-22 07:11:14 +00:00
|
|
|
filter.setDisplayTaxonomy(displayTaxonomy);
|
2018-06-19 07:15:37 +00:00
|
|
|
filter.setAl(AnalysisLevel.STRING_LEVEL);
|
|
|
|
filter.setSkipValue(skipValue);
|
2018-12-13 13:12:05 +00:00
|
|
|
// filter.setIsCvv(calculateCvv);
|
2018-06-19 07:15:37 +00:00
|
|
|
filter.setSolarFilters(solarFiltersMap);
|
2018-07-23 07:14:46 +00:00
|
|
|
filter.setNotePunctuations(notePunctuations);
|
2018-08-22 07:11:14 +00:00
|
|
|
filter.setMultipleKeys(alsoVisualize);
|
2018-09-03 11:31:41 +00:00
|
|
|
|
|
|
|
// setMsd must be behind alsoVisualize
|
|
|
|
filter.setMsd(msd);
|
2018-07-31 06:58:17 +00:00
|
|
|
filter.setMinimalOccurrences(minimalOccurrences);
|
|
|
|
filter.setMinimalTaxonomy(minimalTaxonomy);
|
2018-10-24 08:36:07 +00:00
|
|
|
filter.setCollocability(collocability);
|
2018-06-19 07:15:37 +00:00
|
|
|
|
2018-12-13 13:12:05 +00:00
|
|
|
// if (ngramValue != null && ngramValue == 0) {
|
|
|
|
// filter.setStringLength(stringLength);
|
|
|
|
// }
|
2018-06-19 07:15:37 +00:00
|
|
|
|
|
|
|
String message = Validation.validateForStringLevel(filter);
|
|
|
|
if (message == null) {
|
|
|
|
// no errors
|
|
|
|
logger.info("Executing: ", filter.toString());
|
|
|
|
StatisticsNew statistic = new StatisticsNew(corpus, filter, useDb);
|
2018-10-24 08:36:07 +00:00
|
|
|
// ADD THINGS HERE!!!
|
2018-06-19 07:15:37 +00:00
|
|
|
execute(statistic);
|
|
|
|
} else {
|
|
|
|
logAlert(message);
|
|
|
|
showAlert(Alert.AlertType.ERROR, "Prosim izpolnite polja:", message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void logAlert(String alert) {
|
|
|
|
logger.info("alert: " + alert);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void openHelpWebsite(){
|
|
|
|
hostService.showDocument(Messages.HELP_URL);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Corpus getCorpus() {
|
|
|
|
return corpus;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2019-01-11 12:00:42 +00:00
|
|
|
selectedFiltersTextArea.setVisible(true);
|
|
|
|
selectedFiltersTextArea.setText(content);
|
2018-06-19 07:15:37 +00:00
|
|
|
} else {
|
|
|
|
solarFilters.setVisible(false);
|
2019-01-11 12:00:42 +00:00
|
|
|
selectedFiltersTextArea.setVisible(false);
|
2018-06-19 07:15:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-24 08:36:07 +00:00
|
|
|
// public void calculate_collocabilities(StatisticsNew statistics, StatisticsNew oneWordStatistics) {
|
|
|
|
// statistics.updateCalculateCollocabilities(oneWordStatistics);
|
|
|
|
//
|
|
|
|
// }
|
|
|
|
|
|
|
|
private final Task<Void> prepareTaskForCollocability(StatisticsNew statistic, StatisticsNew statisticsOneGrams) {
|
|
|
|
Collection<File> corpusFiles = statisticsOneGrams.getCorpus().getDetectedCorpusFiles();
|
|
|
|
|
|
|
|
final Task<Void> task = new Task<Void>() {
|
|
|
|
@SuppressWarnings("Duplicates")
|
|
|
|
@Override
|
|
|
|
protected Void call() throws Exception {
|
2019-01-08 10:38:44 +00:00
|
|
|
final boolean multipleFiles = CorpusType.multipleFilesCorpuses().contains(statistic.getCorpus().getCorpusType());
|
|
|
|
if(multipleFiles){
|
2019-01-07 11:55:11 +00:00
|
|
|
cancel.setVisible(true);
|
|
|
|
}
|
|
|
|
int i = corpusFiles.size();
|
|
|
|
Date startTime = new Date();
|
|
|
|
Date previousTime = new Date();
|
|
|
|
int remainingSeconds = -1;
|
|
|
|
int corpusSize;
|
|
|
|
if (statistic.getFilter().getCollocability().size() > 0) {
|
|
|
|
corpusSize = corpusFiles.size() * 2;
|
|
|
|
} else {
|
|
|
|
corpusSize = corpusFiles.size();
|
|
|
|
}
|
2018-10-24 08:36:07 +00:00
|
|
|
for (File f : corpusFiles) {
|
2019-01-07 11:55:11 +00:00
|
|
|
final int iFinal = i;
|
|
|
|
XML_processing xml_processing = new XML_processing();
|
2018-11-05 09:30:41 +00:00
|
|
|
i++;
|
2019-01-08 10:38:44 +00:00
|
|
|
if(xml_processing.progressBarListener != null) {
|
|
|
|
xml_processing.progressProperty().removeListener(xml_processing.progressBarListener);
|
|
|
|
}
|
|
|
|
if (multipleFiles) {
|
2019-01-07 11:55:11 +00:00
|
|
|
if ((new Date()).getTime() - previousTime.getTime() > 500 || remainingSeconds == -1){
|
|
|
|
remainingSeconds = (int) (((new Date()).getTime() - startTime.getTime()) * (1.0/i) * (corpusSize - i) / 1000);
|
|
|
|
previousTime = new Date();
|
|
|
|
}
|
|
|
|
this.updateProgress(i, corpusSize);
|
|
|
|
this.updateMessage(String.format(I18N.get("message.ONGOING_NOTIFICATION_ANALYZING_FILE_X_OF_Y"), i, corpusSize, f.getName(), remainingSeconds));
|
|
|
|
// if (isCancelled()) {
|
|
|
|
// updateMessage(I18N.get("message.CANCELING_NOTIFICATION"));
|
|
|
|
// break;
|
|
|
|
// }
|
2018-12-01 09:50:11 +00:00
|
|
|
} else {
|
2019-01-08 10:38:44 +00:00
|
|
|
xml_processing.progressBarListener = new InvalidationListener() {
|
2019-01-07 11:55:11 +00:00
|
|
|
int remainingSeconds = -1;
|
|
|
|
Date previousTime = new Date();
|
|
|
|
@Override
|
|
|
|
public void invalidated(Observable observable) {
|
|
|
|
cancel.setVisible(true);
|
|
|
|
if ((new Date()).getTime() - previousTime.getTime() > 500 || remainingSeconds == -1){
|
|
|
|
remainingSeconds = (int) (((new Date()).getTime() - xml_processing.startTime.getTime()) *
|
|
|
|
(1.0/(iFinal * 100 + ((ReadOnlyDoubleWrapper) observable).get() + 1)) *
|
|
|
|
((corpusSize - iFinal - 1) * 100 + 100 - ((ReadOnlyDoubleWrapper) observable).get()) / 1000);
|
|
|
|
// System.out.println(((new Date()).getTime() - xml_processing.startTime.getTime()));
|
|
|
|
// System.out.println((1.0/(iFinal * 100 + ((ReadOnlyDoubleWrapper) observable).get() + 1)));
|
|
|
|
// System.out.println(((corpusSize - iFinal - 1) * 100 + 100 - ((ReadOnlyDoubleWrapper) observable).get()));
|
|
|
|
// System.out.println(remainingSeconds);
|
|
|
|
previousTime = new Date();
|
|
|
|
}
|
|
|
|
xml_processing.isCancelled = isCancelled();
|
|
|
|
updateProgress((iFinal * 100) + ((ReadOnlyDoubleWrapper) observable).get() + 1, corpusSize * 100);
|
|
|
|
updateMessage(String.format(I18N.get("message.ONGOING_NOTIFICATION_ANALYZING_FILE_X_OF_Y"), iFinal + 1, corpusSize, f.getName(), remainingSeconds));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-01-08 10:38:44 +00:00
|
|
|
xml_processing.progressProperty().addListener(xml_processing.progressBarListener);
|
2019-01-07 11:55:11 +00:00
|
|
|
}
|
|
|
|
xml_processing.isCollocability = true;
|
|
|
|
xml_processing.readXML(f.toString(), statisticsOneGrams);
|
|
|
|
xml_processing.isCollocability = false;
|
|
|
|
if (isCancelled()) {
|
|
|
|
updateMessage(I18N.get("message.CANCELING_NOTIFICATION"));
|
|
|
|
break;
|
2018-12-01 09:50:11 +00:00
|
|
|
}
|
2019-01-07 11:55:11 +00:00
|
|
|
// readXML(f.toString(), statisticsOneGrams);
|
|
|
|
// i++;
|
|
|
|
// this.updateProgress(i, corpusFiles.size() * 2);
|
|
|
|
// if (statistic.getFilter().getCollocability().size() > 0) {
|
|
|
|
// this.updateMessage(String.format(I18N.get("message.ONGOING_NOTIFICATION_ANALYZING_FILE_X_OF_Y"), i, corpusFiles.size() * 2, f.getName()));
|
|
|
|
// } else {
|
|
|
|
// this.updateMessage(String.format(I18N.get("message.ONGOING_NOTIFICATION_ANALYZING_FILE_X_OF_Y"), i, corpusFiles.size(), f.getName()));
|
|
|
|
// }
|
2018-10-24 08:36:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-11-05 09:30:41 +00:00
|
|
|
ngramProgressBar.progressProperty().bind(task.progressProperty());
|
|
|
|
progressLabel.textProperty().bind(task.messageProperty());
|
2018-10-24 08:36:07 +00:00
|
|
|
|
|
|
|
task.setOnSucceeded(e -> {
|
|
|
|
try {
|
|
|
|
System.out.print(statistic);
|
|
|
|
// calculate_collocabilities(statistic, statisticsOneGrams);
|
|
|
|
statistic.updateCalculateCollocabilities(statisticsOneGrams);
|
|
|
|
boolean successullySaved = statistic.saveResultToDisk();
|
|
|
|
if (successullySaved) {
|
2018-12-13 07:35:36 +00:00
|
|
|
showAlert(Alert.AlertType.INFORMATION, I18N.get("message.NOTIFICATION_ANALYSIS_COMPLETED"));
|
2018-10-24 08:36:07 +00:00
|
|
|
} else {
|
2018-12-13 07:35:36 +00:00
|
|
|
showAlert(Alert.AlertType.INFORMATION, I18N.get("message.NOTIFICATION_ANALYSIS_COMPLETED_NO_RESULTS"));
|
2018-10-24 08:36:07 +00:00
|
|
|
}
|
|
|
|
} catch (UnsupportedEncodingException e1) {
|
2018-12-13 07:35:36 +00:00
|
|
|
showAlert(Alert.AlertType.ERROR, I18N.get("message.ERROR_WHILE_SAVING_RESULTS_TO_CSV"));
|
2018-10-24 08:36:07 +00:00
|
|
|
logger.error("Error while saving", e1);
|
|
|
|
} catch (OutOfMemoryError e1) {
|
2018-12-13 07:35:36 +00:00
|
|
|
showAlert(Alert.AlertType.ERROR, I18N.get("message.ERROR_NOT_ENOUGH_MEMORY"));
|
2018-10-24 08:36:07 +00:00
|
|
|
logger.error("Out of memory error", e1);
|
|
|
|
}
|
|
|
|
// try {
|
|
|
|
// boolean successullySaved = statistic.saveResultToDisk();
|
|
|
|
// 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);
|
|
|
|
// } catch (OutOfMemoryError e1){
|
|
|
|
// showAlert(Alert.AlertType.ERROR, ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
// logger.error("Out of memory error", e1);
|
|
|
|
// }
|
|
|
|
//
|
2018-11-05 09:30:41 +00:00
|
|
|
ngramProgressBar.progressProperty().unbind();
|
|
|
|
ngramProgressBar.setStyle(Settings.FX_ACCENT_OK);
|
|
|
|
progressLabel.textProperty().unbind();
|
|
|
|
progressLabel.setText("");
|
|
|
|
cancel.setVisible(false);
|
2018-10-24 08:36:07 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
task.setOnFailed(e -> {
|
2018-12-13 07:35:36 +00:00
|
|
|
showAlert(Alert.AlertType.ERROR, I18N.get("message.ERROR_WHILE_EXECUTING"));
|
2018-11-05 09:30:41 +00:00
|
|
|
logger.error("Error while executing", e);
|
|
|
|
ngramProgressBar.progressProperty().unbind();
|
|
|
|
ngramProgressBar.setProgress(0.0);
|
|
|
|
ngramProgressBar.setStyle(Settings.FX_ACCENT_NOK);
|
|
|
|
progressLabel.textProperty().unbind();
|
|
|
|
progressLabel.setText("");
|
|
|
|
cancel.setVisible(false);
|
2018-10-24 08:36:07 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
task.setOnCancelled(e -> {
|
2018-12-13 07:35:36 +00:00
|
|
|
showAlert(Alert.AlertType.INFORMATION, I18N.get("message.NOTIFICATION_ANALYSIS_CANCELED"));
|
2018-11-05 09:30:41 +00:00
|
|
|
ngramProgressBar.progressProperty().unbind();
|
|
|
|
ngramProgressBar.setProgress(0.0);
|
|
|
|
ngramProgressBar.setStyle(Settings.FX_ACCENT_OK);
|
|
|
|
progressLabel.textProperty().unbind();
|
|
|
|
progressLabel.setText("");
|
|
|
|
cancel.setVisible(false);
|
2018-10-24 08:36:07 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// When cancel button is pressed cancel analysis
|
|
|
|
cancel.setOnAction(e -> {
|
|
|
|
task.cancel();
|
|
|
|
// logger.info("cancel button");
|
|
|
|
});
|
|
|
|
return task;
|
|
|
|
}
|
|
|
|
|
2018-06-19 07:15:37 +00:00
|
|
|
private void execute(StatisticsNew statistic) {
|
2018-10-24 08:36:07 +00:00
|
|
|
Filter f = statistic.getFilter();
|
|
|
|
logger.info("Started execution: ", f);
|
|
|
|
// Task<Void> task_collocability = null;
|
2018-06-19 07:15:37 +00:00
|
|
|
|
|
|
|
Collection<File> corpusFiles = statistic.getCorpus().getDetectedCorpusFiles();
|
|
|
|
|
|
|
|
final Task<Void> task = new Task<Void>() {
|
|
|
|
@SuppressWarnings("Duplicates")
|
|
|
|
@Override
|
|
|
|
protected Void call() throws Exception {
|
2019-01-08 10:38:44 +00:00
|
|
|
final boolean multipleFiles = CorpusType.multipleFilesCorpuses().contains(statistic.getCorpus().getCorpusType());
|
|
|
|
if(multipleFiles){
|
2019-01-07 11:55:11 +00:00
|
|
|
cancel.setVisible(true);
|
|
|
|
}
|
|
|
|
int i = 0;
|
|
|
|
Date startTime = new Date();
|
|
|
|
Date previousTime = new Date();
|
|
|
|
int remainingSeconds = -1;
|
|
|
|
int corpusSize;
|
|
|
|
if (statistic.getFilter().getCollocability().size() > 0) {
|
|
|
|
corpusSize = corpusFiles.size() * 2;
|
|
|
|
} else {
|
|
|
|
corpusSize = corpusFiles.size();
|
|
|
|
}
|
2018-06-19 07:15:37 +00:00
|
|
|
for (File f : corpusFiles) {
|
2019-01-07 11:55:11 +00:00
|
|
|
final int iFinal = i;
|
|
|
|
XML_processing xml_processing = new XML_processing();
|
2019-01-08 10:38:44 +00:00
|
|
|
xml_processing.isCancelled = false;
|
2018-06-19 07:15:37 +00:00
|
|
|
i++;
|
2019-01-08 10:38:44 +00:00
|
|
|
if(xml_processing.progressBarListener != null) {
|
|
|
|
xml_processing.progressProperty().removeListener(xml_processing.progressBarListener);
|
|
|
|
}
|
|
|
|
if (multipleFiles) {
|
2019-01-07 11:55:11 +00:00
|
|
|
if ((new Date()).getTime() - previousTime.getTime() > 500 || remainingSeconds == -1){
|
|
|
|
remainingSeconds = (int) (((new Date()).getTime() - startTime.getTime()) * (1.0/i) * (corpusSize - i) / 1000);
|
|
|
|
previousTime = new Date();
|
|
|
|
}
|
|
|
|
this.updateProgress(i, corpusSize);
|
|
|
|
this.updateMessage(String.format(I18N.get("message.ONGOING_NOTIFICATION_ANALYZING_FILE_X_OF_Y"), i, corpusSize, f.getName(), remainingSeconds));
|
|
|
|
// if (isCancelled()) {
|
|
|
|
// updateMessage(I18N.get("message.CANCELING_NOTIFICATION"));
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
} else {
|
2019-01-08 10:38:44 +00:00
|
|
|
xml_processing.progressBarListener = new InvalidationListener() {
|
2019-01-07 11:55:11 +00:00
|
|
|
int remainingSeconds = -1;
|
|
|
|
Date previousTime = new Date();
|
|
|
|
@Override
|
|
|
|
public void invalidated(Observable observable) {
|
|
|
|
cancel.setVisible(true);
|
|
|
|
if ((new Date()).getTime() - previousTime.getTime() > 500 || remainingSeconds == -1){
|
|
|
|
remainingSeconds = (int) (((new Date()).getTime() - xml_processing.startTime.getTime()) *
|
|
|
|
(1.0/(iFinal * 100 + ((ReadOnlyDoubleWrapper) observable).get() + 1)) *
|
|
|
|
((corpusSize - iFinal - 1) * 100 + 100 - ((ReadOnlyDoubleWrapper) observable).get()) / 1000);
|
|
|
|
// System.out.println(((new Date()).getTime() - xml_processing.startTime.getTime()));
|
|
|
|
// System.out.println((1.0/(iFinal * 100 + ((ReadOnlyDoubleWrapper) observable).get())) + 1);
|
|
|
|
// System.out.println(((corpusSize - iFinal - 1) * 100 + 100 - ((ReadOnlyDoubleWrapper) observable).get()));
|
|
|
|
// System.out.println(remainingSeconds);
|
|
|
|
previousTime = new Date();
|
|
|
|
}
|
|
|
|
xml_processing.isCancelled = isCancelled();
|
|
|
|
updateProgress((iFinal * 100) + ((ReadOnlyDoubleWrapper) observable).get() + 1, corpusSize * 100);
|
|
|
|
updateMessage(String.format(I18N.get("message.ONGOING_NOTIFICATION_ANALYZING_FILE_X_OF_Y"), iFinal + 1, corpusSize, f.getName(), remainingSeconds));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-01-08 10:38:44 +00:00
|
|
|
xml_processing.progressProperty().addListener(xml_processing.progressBarListener);
|
2019-01-07 11:55:11 +00:00
|
|
|
}
|
|
|
|
xml_processing.readXML(f.toString(), statistic);
|
2018-06-29 10:53:29 +00:00
|
|
|
if (isCancelled()) {
|
2018-12-13 07:35:36 +00:00
|
|
|
updateMessage(I18N.get("message.CANCELING_NOTIFICATION"));
|
2018-06-29 10:53:29 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-01-08 10:38:44 +00:00
|
|
|
if(!(multipleFiles)){
|
2019-01-07 11:55:11 +00:00
|
|
|
cancel.setVisible(false);
|
2018-11-05 09:30:41 +00:00
|
|
|
}
|
2019-01-07 11:55:11 +00:00
|
|
|
// readXML(f.toString(), statistic);
|
|
|
|
// i++;
|
|
|
|
// if (isCancelled()) {
|
|
|
|
// updateMessage(I18N.get("message.CANCELING_NOTIFICATION"));
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
// if (statistic.getFilter().getCollocability().size() > 0) {
|
|
|
|
// this.updateProgress(i, corpusFiles.size() * 2);
|
|
|
|
// this.updateMessage(String.format(I18N.get("message.ONGOING_NOTIFICATION_ANALYZING_FILE_X_OF_Y"), i, corpusFiles.size() * 2, f.getName()));
|
|
|
|
// } else {
|
|
|
|
// 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(ONGOING_NOTIFICATION_ANALYZING_FILE_X_OF_Y, i, corpusFiles.size() * 2, f.getName()));
|
2018-06-19 07:15:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
ngramProgressBar.progressProperty().bind(task.progressProperty());
|
|
|
|
progressLabel.textProperty().bind(task.messageProperty());
|
|
|
|
task.setOnSucceeded(e -> {
|
2018-10-24 08:36:07 +00:00
|
|
|
if (f.getCollocability().size() > 0) {
|
|
|
|
try{
|
|
|
|
Filter f2 = (Filter) f.clone();
|
|
|
|
f2.setNgramValue(1);
|
|
|
|
StatisticsNew statisticsOneGrams = new StatisticsNew(corpus, f2, useDb);
|
|
|
|
final Task<Void> taskCollocability = prepareTaskForCollocability(statistic, statisticsOneGrams);
|
|
|
|
final Thread thread_collocability = new Thread(taskCollocability, "task_collocability");
|
|
|
|
thread_collocability.setDaemon(true);
|
|
|
|
thread_collocability.start();
|
|
|
|
}catch(CloneNotSupportedException c){}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
// System.out.print(statistics);
|
|
|
|
boolean successullySaved = statistic.saveResultToDisk();
|
|
|
|
if (successullySaved) {
|
2018-12-13 07:35:36 +00:00
|
|
|
showAlert(Alert.AlertType.INFORMATION, I18N.get("message.NOTIFICATION_ANALYSIS_COMPLETED"));
|
2018-10-24 08:36:07 +00:00
|
|
|
} else {
|
2018-12-13 07:35:36 +00:00
|
|
|
showAlert(Alert.AlertType.INFORMATION, I18N.get("message.NOTIFICATION_ANALYSIS_COMPLETED_NO_RESULTS"));
|
2018-10-24 08:36:07 +00:00
|
|
|
}
|
|
|
|
} catch (UnsupportedEncodingException e1) {
|
2018-12-13 07:35:36 +00:00
|
|
|
showAlert(Alert.AlertType.ERROR, I18N.get("message.ERROR_WHILE_SAVING_RESULTS_TO_CSV"));
|
2018-10-24 08:36:07 +00:00
|
|
|
logger.error("Error while saving", e1);
|
|
|
|
} catch (OutOfMemoryError e1) {
|
2018-12-13 07:35:36 +00:00
|
|
|
showAlert(Alert.AlertType.ERROR, I18N.get("message.ERROR_NOT_ENOUGH_MEMORY"));
|
2018-10-24 08:36:07 +00:00
|
|
|
logger.error("Out of memory error", e1);
|
2018-06-19 07:15:37 +00:00
|
|
|
}
|
2018-11-05 09:30:41 +00:00
|
|
|
ngramProgressBar.progressProperty().unbind();
|
|
|
|
ngramProgressBar.setStyle(Settings.FX_ACCENT_OK);
|
|
|
|
progressLabel.textProperty().unbind();
|
|
|
|
progressLabel.setText("");
|
|
|
|
cancel.setVisible(false);
|
2018-06-19 07:15:37 +00:00
|
|
|
}
|
|
|
|
|
2018-11-05 09:30:41 +00:00
|
|
|
|
2018-06-19 07:15:37 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
task.setOnFailed(e -> {
|
2018-12-13 07:35:36 +00:00
|
|
|
showAlert(Alert.AlertType.ERROR, I18N.get("message.ERROR_WHILE_EXECUTING"));
|
2018-06-19 07:15:37 +00:00
|
|
|
logger.error("Error while executing", e);
|
|
|
|
ngramProgressBar.progressProperty().unbind();
|
|
|
|
ngramProgressBar.setProgress(0.0);
|
|
|
|
ngramProgressBar.setStyle(Settings.FX_ACCENT_NOK);
|
|
|
|
progressLabel.textProperty().unbind();
|
|
|
|
progressLabel.setText("");
|
2018-06-29 10:53:29 +00:00
|
|
|
cancel.setVisible(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
task.setOnCancelled(e -> {
|
2018-12-13 07:35:36 +00:00
|
|
|
showAlert(Alert.AlertType.INFORMATION, I18N.get("message.NOTIFICATION_ANALYSIS_CANCELED"));
|
2018-06-29 10:53:29 +00:00
|
|
|
ngramProgressBar.progressProperty().unbind();
|
|
|
|
ngramProgressBar.setProgress(0.0);
|
|
|
|
ngramProgressBar.setStyle(Settings.FX_ACCENT_OK);
|
|
|
|
progressLabel.textProperty().unbind();
|
|
|
|
progressLabel.setText("");
|
|
|
|
cancel.setVisible(false);
|
2018-06-19 07:15:37 +00:00
|
|
|
});
|
|
|
|
|
2018-06-29 10:53:29 +00:00
|
|
|
// When cancel button is pressed cancel analysis
|
|
|
|
cancel.setOnAction(e -> {
|
|
|
|
task.cancel();
|
|
|
|
logger.info("cancel button");
|
|
|
|
});
|
|
|
|
|
2018-06-19 07:15:37 +00:00
|
|
|
final Thread thread = new Thread(task, "task");
|
|
|
|
thread.setDaemon(true);
|
|
|
|
thread.start();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setSolarFiltersMap(HashMap<String, HashSet<String>> solarFiltersMap) {
|
|
|
|
this.solarFiltersMap = solarFiltersMap;
|
|
|
|
}
|
|
|
|
public void setHostServices(HostServices hostServices){
|
|
|
|
this.hostService = hostServices;
|
|
|
|
}
|
|
|
|
}
|