Added custom name string functionality

master
Luka 5 years ago
parent 2d7d5169cc
commit 4a53362566

@ -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<>();

@ -35,12 +35,23 @@ public class Corpus {
private boolean gosOrthMode;
boolean hasMsdData;
private ArrayList<String> 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;
}

@ -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);

@ -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

@ -8,12 +8,15 @@
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.TextField?>
<AnchorPane fx:id="corpusTabPane" prefHeight="600.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="gui.CorpusTab">
<children>
<Pane/>
<Button fx:id="chooseCorpusLocationB" layoutX="10.0" layoutY="20.0" mnemonicParsing="false"/>
<CheckBox fx:id="readHeaderInfoChB" layoutX="185.0" layoutY="24.0" mnemonicParsing="false"/>
<!--<TextField fx:id="stringLengthTF" layoutX="225.0" layoutY="20.0" prefWidth="140.0" />-->
<Label fx:id="chooseCorpusLocationL" layoutX="10.0" layoutY="20.0" prefHeight="25.0" text="Nastavi lokacijo korpusa" />
<Button fx:id="chooseCorpusLocationB" layoutX="225.0" layoutY="20.0" prefWidth="140.0" mnemonicParsing="false"/>
<Pane fx:id="setCorpusWrapperP" layoutX="10.0" layoutY="60.0" prefHeight="118.0" prefWidth="683.0">
<children>
<Label fx:id="chooseCorpusL" prefHeight="70.0" prefWidth="704.0" text="Label"/>
@ -21,9 +24,21 @@
</children>
</Pane>
<ProgressIndicator fx:id="locationScanPI" layoutX="10.0" layoutY="60.0" prefHeight="50.0" progress="0.0"/>
<Button fx:id="chooseResultsLocationB" layoutX="10.0" layoutY="180.0" mnemonicParsing="false"/>
<Label fx:id="readHeaderInfoL" layoutX="10.0" layoutY="140.0" prefHeight="25.0" text="Preberi info iz headerjev" />
<CheckBox fx:id="readHeaderInfoChB" layoutX="283.0" layoutY="140.0" mnemonicParsing="false"/>
<Label fx:id="chooseResultsLocationL" layoutX="10.0" layoutY="180.0" prefHeight="25.0" text="Nastavi lokacijo rezultatov" />
<Button fx:id="chooseResultsLocationB" layoutX="225.0" layoutY="180.0" prefWidth="140.0" mnemonicParsing="false"/>
<Label fx:id="chooseResultsL" layoutX="10.0" layoutY="220.0" text="Label"/>
<Label fx:id="selectReaderL" layoutX="10.0" layoutY="260.0" prefHeight="25.0" text="Izberi bralnik"/>
<ComboBox fx:id="selectReaderCB" layoutX="225.0" layoutY="260.0" minWidth="140.0" prefWidth="140.0"
visibleRowCount="5"/>
<Label fx:id="outputNameL" layoutX="10.0" layoutY="300.0" prefHeight="25.0" text="Ime izhodne datoteke" />
<TextField fx:id="outputNameTF" layoutX="225.0" layoutY="300.0" prefWidth="140.0" />
<Hyperlink fx:id="helpH" alignment="TOP_LEFT" layoutX="710.0" layoutY="16.0"/>
<Button fx:id="changeLanguageB" layoutX="710.0" layoutY="40.0" mnemonicParsing="false" prefWidth="50.0"/>
</children>

@ -15,9 +15,14 @@ tab.oneWordAnalysisTab=Words
tab.stringLevelTabNew2=Word sets
# corpus tab
button.setCorpusLocation=Set corpus location
label.setCorpusLocation=Set corpus location
button.setCorpusLocation=Set location
label.readHeaderInfo=Read info from headers
checkBox.readHeaderInfo=Read info from headers
button.chooseResultsLocation=Choose result location
label.chooseResultsLocation=Choose result location
button.chooseResultsLocation=Set location
label.selectReader=Select reader
label.outputName=Output file name
# character analysis tab
label.stringLength=Number of letters

@ -15,9 +15,14 @@ tab.oneWordAnalysisTab=Besede
tab.stringLevelTabNew2=Besedni nizi
# corpus tab
button.setCorpusLocation=Nastavi lokacijo korpusa
label.setCorpusLocation=Nastavi lokacijo korpusa
button.setCorpusLocation=Ponastavi
label.readHeaderInfo=Preberi info iz headerjev
checkBox.readHeaderInfo=Preberi info iz headerjev
button.chooseResultsLocation=Nastavi lokacijo rezultatov
label.chooseResultsLocation=Nastavi lokacijo rezultatov
button.chooseResultsLocation=Ponastavi
label.selectReader=Izberi bralnik
label.outputName=Ime izhodne datoteke
# character analysis tab
label.stringLength=Dolžina črkovnih nizov

Loading…
Cancel
Save