Added collocability functionality - implemented Dice method

This commit is contained in:
2018-10-24 10:36:07 +02:00
parent 1d9e9b7ed6
commit f9ce74d7b8
6 changed files with 290 additions and 108 deletions

View File

@@ -9,9 +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 data.*;
import gui.ValidationUtil;
import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVPrinter;
@@ -61,7 +59,9 @@ 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, Filter filter) {
StatisticsNew statistics, Filter filter) {
Map<String, Map<MultipleHMKeys, AtomicLong>> taxonomyResults = statistics.getTaxonomyResult();
//Delimiter used in CSV file
String NEW_LINE_SEPARATOR = "\n";
List<Object> FILE_HEADER_AL = new ArrayList<Object>();
@@ -96,77 +96,22 @@ public class Export {
FILE_HEADER_AL.add("Lema male črke");
headerInfoBlock.put(filter.getCalculateFor().toMetadataString(), String.valueOf(num_frequencies));
// if (headerInfoBlock.containsKey("Analiza") && (headerInfoBlock.get("Analiza").equals("Besede") || headerInfoBlock.get("Analiza").equals("Besedni nizi"))) {
// if (headerInfoBlock.containsKey("Izračunaj za:") && headerInfoBlock.get("Izračunaj za:").equals("različnica")) {
// headerInfoBlock.put("Skupna vsota vseh različnic:", String.valueOf(num_frequencies));
// if (headerInfoBlock.get("Analiza").equals("Besede")){
// FILE_HEADER_AL.add("Različnica");
// } else if (headerInfoBlock.get("Analiza").equals("Besedni nizi")) {
// FILE_HEADER_AL.add("Različnice");
// }
// } else if (headerInfoBlock.containsKey("Izračunaj za:") && headerInfoBlock.get("Izračunaj za:").equals("lema")) {
// 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));
// if (headerInfoBlock.get("Analiza").equals("Besede")){
// FILE_HEADER_AL.add("Oblikoskladenjska oznaka");
// } else if (headerInfoBlock.get("Analiza").equals("Besedni nizi")) {
// FILE_HEADER_AL.add("Oblikoskladenjska oznake");
// }
// } 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 (CalculateFor otherKey : filter.getMultipleKeys()) {
FILE_HEADER_AL.add(otherKey.toHeaderString());
if (otherKey.equals(CalculateFor.LEMMA))
FILE_HEADER_AL.add("Lema male črke");
}
// if(otherKey.equals(CalculateFor.LEMMA)){
// FILE_HEADER_AL.add("Lema");
// FILE_HEADER_AL.add("Lema male črke");
// }
// if(otherKey.equals(CalculateFor.WORD_TYPE)){
// FILE_HEADER_AL.add("Besedna vrsta");
// }
// if(otherKey.equals(CalculateFor.MORPHOSYNTACTIC_SPECS)){
// FILE_HEADER_AL.add("Oblikoskladenjska oznaka");
// }
// if(otherKey.equals(CalculateFor.NORMALIZED_WORD)){
// FILE_HEADER_AL.add("Normalizirana različnica");
// }
// }
// break;
// }
FILE_HEADER_AL.add("Skupna absolutna pogostost");
FILE_HEADER_AL.add(filter.getCalculateFor().toPercentString());
// if (headerInfoBlock.containsKey("Izračunaj za:") && headerInfoBlock.get("Izračunaj za:").equals("različnica")) {
// FILE_HEADER_AL.add("Delež glede na vse različnice");
// } else if (headerInfoBlock.containsKey("Izračunaj za:") && headerInfoBlock.get("Izračunaj za:").equals("lema")) {
// FILE_HEADER_AL.add("Delež glede na vse leme");
// } else if (headerInfoBlock.containsKey("Izračunaj za:") && headerInfoBlock.get("Izračunaj za:").equals("oblikoskladenjska oznaka")) {
// FILE_HEADER_AL.add("Delež glede na vse oblikoskladenjske oznake");
// } else {
// FILE_HEADER_AL.add("Delež glede na vse leme");
// }
FILE_HEADER_AL.add("Skupna relativna pogostost (na milijon pojavitev)");
if (filter.getCollocability().size() > 0){
FILE_HEADER_AL.add(filter.getCollocability().get(0).toHeaderString());
}
for (String key : taxonomyResults.keySet()) {
if(!key.equals("Total") && num_taxonomy_frequencies.get(key) > 0) {
FILE_HEADER_AL.add("Absolutna pogostost [" + key + "]");
@@ -176,9 +121,6 @@ public class Export {
}
FILE_HEADER = new String[ FILE_HEADER_AL.size() ];
FILE_HEADER_AL.toArray(FILE_HEADER);
// } else {
// FILE_HEADER = new Object[]{"word", "frequency", "percent"};
// }
String fileName = "";
@@ -250,16 +192,7 @@ public class Export {
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() * 1000000)/num_frequencies));
@@ -270,8 +203,13 @@ public class Export {
dataEntry.add(formatNumberAsPercent((double) frequency.get() / num_taxonomy_frequencies.get(key)));
dataEntry.add(String.format("%.2f", ((double) frequency.get() * 1000000) / num_taxonomy_frequencies.get(key)));
}
}
if (filter.getCollocability().size() > 0){
dataEntry.add(String.format("%.4f", statistics.getCollocability().get(filter.getCollocability().get(0)).get(e.getKey())));
}
// Write msd separated per letters at the end of each line in csv
if (filter.getWriteMsdAtTheEnd()) {
String msd = "";