Added custom name string functionality

This commit is contained in:
Luka 2019-01-16 09:09:25 +01:00
parent 2d7d5169cc
commit 4a53362566
7 changed files with 241 additions and 90 deletions

View File

@ -882,7 +882,8 @@ public class XML_processing {
} }
} }
} catch (FileNotFoundException | XMLStreamException e) { } catch (FileNotFoundException | XMLStreamException e) {
e.printStackTrace(); throw new java.lang.RuntimeException("XMLStreamException | FileNotFoundException");
// e.printStackTrace();
} finally { } finally {
if (eventReader != null) { if (eventReader != null) {
try { try {
@ -1486,7 +1487,8 @@ public class XML_processing {
LineIterator.closeQuietly(regiIt); LineIterator.closeQuietly(regiIt);
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); throw new java.lang.RuntimeException("IOException");
// e.printStackTrace();
} }
int numLines = 0; int numLines = 0;
@ -1539,7 +1541,7 @@ public class XML_processing {
// beginning tags // beginning tags
// taxonomy // 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("\" "); String[] split = line.split("\" ");
currentFiletaxonomy = new ArrayList<>(); currentFiletaxonomy = new ArrayList<>();

View File

@ -35,12 +35,23 @@ public class Corpus {
private boolean gosOrthMode; private boolean gosOrthMode;
boolean hasMsdData; boolean hasMsdData;
private ArrayList<String> validationErrors; private ArrayList<String> validationErrors;
private String corpusName = "";
public Corpus() { public Corpus() {
validationErrors = new ArrayList<>(); validationErrors = new ArrayList<>();
setTotal(); 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() { public CorpusType getCorpusType() {
return corpusType; return corpusType;
} }

View File

@ -109,34 +109,43 @@ public class StatisticsNew {
if (filter.getAl() == AnalysisLevel.STRING_LEVEL) { if (filter.getAl() == AnalysisLevel.STRING_LEVEL) {
Integer ngramLevel = filter.getNgramValue(); Integer ngramLevel = filter.getNgramValue();
String name = corpus.getCorpusName();
if(ngramLevel == 0) { if(ngramLevel == 0) {
sb.append(corpus.getCorpusType().toString()) if(!name.equals("")) {
.append(separator) sb.append(name)
.append(I18N.get("exportFileName.letters")) .append(separator);
}
sb.append(I18N.get("exportFileName.letters"))
.append(separator) .append(separator)
.append(filter.getCalculateFor()) .append(filter.getCalculateFor())
.append(separator); .append(separator);
} else if(ngramLevel == 1) { } else if(ngramLevel == 1) {
if (filter.getSuffixLength() != null && filter.getSuffixList() != null && filter.getPrefixLength() != null && filter.getPrefixList() != null) { if (filter.getSuffixLength() != null && filter.getSuffixList() != null && filter.getPrefixLength() != null && filter.getPrefixList() != null) {
sb.append(corpus.getCorpusType().toString()) if(!name.equals("")) {
.append(separator) sb.append(name)
.append(I18N.get("exportFileName.wordParts")) .append(separator);
}
sb.append(I18N.get("exportFileName.wordParts"))
.append(separator) .append(separator)
.append(filter.getCalculateFor()) .append(filter.getCalculateFor())
.append(separator); .append(separator);
} else { } else {
sb.append(corpus.getCorpusType().toString()) if(!name.equals("")) {
.append(separator) sb.append(name)
.append(I18N.get("exportFileName.words")) .append(separator);
}
sb.append(I18N.get("exportFileName.words"))
.append(separator) .append(separator)
.append(filter.getCalculateFor()) .append(filter.getCalculateFor())
.append(separator); .append(separator);
} }
} }
else { else {
sb.append(corpus.getCorpusType().toString()) if(!name.equals("")) {
.append(separator) sb.append(name)
.append(I18N.get("exportFileName.wordSets")) .append(separator);
}
sb.append(I18N.get("exportFileName.wordSets"))
.append(separator); .append(separator);
sb.append(filter.getCalculateFor().toString()) sb.append(filter.getCalculateFor().toString())
.append(separator); .append(separator);

View File

@ -11,6 +11,7 @@ import java.lang.reflect.Constructor;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.*; import java.util.*;
import javafx.collections.FXCollections;
import javafx.scene.layout.AnchorPane; import javafx.scene.layout.AnchorPane;
import javafx.util.Duration; import javafx.util.Duration;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
@ -70,6 +71,29 @@ public class CorpusTab {
private Label chooseResultsL; private Label chooseResultsL;
private String chooseResultsLabelContent; 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 @FXML
private ProgressIndicator locationScanPI; private ProgressIndicator locationScanPI;
@ -99,6 +123,11 @@ public class CorpusTab {
private String corpusLocation; private String corpusLocation;
private String corpusFilesSize; 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. * Hack allowing to modify the default behavior of the tooltips.
* @param openDelay The open delay, knowing that by default it is set to 1000. * @param openDelay The open delay, knowing that by default it is set to 1000.
@ -145,6 +174,30 @@ public class CorpusTab {
manageTranslations(); 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 // add listeners
chooseCorpusLocationB.setOnAction(e -> chooseCorpusLocation()); chooseCorpusLocationB.setOnAction(e -> chooseCorpusLocation());
chooseCorpusLocationB.setTooltip(new Tooltip(I18N.get("message.TOOLTIP_chooseCorpusLocationB"))); chooseCorpusLocationB.setTooltip(new Tooltip(I18N.get("message.TOOLTIP_chooseCorpusLocationB")));
@ -206,13 +259,18 @@ public class CorpusTab {
private void manageTranslations(){ private void manageTranslations(){
chooseCorpusLocationB.textProperty().bind(I18N.createStringBinding("button.setCorpusLocation")); chooseCorpusLocationB.textProperty().bind(I18N.createStringBinding("button.setCorpusLocation"));
chooseCorpusLocationL.textProperty().bind(I18N.createStringBinding("label.setCorpusLocation"));
readHeaderInfoChB.textProperty().bind(I18N.createStringBinding("checkBox.readHeaderInfo")); readHeaderInfoChB.textProperty().bind(I18N.createStringBinding("checkBox.readHeaderInfo"));
chooseResultsLocationB.textProperty().bind(I18N.createStringBinding("button.chooseResultsLocation")); chooseResultsLocationB.textProperty().bind(I18N.createStringBinding("button.chooseResultsLocation"));
chooseResultsLocationL.textProperty().bind(I18N.createStringBinding("label.chooseResultsLocation"));
helpH.textProperty().bind(I18N.createStringBinding("hyperlink.help")); helpH.textProperty().bind(I18N.createStringBinding("hyperlink.help"));
changeLanguageB.textProperty().bind(I18N.createStringBinding("button.language")); changeLanguageB.textProperty().bind(I18N.createStringBinding("button.language"));
chooseCorpusL.textProperty().bind(I18N.createStringBinding("message.LABEL_CORPUS_LOCATION_NOT_SET")); chooseCorpusL.textProperty().bind(I18N.createStringBinding("message.LABEL_CORPUS_LOCATION_NOT_SET"));
chooseResultsL.textProperty().bind(I18N.createStringBinding("message.LABEL_RESULTS_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) { private void togglePiAndSetCorpusWrapper(boolean piIsActive) {
@ -238,15 +296,20 @@ public class CorpusTab {
* has to produce a non-empty list results list * has to produce a non-empty list results list
*/ */
private void chooseCorpusLocation() { private void chooseCorpusLocation() {
File selectedDirectory = directoryChooser(); selectedDirectory = directoryChooser();
if (selectedDirectory != null && ValidationUtil.isReadableDirectory(selectedDirectory)) { if (selectedDirectory != null && ValidationUtil.isReadableDirectory(selectedDirectory)) {
logger.info("selected corpus dir: ", selectedDirectory.getAbsolutePath()); logger.info("selected corpus dir: ", selectedDirectory.getAbsolutePath());
// scan for xml files // 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();
}
}
private void changeCorpus(){
// make sure there are corpus files in selected directory or notify the user about it // make sure there are corpus files in selected directory or notify the user about it
if (corpusFiles.size() == 0) { if (corpusFiles.size() == 0) {
// try .vert // try .vert
@ -267,7 +330,7 @@ public class CorpusTab {
corpusLocation = selectedDirectory.getAbsolutePath(); corpusLocation = selectedDirectory.getAbsolutePath();
corpusFilesSize = String.valueOf(corpusFiles.size()); corpusFilesSize = String.valueOf(corpusFiles.size());
Messages.setChooseCorpusProperties(corpusLocation, corpusFilesSize, corpusType != null ? corpusType.toString() : null); Messages.setChooseCorpusProperties(corpusLocation, corpusFilesSize, corpusType != null ? corpusType.toString() : null);
corpusType = VERT; // corpusType = VERT;
corpus.setCorpusType(corpusType); corpus.setCorpusType(corpusType);
@ -303,11 +366,22 @@ public class CorpusTab {
} }
} else { } else {
System.out.println(corpusLocation);
corpusLocation = selectedDirectory.getAbsolutePath(); corpusLocation = selectedDirectory.getAbsolutePath();
corpusFilesSize = String.valueOf(corpusFiles.size()); corpusFilesSize = String.valueOf(corpusFiles.size());
Messages.setChooseCorpusProperties(corpusLocation, corpusFilesSize, corpusType != null ? corpusType.toString() : null); Messages.setChooseCorpusProperties(corpusLocation, corpusFilesSize, corpusType != null ? corpusType.toString() : null);
String chooseCorpusLabelContentTmp = detectCorpusType(corpusFiles); // 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);
if (chooseCorpusLabelContentTmp == null) { if (chooseCorpusLabelContentTmp == null) {
logger.info("alert: ", I18N.get("message.WARNING_CORPUS_NOT_FOUND")); logger.info("alert: ", I18N.get("message.WARNING_CORPUS_NOT_FOUND"));
@ -332,7 +406,7 @@ public class CorpusTab {
} }
} }
} }
} corpus.setCorpusName(outputName);
} }
/** /**
@ -661,6 +735,36 @@ public class CorpusTab {
// gosUseOrthChB.setVisible(corpus != null && corpus.getCorpusType() != null && corpus.getCorpusType() == CorpusType.GOS); // 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) { private String detectCorpusType(Collection<File> corpusFiles) {
// check that we recognize this corpus // check that we recognize this corpus
// read first file only, maybe later do all, if toll on resources is acceptable // read first file only, maybe later do all, if toll on resources is acceptable

View File

@ -8,12 +8,15 @@
<?import javafx.scene.layout.AnchorPane?> <?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.Pane?> <?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" <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"> fx:controller="gui.CorpusTab">
<children> <children>
<Pane/> <Pane/>
<Button fx:id="chooseCorpusLocationB" layoutX="10.0" layoutY="20.0" mnemonicParsing="false"/> <!--<TextField fx:id="stringLengthTF" layoutX="225.0" layoutY="20.0" prefWidth="140.0" />-->
<CheckBox fx:id="readHeaderInfoChB" layoutX="185.0" layoutY="24.0" mnemonicParsing="false"/> <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"> <Pane fx:id="setCorpusWrapperP" layoutX="10.0" layoutY="60.0" prefHeight="118.0" prefWidth="683.0">
<children> <children>
<Label fx:id="chooseCorpusL" prefHeight="70.0" prefWidth="704.0" text="Label"/> <Label fx:id="chooseCorpusL" prefHeight="70.0" prefWidth="704.0" text="Label"/>
@ -21,9 +24,21 @@
</children> </children>
</Pane> </Pane>
<ProgressIndicator fx:id="locationScanPI" layoutX="10.0" layoutY="60.0" prefHeight="50.0" progress="0.0"/> <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="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"/> <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"/> <Button fx:id="changeLanguageB" layoutX="710.0" layoutY="40.0" mnemonicParsing="false" prefWidth="50.0"/>
</children> </children>

View File

@ -15,9 +15,14 @@ tab.oneWordAnalysisTab=Words
tab.stringLevelTabNew2=Word sets tab.stringLevelTabNew2=Word sets
# corpus tab # 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 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 # character analysis tab
label.stringLength=Number of letters label.stringLength=Number of letters

View File

@ -15,9 +15,14 @@ tab.oneWordAnalysisTab=Besede
tab.stringLevelTabNew2=Besedni nizi tab.stringLevelTabNew2=Besedni nizi
# corpus tab # 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 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 # character analysis tab
label.stringLength=Dolžina črkovnih nizov label.stringLength=Dolžina črkovnih nizov