85 lines
3.3 KiB
Java
85 lines
3.3 KiB
Java
package nogui;
|
|
|
|
import data.*;
|
|
import gui.GUIController;
|
|
import gui.I18N;
|
|
import javafx.concurrent.Task;
|
|
import org.apache.logging.log4j.LogManager;
|
|
import org.apache.logging.log4j.Logger;
|
|
import org.json.simple.JSONArray;
|
|
import org.json.simple.JSONObject;
|
|
import util.Tasks;
|
|
|
|
import java.io.UnsupportedEncodingException;
|
|
import java.util.ArrayList;
|
|
import java.util.regex.Pattern;
|
|
|
|
import static nogui.Utils.*;
|
|
import static nogui.Utils.getTaxonomy;
|
|
|
|
public class Words {
|
|
public final static Logger logger = LogManager.getLogger(GUIController.class);
|
|
|
|
public static void words(JSONObject settings, Corpus corpus) {
|
|
Filter filter = new Filter();
|
|
// fixed values
|
|
filter.setNgramValue(1);
|
|
filter.setAl(AnalysisLevel.STRING_LEVEL);
|
|
filter.setSkipValue(0);
|
|
filter.setIsCvv(false);
|
|
filter.setStringLength(1);
|
|
|
|
// tab specific values
|
|
filter.setNotePunctuations((boolean) settings.get("notePunctuations"));
|
|
filter.setWriteMsdAtTheEnd((boolean) settings.get("writeMsdAtTheEnd"));
|
|
|
|
String calculateForString = (String) settings.get("calculateFor");
|
|
CalculateFor calculateFor = CalculateFor.factory(I18N.get(calculateForString));
|
|
filter.setCalculateFor(calculateFor);
|
|
ArrayList<String> alsoVisualize = getAlsoVisualizeList((JSONArray) settings.get("alsoVisualize"));
|
|
filter.setMultipleKeys(alsoVisualize);
|
|
filter.setDisplayTaxonomy((boolean) settings.get("displayTaxonomy"));
|
|
filter.setMinimalRelFre(Math.toIntExact((Long) settings.get("minimalRelFre")));
|
|
|
|
|
|
// right part
|
|
ArrayList<Pattern> msd = getMsd((String) settings.get("msd"));
|
|
filter.setMsd(msd);
|
|
filter.setTaxonomySetOperation(I18N.get((String) settings.get("taxonomySetOperation")));
|
|
ArrayList<Taxonomy> taxonomy = getTaxonomy((JSONArray) settings.get("taxonomy"), corpus);
|
|
filter.setTaxonomy(taxonomy);
|
|
filter.setMinimalOccurrences(Math.toIntExact((Long) settings.get("minimalOccurrences")));
|
|
filter.setMinimalTaxonomy(Math.toIntExact((Long) settings.get("minimalTaxonomy")));
|
|
|
|
String message = Validation.validateForStringLevel(filter);
|
|
if (message == null) {
|
|
// no errors
|
|
logger.info("Executing: ", filter.toString());
|
|
StatisticsNew statistic = new StatisticsNew(corpus, filter, false);
|
|
execute(statistic, corpus);
|
|
try {
|
|
boolean successullySaved = statistic.saveResultToDisk();
|
|
if (successullySaved) {
|
|
logger.info(I18N.get("message.NOTIFICATION_ANALYSIS_COMPLETED"));
|
|
} else {
|
|
logger.info(I18N.get("message.NOTIFICATION_ANALYSIS_COMPLETED_NO_RESULTS"));
|
|
}
|
|
} catch (UnsupportedEncodingException e1) {
|
|
logger.error(I18N.get("message.ERROR_WHILE_SAVING_RESULTS_TO_CSV"));
|
|
}
|
|
} else {
|
|
logger.error(message);
|
|
}
|
|
}
|
|
|
|
private static void execute(StatisticsNew statistic, Corpus corpus) {
|
|
logger.info("Started execution: ", statistic.getFilter());
|
|
|
|
if (statistic.getFilter().getMinimalRelFre() > 1){
|
|
prepareTaskForMinRelFre(statistic, corpus);
|
|
} else {
|
|
prepareMainTask(statistic, corpus);
|
|
}
|
|
}
|
|
}
|