Added functional additional combinational filters for words
This commit is contained in:
@@ -24,7 +24,8 @@ public class Filter {
|
||||
TAXONOMY,
|
||||
MSD,
|
||||
HAS_MSD,
|
||||
SOLAR_FILTERS
|
||||
SOLAR_FILTERS,
|
||||
MULTIPLE_KEYS
|
||||
}
|
||||
|
||||
public Filter() {
|
||||
@@ -141,4 +142,23 @@ public class Filter {
|
||||
public HashMap<String, HashSet<String>> getSolarFilters() {
|
||||
return (HashMap<String, HashSet<String>>) filter.get(SOLAR_FILTERS);
|
||||
}
|
||||
|
||||
public void setMultipleKeys(ArrayList<String> keys) {
|
||||
ArrayList<CalculateFor> newKeys = new ArrayList<>();
|
||||
if (keys != null) {
|
||||
for (String key : keys) {
|
||||
newKeys.add(CalculateFor.factory(key));
|
||||
}
|
||||
}
|
||||
|
||||
filter.put(MULTIPLE_KEYS, newKeys);
|
||||
}
|
||||
|
||||
public ArrayList<CalculateFor> getMultipleKeys() {
|
||||
if (filter.containsKey(MULTIPLE_KEYS) && filter.get(MULTIPLE_KEYS) != null) {
|
||||
return (ArrayList<CalculateFor>) filter.get(MULTIPLE_KEYS);
|
||||
} else {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,48 +2,54 @@ 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 final class MultipleHMKeys {
|
||||
private final String key, lemma, wordType, msd;
|
||||
|
||||
public MultipleHMKeys(String key1) {
|
||||
this.key1 = key1;
|
||||
this.key2 = null;
|
||||
this.key3 = null;
|
||||
public MultipleHMKeys(String key) {
|
||||
this.key = key;
|
||||
this.lemma = "";
|
||||
this.wordType = "";
|
||||
this.msd = "";
|
||||
}
|
||||
|
||||
public MultipleHMKeys(String key1, String key2) {
|
||||
this.key1 = key1;
|
||||
this.key2 = key2;
|
||||
this.key3 = null;
|
||||
public MultipleHMKeys(String key, String lemma, String wordType, String msd) {
|
||||
this.key = key;
|
||||
this.lemma = lemma;
|
||||
this.wordType = wordType;
|
||||
this.msd = msd;
|
||||
}
|
||||
|
||||
public MultipleHMKeys(String key1, String key2, String key3) {
|
||||
this.key1 = key1;
|
||||
this.key2 = key2;
|
||||
this.key3 = key3;
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public String getKey1() {
|
||||
return key1;
|
||||
public String getLemma() {
|
||||
return lemma;
|
||||
}
|
||||
|
||||
public String getKey2() {
|
||||
return key2;
|
||||
public String getWordType() {
|
||||
return wordType;
|
||||
}
|
||||
|
||||
public String getKey3() {
|
||||
return key3;
|
||||
public String getMsd() {
|
||||
return msd;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return key1.hashCode() ^ key2.hashCode() ^ key3.hashCode();
|
||||
// if(key2 == null){
|
||||
// return key1.hashCode();
|
||||
// } else if (key3 == null){
|
||||
// return key1.hashCode() ^ key2.hashCode();
|
||||
// }
|
||||
return key.hashCode() ^ lemma.hashCode() ^ wordType.hashCode() ^ msd.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);
|
||||
return (obj instanceof MultipleHMKeys) && ((MultipleHMKeys) obj).key.equals(key)
|
||||
&& ((MultipleHMKeys) obj).lemma.equals(lemma)
|
||||
&& ((MultipleHMKeys) obj).wordType.equals(wordType)
|
||||
&& ((MultipleHMKeys) obj).msd.equals(msd);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -222,7 +222,7 @@ public class Statistics {
|
||||
// return sortedM;
|
||||
// }
|
||||
|
||||
private Map<String, Long> getSortedResult(Map<String, AtomicLong> map, int limit) {
|
||||
private Map<MultipleHMKeys, Long> getSortedResult(Map<MultipleHMKeys, AtomicLong> map, int limit) {
|
||||
return Util.sortByValue(Util.atomicInt2StringAndInt(map), limit);
|
||||
}
|
||||
|
||||
|
||||
@@ -32,10 +32,10 @@ public class StatisticsNew {
|
||||
|
||||
private String resultTitle;
|
||||
private Map<String, AtomicLong> result;
|
||||
private Map<String, Map<String, AtomicLong>> taxonomyResult;
|
||||
private Map<String, Map<MultipleHMKeys, AtomicLong>> taxonomyResult;
|
||||
private Object[][] resultCustom; // for when calculating percentages that don't add up to 100%
|
||||
private Map<String, ConcurrentHashMap<String, AtomicLong>> resultNestedSuffix;
|
||||
private Map<String, ConcurrentHashMap<String, AtomicLong>> resultNestedPrefix;
|
||||
private Map<String, ConcurrentHashMap<MultipleHMKeys, AtomicLong>> resultNestedSuffix;
|
||||
private Map<String, ConcurrentHashMap<MultipleHMKeys, AtomicLong>> resultNestedPrefix;
|
||||
private boolean useDB;
|
||||
private RDB db;
|
||||
private boolean analysisProducedResults;
|
||||
@@ -194,7 +194,7 @@ public class StatisticsNew {
|
||||
}
|
||||
|
||||
public boolean saveResultToDisk(int... limit) throws UnsupportedEncodingException {
|
||||
Set<Pair<String, Map<String, Long>>> stats = new HashSet<>();
|
||||
Set<Pair<String, Map<MultipleHMKeys, Long>>> stats = new HashSet<>();
|
||||
|
||||
if (useDB) {
|
||||
result = db.getDump();
|
||||
@@ -223,13 +223,14 @@ public class StatisticsNew {
|
||||
}
|
||||
Map<WordLevelType, Map<String, Map<String, Long>>> results = new HashMap<>();
|
||||
|
||||
if (!isEmpty(resultNestedSuffix)) {
|
||||
results.put(WordLevelType.SUFFIX, sortNestedMap(resultNestedSuffix, Util.getValidInt(limit)));
|
||||
}
|
||||
|
||||
if (!isEmpty(resultNestedPrefix)) {
|
||||
results.put(WordLevelType.PREFIX, sortNestedMap(resultNestedPrefix, Util.getValidInt(limit)));
|
||||
}
|
||||
// UNCOMMENT!!!!!!
|
||||
// if (!isEmpty(resultNestedSuffix)) {
|
||||
// results.put(WordLevelType.SUFFIX, sortNestedMap(resultNestedSuffix, Util.getValidInt(limit)));
|
||||
// }
|
||||
//
|
||||
// if (!isEmpty(resultNestedPrefix)) {
|
||||
// results.put(WordLevelType.PREFIX, sortNestedMap(resultNestedPrefix, Util.getValidInt(limit)));
|
||||
// }
|
||||
|
||||
// if no results and nothing to save, return false
|
||||
if (!(results.size() > 0)) {
|
||||
@@ -266,8 +267,8 @@ public class StatisticsNew {
|
||||
return true;
|
||||
}
|
||||
|
||||
private Map<String, Map<String, Long>> sortNestedMap(Map<String, ConcurrentHashMap<String, AtomicLong>> nestedMap, int limit) {
|
||||
Map<String, Map<String, Long>> sorted = new HashMap<>();
|
||||
private Map<String, Map<MultipleHMKeys, Long>> sortNestedMap(Map<String, ConcurrentHashMap<MultipleHMKeys, AtomicLong>> nestedMap, int limit) {
|
||||
Map<String, Map<MultipleHMKeys, Long>> sorted = new HashMap<>();
|
||||
|
||||
for (String s : nestedMap.keySet()) {
|
||||
sorted.put(s, getSortedResult(nestedMap.get(s), Util.getValidInt(limit)));
|
||||
@@ -277,11 +278,11 @@ public class StatisticsNew {
|
||||
}
|
||||
|
||||
|
||||
private Map<String, Long> getSortedResult(Map<String, AtomicLong> map, int limit) {
|
||||
private Map<MultipleHMKeys, Long> getSortedResult(Map<MultipleHMKeys, AtomicLong> map, int limit) {
|
||||
return Util.sortByValue(Util.atomicInt2StringAndInt(map), limit);
|
||||
}
|
||||
|
||||
public void updateTaxonomyResults(String o, List<String> taxonomy) {
|
||||
public void updateTaxonomyResults(MultipleHMKeys o, List<String> taxonomy) {
|
||||
for (String key : taxonomyResult.keySet()) {
|
||||
// first word should have the same taxonomy as others
|
||||
if (taxonomy.contains(key) || key.equals("Total")) {
|
||||
@@ -335,9 +336,11 @@ public class StatisticsNew {
|
||||
}
|
||||
|
||||
public void updateResultsNestedSuffix(String key, String stringValue) {
|
||||
MultipleHMKeys mkStringValue = new MultipleHMKeys(stringValue);
|
||||
|
||||
if (resultNestedSuffix.containsKey(key)) {
|
||||
// if not in map
|
||||
AtomicLong r = resultNestedSuffix.get(key).putIfAbsent(stringValue, new AtomicLong(1));
|
||||
AtomicLong r = resultNestedSuffix.get(key).putIfAbsent(mkStringValue, new AtomicLong(1));
|
||||
|
||||
// else
|
||||
if (r != null) {
|
||||
@@ -345,7 +348,7 @@ public class StatisticsNew {
|
||||
}
|
||||
} else {
|
||||
resultNestedSuffix.putIfAbsent(key, new ConcurrentHashMap<>());
|
||||
AtomicLong r = resultNestedSuffix.get(key).putIfAbsent(stringValue, new AtomicLong(1));
|
||||
AtomicLong r = resultNestedSuffix.get(key).putIfAbsent(mkStringValue, new AtomicLong(1));
|
||||
|
||||
if (r != null) {
|
||||
resultNestedSuffix.get(key).get(stringValue).incrementAndGet();
|
||||
@@ -354,9 +357,11 @@ public class StatisticsNew {
|
||||
}
|
||||
|
||||
public void updateResultsNestedPrefix(String key, String stringValue) {
|
||||
MultipleHMKeys mkStringValue = new MultipleHMKeys(stringValue);
|
||||
|
||||
if (resultNestedPrefix.containsKey(key)) {
|
||||
// if not in map
|
||||
AtomicLong r = resultNestedPrefix.get(key).putIfAbsent(stringValue, new AtomicLong(1));
|
||||
AtomicLong r = resultNestedPrefix.get(key).putIfAbsent(mkStringValue, new AtomicLong(1));
|
||||
|
||||
// else
|
||||
if (r != null) {
|
||||
@@ -364,7 +369,7 @@ public class StatisticsNew {
|
||||
}
|
||||
} else {
|
||||
resultNestedPrefix.putIfAbsent(key, new ConcurrentHashMap<>());
|
||||
AtomicLong r = resultNestedPrefix.get(key).putIfAbsent(stringValue, new AtomicLong(1));
|
||||
AtomicLong r = resultNestedPrefix.get(key).putIfAbsent(mkStringValue, new AtomicLong(1));
|
||||
|
||||
if (r != null) {
|
||||
resultNestedPrefix.get(key).get(stringValue).incrementAndGet();
|
||||
|
||||
Reference in New Issue
Block a user