You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
206 lines
5.7 KiB
206 lines
5.7 KiB
package data;
|
|
|
|
import static gui.Messages.*;
|
|
|
|
import java.io.File;
|
|
import java.util.ArrayList;
|
|
import java.util.Collection;
|
|
import java.util.HashMap;
|
|
import java.util.HashSet;
|
|
|
|
import gui.I18N;
|
|
import javafx.collections.FXCollections;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.logging.log4j.LogManager;
|
|
import org.apache.logging.log4j.Logger;
|
|
|
|
import data.Enums.solar.SolarFilters;
|
|
import gui.ValidationUtil;
|
|
import javafx.collections.ObservableList;
|
|
import org.controlsfx.control.CheckComboBox;
|
|
|
|
public class Corpus {
|
|
public final static Logger logger = LogManager.getLogger(Corpus.class);
|
|
|
|
private CorpusType corpusType;
|
|
private File chosenResultsLocation;
|
|
private File chosenCorpusLocation;
|
|
private Collection<File> detectedCorpusFiles;
|
|
boolean headerRead;
|
|
private ArrayList<Taxonomy> taxonomy; // if gigafida or gos
|
|
private Taxonomy taxonomyTotal;
|
|
private HashMap<String, ObservableList<String>> solarFilters; // if solar
|
|
public HashMap<String, ObservableList<String>> solarSelectedFilters; // if solar selected
|
|
private HashMap<String, HashSet<String>> solarFiltersForXML; // if solar - used while parsing xml
|
|
private boolean gosOrthMode;
|
|
boolean hasMsdData;
|
|
private ArrayList<String> validationErrors;
|
|
|
|
public Corpus() {
|
|
validationErrors = new ArrayList<>();
|
|
setTotal();
|
|
}
|
|
|
|
public CorpusType getCorpusType() {
|
|
return corpusType;
|
|
}
|
|
|
|
public void setCorpusType(CorpusType corpusType) {
|
|
this.corpusType = corpusType;
|
|
logger.info("Corpus.set: ", corpusType);
|
|
}
|
|
|
|
public File getChosenResultsLocation() {
|
|
return chosenResultsLocation;
|
|
}
|
|
|
|
public void setChosenResultsLocation(File chosenResultsLocation) {
|
|
this.chosenResultsLocation = chosenResultsLocation;
|
|
logger.info("Corpus.set: ", chosenResultsLocation);
|
|
}
|
|
|
|
public File getChosenCorpusLocation() {
|
|
return chosenCorpusLocation;
|
|
}
|
|
|
|
public void setChosenCorpusLocation(File chosenCorpusLocation) {
|
|
this.chosenCorpusLocation = chosenCorpusLocation;
|
|
logger.info("Corpus.set: ", chosenCorpusLocation);
|
|
}
|
|
|
|
public Collection<File> getDetectedCorpusFiles() {
|
|
return detectedCorpusFiles;
|
|
}
|
|
|
|
public void setDetectedCorpusFiles(Collection<File> detectedCorpusFiles) {
|
|
this.detectedCorpusFiles = detectedCorpusFiles;
|
|
logger.info("Corpus.set: ", detectedCorpusFiles);
|
|
}
|
|
|
|
public boolean isHeaderRead() {
|
|
return headerRead;
|
|
}
|
|
|
|
public void setHeaderRead(boolean headerRead) {
|
|
this.headerRead = headerRead;
|
|
}
|
|
|
|
public Taxonomy getTotal() {
|
|
return taxonomyTotal;
|
|
}
|
|
|
|
public void setTotal() {
|
|
taxonomyTotal = new Taxonomy("Total", false);
|
|
}
|
|
|
|
public ArrayList<Taxonomy> getTaxonomy() {
|
|
return taxonomy;
|
|
}
|
|
|
|
public ObservableList<String> getObservableListTaxonomy() {
|
|
ArrayList<String> al = new ArrayList<>();
|
|
if(taxonomy != null) {
|
|
for (Taxonomy t : this.taxonomy) {
|
|
al.add(t.toLongNameString());
|
|
}
|
|
}
|
|
return FXCollections.observableArrayList(al);
|
|
}
|
|
//
|
|
// public ObservableList<String> getFormattedTaxonomy() {
|
|
// ArrayList<String> al = Tax.getTaxonomyFormatted(new ArrayList<>(taxonomy), corpusType);
|
|
// return FXCollections.observableArrayList(al);
|
|
// }
|
|
|
|
public void setTaxonomy(ObservableList<String> taxonomy) {
|
|
this.taxonomy = new ArrayList<>();
|
|
for(String t : taxonomy){
|
|
this.taxonomy.add(new Taxonomy(t, true));
|
|
}
|
|
logger.info("Corpus.set: ", taxonomy);
|
|
}
|
|
|
|
public HashMap<String, ObservableList<String>> getSolarFilters() {
|
|
return solarFilters;
|
|
}
|
|
|
|
public void setSolarFilters(HashMap<String, ObservableList<String>> solarFilters) {
|
|
this.solarFilters = solarFilters;
|
|
logger.info("Corpus.set: ", solarFilters);
|
|
}
|
|
|
|
public HashMap<String, ObservableList<String>> getSolarSelectedFilters() {
|
|
return solarSelectedFilters;
|
|
}
|
|
|
|
public void setSolarSelectedFilters(HashMap<String, ObservableList<String>> solarFilters) {
|
|
this.solarSelectedFilters = solarFilters;
|
|
logger.info("Corpus.set: ", solarFilters);
|
|
}
|
|
|
|
public HashMap<String, HashSet<String>> getSolarFiltersForXML() {
|
|
return solarFiltersForXML;
|
|
}
|
|
|
|
public void setSolarFiltersForXML(HashMap<String, HashSet<String>> solarFiltersForXML) {
|
|
this.solarFiltersForXML = solarFiltersForXML;
|
|
logger.info("Corpus.set: ", solarFiltersForXML);
|
|
}
|
|
|
|
public boolean isGosOrthMode() {
|
|
return gosOrthMode;
|
|
}
|
|
|
|
public void setGosOrthMode(boolean gosOrthMode) {
|
|
this.gosOrthMode = gosOrthMode;
|
|
logger.info("Corpus.set: ", gosOrthMode);
|
|
}
|
|
|
|
public ArrayList<String> getValidationErrors() {
|
|
return validationErrors;
|
|
}
|
|
|
|
public String getValidationErrorsToString() {
|
|
return StringUtils.join(validationErrors, "\n - ");
|
|
}
|
|
|
|
public void setValidationErrors(ArrayList<String> validationErrors) {
|
|
this.validationErrors = validationErrors;
|
|
}
|
|
|
|
public boolean validate() {
|
|
if (corpusType == null) {
|
|
validationErrors.add(I18N.get("message.LABEL_RESULTS_CORPUS_TYPE_NOT_SET"));
|
|
}
|
|
|
|
if (chosenCorpusLocation == null) {
|
|
validationErrors.add(I18N.get("message.LABEL_CORPUS_LOCATION_NOT_SET"));
|
|
}
|
|
|
|
if (chosenResultsLocation == null) {
|
|
validationErrors.add(I18N.get("message.LABEL_RESULTS_LOCATION_NOT_SET"));
|
|
}
|
|
|
|
if (!headerRead && corpusType != null) {
|
|
// if user didn't opt into reading the headers, set default taxonomy or solar filters
|
|
if (Tax.getCorpusTypesWithTaxonomy().contains(corpusType)) {
|
|
Tax.getTaxonomyForComboBox(corpusType);
|
|
setTaxonomy(Tax.getTaxonomyForComboBox(corpusType));
|
|
} else if (corpusType == CorpusType.SOLAR && solarFilters == null) {
|
|
setSolarFilters(SolarFilters.getFiltersForComboBoxes());
|
|
}
|
|
}
|
|
|
|
if (headerRead && ValidationUtil.isEmpty(taxonomy)) {
|
|
// mustn't happen, intercept at gui level
|
|
}
|
|
|
|
if (!ValidationUtil.isEmpty(validationErrors)) {
|
|
logger.error("Corpus validation error: ", StringUtils.join(validationErrors, "\n - "));
|
|
return false;
|
|
} else {
|
|
return true;
|
|
}
|
|
}
|
|
}
|