diff --git a/src/main/java/alg/XML_processing.java b/src/main/java/alg/XML_processing.java index d0875e6..5d4ebcd 100755 --- a/src/main/java/alg/XML_processing.java +++ b/src/main/java/alg/XML_processing.java @@ -882,7 +882,8 @@ public class XML_processing { } } } catch (FileNotFoundException | XMLStreamException e) { - e.printStackTrace(); + throw new java.lang.RuntimeException("XMLStreamException | FileNotFoundException"); +// e.printStackTrace(); } finally { if (eventReader != null) { try { @@ -1486,7 +1487,8 @@ public class XML_processing { LineIterator.closeQuietly(regiIt); } } catch (IOException e) { - e.printStackTrace(); + throw new java.lang.RuntimeException("IOException"); +// e.printStackTrace(); } int numLines = 0; @@ -1539,7 +1541,7 @@ public class XML_processing { // beginning tags // taxonomy - if (line.length() > 4 && line.substring(1, 5).equals("text")) { + if (stats.getCorpus().getTaxonomy().size() > 0 && line.length() > 4 && line.substring(1, 5).equals("text")) { String[] split = line.split("\" "); currentFiletaxonomy = new ArrayList<>(); diff --git a/src/main/java/data/Corpus.java b/src/main/java/data/Corpus.java index 8e8b820..95d2d48 100755 --- a/src/main/java/data/Corpus.java +++ b/src/main/java/data/Corpus.java @@ -35,12 +35,23 @@ public class Corpus { private boolean gosOrthMode; boolean hasMsdData; private ArrayList validationErrors; + private String corpusName = ""; public Corpus() { validationErrors = new ArrayList<>(); setTotal(); } + public String getCorpusName() { + return corpusName; + } + + public void setCorpusName(String corpusName) { + System.out.println(corpusName); + this.corpusName = corpusName; + logger.info("Corpus.set: ", corpusName); + } + public CorpusType getCorpusType() { return corpusType; } diff --git a/src/main/java/data/StatisticsNew.java b/src/main/java/data/StatisticsNew.java index 9a4031c..a47a59d 100755 --- a/src/main/java/data/StatisticsNew.java +++ b/src/main/java/data/StatisticsNew.java @@ -109,34 +109,43 @@ public class StatisticsNew { if (filter.getAl() == AnalysisLevel.STRING_LEVEL) { Integer ngramLevel = filter.getNgramValue(); + String name = corpus.getCorpusName(); if(ngramLevel == 0) { - sb.append(corpus.getCorpusType().toString()) - .append(separator) - .append(I18N.get("exportFileName.letters")) + if(!name.equals("")) { + sb.append(name) + .append(separator); + } + sb.append(I18N.get("exportFileName.letters")) .append(separator) .append(filter.getCalculateFor()) .append(separator); } else if(ngramLevel == 1) { if (filter.getSuffixLength() != null && filter.getSuffixList() != null && filter.getPrefixLength() != null && filter.getPrefixList() != null) { - sb.append(corpus.getCorpusType().toString()) - .append(separator) - .append(I18N.get("exportFileName.wordParts")) + if(!name.equals("")) { + sb.append(name) + .append(separator); + } + sb.append(I18N.get("exportFileName.wordParts")) .append(separator) .append(filter.getCalculateFor()) .append(separator); } else { - sb.append(corpus.getCorpusType().toString()) - .append(separator) - .append(I18N.get("exportFileName.words")) + if(!name.equals("")) { + sb.append(name) + .append(separator); + } + sb.append(I18N.get("exportFileName.words")) .append(separator) .append(filter.getCalculateFor()) .append(separator); } } else { - sb.append(corpus.getCorpusType().toString()) - .append(separator) - .append(I18N.get("exportFileName.wordSets")) + if(!name.equals("")) { + sb.append(name) + .append(separator); + } + sb.append(I18N.get("exportFileName.wordSets")) .append(separator); sb.append(filter.getCalculateFor().toString()) .append(separator); diff --git a/src/main/java/gui/CorpusTab.java b/src/main/java/gui/CorpusTab.java index 62cc2cd..f6d5128 100755 --- a/src/main/java/gui/CorpusTab.java +++ b/src/main/java/gui/CorpusTab.java @@ -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 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 SELECT_READER = new ArrayList<>(Arrays.asList(SELECT_READER_ARRAY)); + private Collection 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 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 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 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 corpusFiles) { // check that we recognize this corpus // read first file only, maybe later do all, if toll on resources is acceptable diff --git a/src/main/resources/gui/CorpusTab.fxml b/src/main/resources/gui/CorpusTab.fxml index 8e7be4a..7da44c5 100755 --- a/src/main/resources/gui/CorpusTab.fxml +++ b/src/main/resources/gui/CorpusTab.fxml @@ -8,12 +8,15 @@ + + -