Refactored results - moved to taxonomyResults

This commit is contained in:
2018-07-05 09:37:35 +02:00
parent 8d7cce6c77
commit e2ce656fc5
8 changed files with 87 additions and 25 deletions

View File

@@ -0,0 +1,49 @@
package data;
/*
Created for when words are sorted by multiple keys, i.e. not just lemmas but lemmas and msd simultaneously.
*/
final class MultipleHMKeys {
private final String key1, key2, key3;
public MultipleHMKeys(String key1) {
this.key1 = key1;
this.key2 = null;
this.key3 = null;
}
public MultipleHMKeys(String key1, String key2) {
this.key1 = key1;
this.key2 = key2;
this.key3 = null;
}
public MultipleHMKeys(String key1, String key2, String key3) {
this.key1 = key1;
this.key2 = key2;
this.key3 = key3;
}
public String getKey1() {
return key1;
}
public String getKey2() {
return key2;
}
public String getKey3() {
return key3;
}
@Override
public int hashCode() {
return key1.hashCode() ^ key2.hashCode() ^ key3.hashCode();
}
@Override
public boolean equals(Object obj) {
return (obj instanceof MultipleHMKeys) && ((MultipleHMKeys) obj).key1.equals(key1)
&& ((MultipleHMKeys) obj).key2.equals(key2)
&& ((MultipleHMKeys) obj).key3.equals(key3);
}
}

View File

@@ -45,6 +45,7 @@ public class StatisticsNew {
this.corpus = corpus;
this.filter = filter;
this.taxonomyResult = new ConcurrentHashMap<>();
this.taxonomyResult.put("Total", new ConcurrentHashMap<>());
// create table for counting word occurances per taxonomies
@@ -97,13 +98,18 @@ public class StatisticsNew {
if (filter.getAl() == AnalysisLevel.STRING_LEVEL) {
Integer ngramLevel = filter.getNgramValue();
if(ngramLevel == 0) {
sb.append("Crke").
append(separator)
.append(corpus.getCorpusType().toString())
sb.append(corpus.getCorpusType().toString())
.append(separator)
.append("crke")
.append(separator)
.append(filter.getCalculateFor())
.append(separator);
} else if(ngramLevel == 1) {
sb.append("Besede").append(separator)
.append(corpus.getCorpusType().toString())
sb.append(corpus.getCorpusType().toString())
.append(separator)
.append("besede")
.append(separator)
.append(filter.getCalculateFor())
.append(separator);
}
else {
@@ -196,14 +202,14 @@ public class StatisticsNew {
}
// if no results and nothing to save, return false
if (!(result.size() > 0)) {
if (!(taxonomyResult.get("Total").size() > 0)) {
analysisProducedResults = false;
return false;
} else {
analysisProducedResults = true;
}
stats.add(ImmutablePair.of(resultTitle, getSortedResult(result, Util.getValidInt(limit))));
stats.add(ImmutablePair.of(resultTitle, getSortedResult(taxonomyResult.get("Total"), Util.getValidInt(limit))));
Export.SetToCSV(stats, corpus.getChosenResultsLocation(), headerInfoBlock(), taxonomyResult);
return true;
}
@@ -275,10 +281,10 @@ public class StatisticsNew {
return Util.sortByValue(Util.atomicInt2StringAndInt(map), limit);
}
public void updateTaxonomyResults(String o, List<Word> ngramCandidate) {
public void updateTaxonomyResults(String o, List<String> taxonomy) {
for (String key : taxonomyResult.keySet()) {
// first word should have the same taxonomy as others
if (ngramCandidate.get(0).getTaxonomy().contains(key)) {
if (taxonomy.contains(key) || key.equals("Total")) {
// if taxonomy not in map and in this word
AtomicLong r = taxonomyResult.get(key).putIfAbsent(o, new AtomicLong(1));

View File

@@ -55,7 +55,8 @@ public class Word implements Serializable {
//private char besedna_vrsta;
public Word(String word, String lemma, String msd, List<String> taxonomy) {
this.lemma = lemma;
this.msd = normalizeMsd(msd);
// this.msd = normalizeMsd(msd);
this.msd = msd;
this.taxonomy = taxonomy;
// veliko zacetnico ohranimo samo za lastna imena