|
|
|
@ -11,6 +11,7 @@ import java.lang.reflect.Constructor;
|
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
import javafx.collections.FXCollections;
|
|
|
|
|
import javafx.scene.layout.AnchorPane;
|
|
|
|
|
import javafx.util.Duration;
|
|
|
|
|
import org.apache.commons.io.FileUtils;
|
|
|
|
@ -70,6 +71,29 @@ public class CorpusTab {
|
|
|
|
|
private Label chooseResultsL;
|
|
|
|
|
private String chooseResultsLabelContent;
|
|
|
|
|
|
|
|
|
|
@FXML
|
|
|
|
|
public Label chooseCorpusLocationL;
|
|
|
|
|
|
|
|
|
|
@FXML
|
|
|
|
|
public Label readHeaderInfoL;
|
|
|
|
|
|
|
|
|
|
@FXML
|
|
|
|
|
public Label chooseResultsLocationL;
|
|
|
|
|
|
|
|
|
|
@FXML
|
|
|
|
|
public Label selectReaderL;
|
|
|
|
|
|
|
|
|
|
@FXML
|
|
|
|
|
public Label outputNameL;
|
|
|
|
|
|
|
|
|
|
@FXML
|
|
|
|
|
public TextField outputNameTF;
|
|
|
|
|
public String outputName;
|
|
|
|
|
|
|
|
|
|
@FXML
|
|
|
|
|
public ComboBox<String> selectReaderCB;
|
|
|
|
|
public String selectReader;
|
|
|
|
|
|
|
|
|
|
@FXML
|
|
|
|
|
private ProgressIndicator locationScanPI;
|
|
|
|
|
|
|
|
|
@ -99,6 +123,11 @@ public class CorpusTab {
|
|
|
|
|
private String corpusLocation;
|
|
|
|
|
private String corpusFilesSize;
|
|
|
|
|
|
|
|
|
|
private static final String [] SELECT_READER_ARRAY = {"vert", "Solar", "GOS", "SSJ500K", "Gigafida", "Gigafida (old)", "Kres (old)"};
|
|
|
|
|
private static final ArrayList<String> SELECT_READER = new ArrayList<>(Arrays.asList(SELECT_READER_ARRAY));
|
|
|
|
|
private Collection<File> corpusFiles;
|
|
|
|
|
private File selectedDirectory;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Hack allowing to modify the default behavior of the tooltips.
|
|
|
|
|
* @param openDelay The open delay, knowing that by default it is set to 1000.
|
|
|
|
@ -145,6 +174,30 @@ public class CorpusTab {
|
|
|
|
|
|
|
|
|
|
manageTranslations();
|
|
|
|
|
|
|
|
|
|
selectReaderCB.setItems(FXCollections.observableArrayList(SELECT_READER));
|
|
|
|
|
|
|
|
|
|
selectReaderCB.valueProperty().addListener((observable, oldValue, newValue) -> {
|
|
|
|
|
if(newValue == null){
|
|
|
|
|
// newValue = I18N.getTranslatedValue(oldValue, N_GRAM_COMPUTE_FOR_LETTERS);
|
|
|
|
|
selectReaderCB.getSelectionModel().select(newValue);
|
|
|
|
|
}
|
|
|
|
|
// System.out.println(oldValue);
|
|
|
|
|
// System.out.println(newValue);
|
|
|
|
|
selectReader = newValue;
|
|
|
|
|
selectReader();
|
|
|
|
|
if(corpus != null && corpus.getCorpusType() != null) {
|
|
|
|
|
changeCorpus();
|
|
|
|
|
}
|
|
|
|
|
logger.info("calculateForCB:", newValue);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
outputNameTF.focusedProperty().addListener((observable, oldValue, newValue) -> {
|
|
|
|
|
corpus.setCorpusName(outputNameTF.getText());
|
|
|
|
|
outputName = outputNameTF.getText();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
selectReaderCB.getSelectionModel().select(0);
|
|
|
|
|
|
|
|
|
|
// add listeners
|
|
|
|
|
chooseCorpusLocationB.setOnAction(e -> chooseCorpusLocation());
|
|
|
|
|
chooseCorpusLocationB.setTooltip(new Tooltip(I18N.get("message.TOOLTIP_chooseCorpusLocationB")));
|
|
|
|
@ -206,13 +259,18 @@ public class CorpusTab {
|
|
|
|
|
|
|
|
|
|
private void manageTranslations(){
|
|
|
|
|
chooseCorpusLocationB.textProperty().bind(I18N.createStringBinding("button.setCorpusLocation"));
|
|
|
|
|
chooseCorpusLocationL.textProperty().bind(I18N.createStringBinding("label.setCorpusLocation"));
|
|
|
|
|
readHeaderInfoChB.textProperty().bind(I18N.createStringBinding("checkBox.readHeaderInfo"));
|
|
|
|
|
chooseResultsLocationB.textProperty().bind(I18N.createStringBinding("button.chooseResultsLocation"));
|
|
|
|
|
chooseResultsLocationL.textProperty().bind(I18N.createStringBinding("label.chooseResultsLocation"));
|
|
|
|
|
helpH.textProperty().bind(I18N.createStringBinding("hyperlink.help"));
|
|
|
|
|
changeLanguageB.textProperty().bind(I18N.createStringBinding("button.language"));
|
|
|
|
|
chooseCorpusL.textProperty().bind(I18N.createStringBinding("message.LABEL_CORPUS_LOCATION_NOT_SET"));
|
|
|
|
|
chooseResultsL.textProperty().bind(I18N.createStringBinding("message.LABEL_RESULTS_LOCATION_NOT_SET"));
|
|
|
|
|
|
|
|
|
|
readHeaderInfoL.textProperty().bind(I18N.createStringBinding("label.readHeaderInfo"));
|
|
|
|
|
selectReaderL.textProperty().bind(I18N.createStringBinding("label.selectReader"));
|
|
|
|
|
outputNameL.textProperty().bind(I18N.createStringBinding("label.outputName"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void togglePiAndSetCorpusWrapper(boolean piIsActive) {
|
|
|
|
@ -238,101 +296,117 @@ public class CorpusTab {
|
|
|
|
|
* has to produce a non-empty list results list
|
|
|
|
|
*/
|
|
|
|
|
private void chooseCorpusLocation() {
|
|
|
|
|
File selectedDirectory = directoryChooser();
|
|
|
|
|
selectedDirectory = directoryChooser();
|
|
|
|
|
|
|
|
|
|
if (selectedDirectory != null && ValidationUtil.isReadableDirectory(selectedDirectory)) {
|
|
|
|
|
logger.info("selected corpus dir: ", selectedDirectory.getAbsolutePath());
|
|
|
|
|
|
|
|
|
|
// scan for xml files
|
|
|
|
|
Collection<File> corpusFiles = FileUtils.listFiles(selectedDirectory, FileFilterUtils.suffixFileFilter("xml", IOCase.INSENSITIVE), TrueFileFilter.INSTANCE);
|
|
|
|
|
corpusFiles = FileUtils.listFiles(selectedDirectory, FileFilterUtils.suffixFileFilter("xml", IOCase.INSENSITIVE), TrueFileFilter.INSTANCE);
|
|
|
|
|
|
|
|
|
|
changeCorpus();
|
|
|
|
|
|
|
|
|
|
// make sure there are corpus files in selected directory or notify the user about it
|
|
|
|
|
if (corpusFiles.size() == 0) {
|
|
|
|
|
// try .vert
|
|
|
|
|
corpusFiles = FileUtils.listFiles(selectedDirectory, FileFilterUtils.suffixFileFilter("vert", IOCase.INSENSITIVE), TrueFileFilter.INSTANCE);
|
|
|
|
|
Collection<File> corpusFilesRegi = FileUtils.listFiles(selectedDirectory, FileFilterUtils.suffixFileFilter("regi", IOCase.INSENSITIVE), TrueFileFilter.INSTANCE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void changeCorpus(){
|
|
|
|
|
// make sure there are corpus files in selected directory or notify the user about it
|
|
|
|
|
if (corpusFiles.size() == 0) {
|
|
|
|
|
// try .vert
|
|
|
|
|
corpusFiles = FileUtils.listFiles(selectedDirectory, FileFilterUtils.suffixFileFilter("vert", IOCase.INSENSITIVE), TrueFileFilter.INSTANCE);
|
|
|
|
|
Collection<File> corpusFilesRegi = FileUtils.listFiles(selectedDirectory, FileFilterUtils.suffixFileFilter("regi", IOCase.INSENSITIVE), TrueFileFilter.INSTANCE);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if (!checkRegiFile(corpusFilesRegi)){
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
if (corpusFiles.size() == 0){
|
|
|
|
|
logger.info("alert: ", I18N.get("message.WARNING_CORPUS_NOT_FOUND"));
|
|
|
|
|
showAlert(Alert.AlertType.ERROR, I18N.get("message.WARNING_CORPUS_NOT_FOUND"), null);
|
|
|
|
|
} else if (corpusFilesRegi.size() == 0){
|
|
|
|
|
GUIController.showAlert(Alert.AlertType.ERROR, String.format(I18N.get("message.ERROR_NO_REGI_FILE_FOUND"), selectedDirectory.getAbsolutePath()));
|
|
|
|
|
} else {
|
|
|
|
|
corpusLocation = selectedDirectory.getAbsolutePath();
|
|
|
|
|
corpusFilesSize = String.valueOf(corpusFiles.size());
|
|
|
|
|
Messages.setChooseCorpusProperties(corpusLocation, corpusFilesSize, corpusType != null ? corpusType.toString() : null);
|
|
|
|
|
corpusType = VERT;
|
|
|
|
|
|
|
|
|
|
corpus.setCorpusType(corpusType);
|
|
|
|
|
if (corpusFiles.size() == 0){
|
|
|
|
|
logger.info("alert: ", I18N.get("message.WARNING_CORPUS_NOT_FOUND"));
|
|
|
|
|
showAlert(Alert.AlertType.ERROR, I18N.get("message.WARNING_CORPUS_NOT_FOUND"), null);
|
|
|
|
|
} else if (corpusFilesRegi.size() == 0){
|
|
|
|
|
GUIController.showAlert(Alert.AlertType.ERROR, String.format(I18N.get("message.ERROR_NO_REGI_FILE_FOUND"), selectedDirectory.getAbsolutePath()));
|
|
|
|
|
} else {
|
|
|
|
|
corpusLocation = selectedDirectory.getAbsolutePath();
|
|
|
|
|
corpusFilesSize = String.valueOf(corpusFiles.size());
|
|
|
|
|
Messages.setChooseCorpusProperties(corpusLocation, corpusFilesSize, corpusType != null ? corpusType.toString() : null);
|
|
|
|
|
// corpusType = VERT;
|
|
|
|
|
|
|
|
|
|
Messages.setChooseCorpusProperties(corpusLocation, corpusFilesSize, corpusType.toString());
|
|
|
|
|
corpus.setCorpusType(corpusType);
|
|
|
|
|
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
sb.append(corpusLocation)
|
|
|
|
|
.append("\n")
|
|
|
|
|
.append(String.format(I18N.get("message.NOTIFICATION_FOUND_X_FILES"), corpusFiles.size()))
|
|
|
|
|
.append("\n")
|
|
|
|
|
.append(String.format(I18N.get("message.NOTIFICATION_CORPUS"), corpusType.toString()));
|
|
|
|
|
Messages.setChooseCorpusProperties(corpusLocation, corpusFilesSize, corpusType.toString());
|
|
|
|
|
|
|
|
|
|
String result = sb.toString();
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
sb.append(corpusLocation)
|
|
|
|
|
.append("\n")
|
|
|
|
|
.append(String.format(I18N.get("message.NOTIFICATION_FOUND_X_FILES"), corpusFiles.size()))
|
|
|
|
|
.append("\n")
|
|
|
|
|
.append(String.format(I18N.get("message.NOTIFICATION_CORPUS"), corpusType.toString()));
|
|
|
|
|
|
|
|
|
|
logger.debug(result);
|
|
|
|
|
String result = sb.toString();
|
|
|
|
|
|
|
|
|
|
initNewCorpus(selectedDirectory, corpusFiles);
|
|
|
|
|
Messages.setChooseCorpusProperties(corpusLocation, corpusFilesSize, corpusType.toString());
|
|
|
|
|
logger.debug(result);
|
|
|
|
|
|
|
|
|
|
corpus.setChosenCorpusLocation(selectedDirectory);
|
|
|
|
|
corpus.setDetectedCorpusFiles(corpusFiles);
|
|
|
|
|
initNewCorpus(selectedDirectory, corpusFiles);
|
|
|
|
|
Messages.setChooseCorpusProperties(corpusLocation, corpusFilesSize, corpusType.toString());
|
|
|
|
|
|
|
|
|
|
chooseCorpusLabelContent = result;
|
|
|
|
|
if (readHeaderInfo) {
|
|
|
|
|
logger.info("reading header info...");
|
|
|
|
|
readHeaderInfo();
|
|
|
|
|
} else {
|
|
|
|
|
setResults();
|
|
|
|
|
corpus.setChosenCorpusLocation(selectedDirectory);
|
|
|
|
|
corpus.setDetectedCorpusFiles(corpusFiles);
|
|
|
|
|
|
|
|
|
|
setCorpusForAnalysis();
|
|
|
|
|
}
|
|
|
|
|
chooseCorpusLabelContent = result;
|
|
|
|
|
if (readHeaderInfo) {
|
|
|
|
|
logger.info("reading header info...");
|
|
|
|
|
readHeaderInfo();
|
|
|
|
|
} else {
|
|
|
|
|
setResults();
|
|
|
|
|
|
|
|
|
|
setCorpusForAnalysis();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
corpusLocation = selectedDirectory.getAbsolutePath();
|
|
|
|
|
corpusFilesSize = String.valueOf(corpusFiles.size());
|
|
|
|
|
Messages.setChooseCorpusProperties(corpusLocation, corpusFilesSize, corpusType != null ? corpusType.toString() : null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String chooseCorpusLabelContentTmp = detectCorpusType(corpusFiles);
|
|
|
|
|
} else {
|
|
|
|
|
System.out.println(corpusLocation);
|
|
|
|
|
corpusLocation = selectedDirectory.getAbsolutePath();
|
|
|
|
|
corpusFilesSize = String.valueOf(corpusFiles.size());
|
|
|
|
|
Messages.setChooseCorpusProperties(corpusLocation, corpusFilesSize, corpusType != null ? corpusType.toString() : null);
|
|
|
|
|
|
|
|
|
|
if (chooseCorpusLabelContentTmp == null) {
|
|
|
|
|
logger.info("alert: ", I18N.get("message.WARNING_CORPUS_NOT_FOUND"));
|
|
|
|
|
showAlert(Alert.AlertType.ERROR, I18N.get("message.WARNING_CORPUS_NOT_FOUND"), null);
|
|
|
|
|
} else {
|
|
|
|
|
// String chooseCorpusLabelContentTmp = detectCorpusType(corpusFiles);
|
|
|
|
|
selectReader();
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
sb.append(corpusLocation)
|
|
|
|
|
.append("\n")
|
|
|
|
|
.append(String.format(I18N.get("message.NOTIFICATION_FOUND_X_FILES"), corpusFiles.size()))
|
|
|
|
|
.append("\n")
|
|
|
|
|
.append(String.format(I18N.get("message.NOTIFICATION_CORPUS"), corpusType.toString()));
|
|
|
|
|
|
|
|
|
|
String chooseCorpusLabelContentTmp = sb.toString();
|
|
|
|
|
logger.debug(chooseCorpusLabelContentTmp);
|
|
|
|
|
|
|
|
|
|
initNewCorpus(selectedDirectory, corpusFiles);
|
|
|
|
|
Messages.setChooseCorpusProperties(corpusLocation, corpusFilesSize, corpusType.toString());
|
|
|
|
|
if (chooseCorpusLabelContentTmp == null) {
|
|
|
|
|
logger.info("alert: ", I18N.get("message.WARNING_CORPUS_NOT_FOUND"));
|
|
|
|
|
showAlert(Alert.AlertType.ERROR, I18N.get("message.WARNING_CORPUS_NOT_FOUND"), null);
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
corpus.setChosenCorpusLocation(selectedDirectory);
|
|
|
|
|
corpus.setDetectedCorpusFiles(corpusFiles);
|
|
|
|
|
chooseCorpusLabelContent = chooseCorpusLabelContentTmp;
|
|
|
|
|
logger.info("corpus dir: ", corpus.getChosenCorpusLocation().getAbsolutePath());
|
|
|
|
|
initNewCorpus(selectedDirectory, corpusFiles);
|
|
|
|
|
Messages.setChooseCorpusProperties(corpusLocation, corpusFilesSize, corpusType.toString());
|
|
|
|
|
|
|
|
|
|
if (readHeaderInfo) {
|
|
|
|
|
logger.info("reading header info...");
|
|
|
|
|
readHeaderInfo();
|
|
|
|
|
} else {
|
|
|
|
|
setResults();
|
|
|
|
|
corpus.setChosenCorpusLocation(selectedDirectory);
|
|
|
|
|
corpus.setDetectedCorpusFiles(corpusFiles);
|
|
|
|
|
chooseCorpusLabelContent = chooseCorpusLabelContentTmp;
|
|
|
|
|
logger.info("corpus dir: ", corpus.getChosenCorpusLocation().getAbsolutePath());
|
|
|
|
|
|
|
|
|
|
setCorpusForAnalysis();
|
|
|
|
|
}
|
|
|
|
|
if (readHeaderInfo) {
|
|
|
|
|
logger.info("reading header info...");
|
|
|
|
|
readHeaderInfo();
|
|
|
|
|
} else {
|
|
|
|
|
setResults();
|
|
|
|
|
|
|
|
|
|
setCorpusForAnalysis();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
corpus.setCorpusName(outputName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -661,6 +735,36 @@ public class CorpusTab {
|
|
|
|
|
// gosUseOrthChB.setVisible(corpus != null && corpus.getCorpusType() != null && corpus.getCorpusType() == CorpusType.GOS);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
private void selectReader() {
|
|
|
|
|
switch (selectReader) {
|
|
|
|
|
// "vert", "Solar", "GOS", "SSJ500K", "Gigafida", "Gigafida (old)", "Kres (old)"
|
|
|
|
|
case "vert":
|
|
|
|
|
corpusType = VERT;
|
|
|
|
|
break;
|
|
|
|
|
case "Solar":
|
|
|
|
|
corpusType = SOLAR;
|
|
|
|
|
break;
|
|
|
|
|
case "GOS":
|
|
|
|
|
corpusType = GOS;
|
|
|
|
|
break;
|
|
|
|
|
case "SSJ500K":
|
|
|
|
|
corpusType = SSJ500K;
|
|
|
|
|
break;
|
|
|
|
|
case "Gigafida":
|
|
|
|
|
corpusType = GIGAFIDA2;
|
|
|
|
|
break;
|
|
|
|
|
case "Gigafida (old)":
|
|
|
|
|
corpusType = GIGAFIDA;
|
|
|
|
|
break;
|
|
|
|
|
case "Kres (old)":
|
|
|
|
|
corpusType = CCKRES;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
logger.debug("No output detected!");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String detectCorpusType(Collection<File> corpusFiles) {
|
|
|
|
|
// check that we recognize this corpus
|
|
|
|
|
// read first file only, maybe later do all, if toll on resources is acceptable
|
|
|
|
|