Added some performance measures

This commit is contained in:
2018-08-09 09:21:06 +02:00
parent 179f09c4bd
commit 9b5fa4616b
24 changed files with 734 additions and 379 deletions

View File

@@ -9,6 +9,7 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicLong;
import data.CalculateFor;
import data.Filter;
import data.MultipleHMKeys;
import org.apache.commons.csv.CSVFormat;
@@ -59,7 +60,7 @@ public class Export {
}
public static String SetToCSV(Set<Pair<String, Map<MultipleHMKeys, Long>>> set, File resultsPath, LinkedHashMap<String, String> headerInfoBlock,
Map<String, Map<MultipleHMKeys, AtomicLong>> taxonomyResults) {
Map<String, Map<MultipleHMKeys, AtomicLong>> taxonomyResults, Filter filter) {
//Delimiter used in CSV file
String NEW_LINE_SEPARATOR = "\n";
List<Object> FILE_HEADER_AL = new ArrayList<Object>();
@@ -98,8 +99,10 @@ public class Export {
headerInfoBlock.put("Skupna vsota vseh lem:", String.valueOf(num_frequencies));
if (headerInfoBlock.get("Analiza").equals("Besede")){
FILE_HEADER_AL.add("Lema");
FILE_HEADER_AL.add("Lema male črke");
} else if (headerInfoBlock.get("Analiza").equals("Besedni nizi")) {
FILE_HEADER_AL.add("Leme");
FILE_HEADER_AL.add("Leme male črke");
}
} else if (headerInfoBlock.containsKey("Izračunaj za:") && headerInfoBlock.get("Izračunaj za:").equals("oblikoskladenjska oznaka")) {
headerInfoBlock.put("Skupna vsota vseh oblikoskladenjskih oznak:", String.valueOf(num_frequencies));
@@ -111,25 +114,26 @@ public class Export {
} else {
headerInfoBlock.put("Skupna vsota vseh različnic:", String.valueOf(num_frequencies));
FILE_HEADER_AL.add("Lema");
FILE_HEADER_AL.add("Lema male črke");
}
for (Map<MultipleHMKeys, AtomicLong> value : taxonomyResults.values()) {
for (MultipleHMKeys key : value.keySet()){
if(!key.getLemma().equals("")){
// for (Map<MultipleHMKeys, AtomicLong> value : taxonomyResults.values()) {
for (CalculateFor otherKey : filter.getMultipleKeys()){
if(otherKey.equals(CalculateFor.LEMMA)){
FILE_HEADER_AL.add("Lema");
FILE_HEADER_AL.add("Lema male črke");
}
if(!key.getWordType().equals("")){
if(otherKey.equals(CalculateFor.WORD_TYPE)){
FILE_HEADER_AL.add("Besedna vrsta");
}
if(!key.getMsd().equals("")){
if(otherKey.equals(CalculateFor.MORPHOSYNTACTIC_SPECS)){
FILE_HEADER_AL.add("Oblikoskladenjska oznaka");
}
break;
}
break;
}
// break;
// }
@@ -198,16 +202,47 @@ public class Export {
for (Map.Entry<MultipleHMKeys, Long> e : map.entrySet()) {
List dataEntry = new ArrayList<>();
dataEntry.add(e.getKey().getKey());
if(!e.getKey().getLemma().equals("")){
dataEntry.add(e.getKey().getLemma());
}
if(!e.getKey().getWordType().equals("")){
dataEntry.add(e.getKey().getWordType());
}
if(!e.getKey().getMsd().equals("")){
dataEntry.add(e.getKey().getMsd());
dataEntry.add(e.getKey().getK1());
if (headerInfoBlock.containsKey("Analiza") && (headerInfoBlock.get("Analiza").equals("Besede") || headerInfoBlock.get("Analiza").equals("Besedni nizi")) &&
headerInfoBlock.containsKey("Izračunaj za:") && headerInfoBlock.get("Izračunaj za:").equals("lema")){
dataEntry.add(e.getKey().getK1().toLowerCase());
}
int i = 0;
for (CalculateFor otherKey : filter.getMultipleKeys()){
switch(i){
case 0:
if (otherKey.equals(CalculateFor.LEMMA)){
dataEntry.add(e.getKey().getK2());
dataEntry.add(e.getKey().getK2().toLowerCase());
} else {
dataEntry.add(e.getKey().getK2());
}
break;
case 1:
dataEntry.add(e.getKey().getK3());
break;
case 2:
dataEntry.add(e.getKey().getK4());
break;
case 3:
dataEntry.add(e.getKey().getK5());
break;
}
i++;
}
// if(!e.getKey().getLemma().equals("")){
// dataEntry.add(e.getKey().getLemma());
// dataEntry.add(e.getKey().getLemma().toLowerCase());
// }
// if(!e.getKey().getWordType().equals("")){
// dataEntry.add(e.getKey().getWordType());
// }
// if(!e.getKey().getMsd().equals("")){
// dataEntry.add(e.getKey().getMsd());
// }
dataEntry.add(e.getValue().toString());
dataEntry.add(formatNumberAsPercent((double) e.getValue() / num_frequencies));
dataEntry.add(String.format("%.2f", ((double) e.getValue() * 10000)/num_frequencies));

View File

@@ -55,7 +55,7 @@ public class Util {
}
public static String formatNumberAsPercent(Object o) {
return MessageFormat.format("{0,number,#.###%}", o);
return MessageFormat.format("{0,number,#.### %}", o).replace('.', ',');
}
private static boolean isInstanceOfInteger(Object o) {