pushing some non-functional code
This commit is contained in:
parent
ab37c00ea9
commit
b82597dfeb
4 changed files with 120 additions and 1 deletions
|
@ -16,6 +16,8 @@ import org.texttechnologylab.project.gruppe_05_1.database.domainimpl.mdb.Speech_
|
|||
import org.texttechnologylab.project.gruppe_05_1.domain.html.HtmlSpeech;
|
||||
import org.texttechnologylab.project.gruppe_05_1.domain.html.Parlamentarier;
|
||||
import org.texttechnologylab.project.gruppe_05_1.domain.html.ParlamentarierDetails;
|
||||
import org.texttechnologylab.project.gruppe_05_1.domain.nlp.NamedEntity;
|
||||
import org.texttechnologylab.project.gruppe_05_1.domain.nlp.Token;
|
||||
import org.texttechnologylab.project.gruppe_05_1.domain.speaker.Membership;
|
||||
import org.texttechnologylab.project.gruppe_05_1.domain.speech.SpeechMetaData;
|
||||
import org.texttechnologylab.project.gruppe_05_1.util.GeneralUtils;
|
||||
|
@ -28,6 +30,7 @@ import java.time.LocalDate;
|
|||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.mongodb.client.model.Filters.eq;
|
||||
|
||||
|
@ -760,4 +763,43 @@ public class MongoPprUtils {
|
|||
}
|
||||
return speechIds;
|
||||
}
|
||||
public static Map<String, Integer> getPOSInformationCardinalitiesForSpeechById(String speechId) {
|
||||
List<Token> tokens = getHTMLSpeechByKey(speechId).getNlp().getTokens();
|
||||
Map<String, Integer> posCounts = Token.countPOS(tokens);
|
||||
|
||||
List<Token> posList = posCounts.entrySet().stream()
|
||||
.map(entry -> new Token(entry.getKey(), String.valueOf(entry.getValue()), "")) // Lemma remains empty
|
||||
.collect(Collectors.toList());
|
||||
|
||||
return posCounts;
|
||||
}
|
||||
|
||||
public static Map<String, Integer> getNamedEntitiesInformationCardinalitiesForSpeechById(String speechId) {
|
||||
Map<String, Map<String, Integer>> namedEntitiesMapOfMaps = new HashMap<>();
|
||||
|
||||
for (NamedEntity ne : getHTMLSpeechByKey(speechId).getNlp().getNamedEntities()) {
|
||||
String type = ne.getType();
|
||||
String text = ne.getText();
|
||||
|
||||
if (namedEntitiesMapOfMaps.containsKey(type)) {
|
||||
// Named Entity Type bekannt...
|
||||
Map<String, Integer> typeAppearance = namedEntitiesMapOfMaps.get(type);
|
||||
if (typeAppearance.containsKey(text)) {
|
||||
// ... und der Text auch bekannt --> erhöhe die Anzahl um 1
|
||||
typeAppearance.replace(
|
||||
text,
|
||||
typeAppearance.get(text) + 1) ;
|
||||
} else {
|
||||
typeAppearance.put(text, 1);
|
||||
}
|
||||
} else {
|
||||
// Named Entity Type unbekannt: erstelle einen neuen Eintrag für Type sowie einen Eintrag für den ihm gehörigen Text
|
||||
Map<String, Integer> firstTextAppearance = new HashMap<>();
|
||||
firstTextAppearance.put(text, 1);
|
||||
namedEntitiesMapOfMaps.put(type, firstTextAppearance);
|
||||
}
|
||||
}
|
||||
|
||||
return namedEntitiesMapOfMaps.get("CARDINAL"); // needs fixing
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.texttechnologylab.project.gruppe_05_1.export;
|
||||
|
||||
import org.texttechnologylab.project.gruppe_05_1.database.domainimpl.mdb.Speaker_MongoDB_Impl;
|
||||
import org.texttechnologylab.project.gruppe_05_1.domain.nlp.Topic;
|
||||
import org.texttechnologylab.project.gruppe_05_1.util.Logger;
|
||||
import org.texttechnologylab.project.gruppe_05_1.xml.speeches.Interfaces.Speech;
|
||||
|
||||
|
@ -16,6 +17,7 @@ import java.time.format.DateTimeFormatter;
|
|||
import java.util.Arrays;
|
||||
import java.util.Base64;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.texttechnologylab.project.gruppe_05_1.Main.RESOURCES_DIR;
|
||||
import static org.texttechnologylab.project.gruppe_05_1.Main.TEMP_EXPORT_DIR;
|
||||
|
@ -49,7 +51,22 @@ public class TeXUtil {
|
|||
|
||||
tex.append(speech.toTeX());
|
||||
|
||||
return tex.toString().replace("$$SPEAKERINFO$$", speaker.toTeX());
|
||||
Map<String, Double> topics = Topic.condenseTopicInformation(getHTMLSpeechByKey(speechId).getNlp().getTopics());
|
||||
// loop through topics and Logger.pink them
|
||||
for (Map.Entry<String, Double> entry : topics.entrySet()) {
|
||||
Logger.pink(entry + " " + entry.getValue());
|
||||
}
|
||||
|
||||
/*Map<String, Integer> pos = getPOSInformationCardinalitiesForSpeechById(speechId);
|
||||
// loop through topics and Logger.pink them
|
||||
for (Map.Entry<String, Integer> entry : pos.entrySet()) {
|
||||
Logger.pink(entry + " " + entry.getValue());
|
||||
}*/
|
||||
|
||||
return tex.toString().replace("$$SPEAKERINFO$$", speaker.toTeX())
|
||||
.replace("$$NLPMETADATA$$",
|
||||
generateChartView(generateBubbleChartLatex(topics),
|
||||
generateBarChartLatex(getPOSInformationCardinalitiesForSpeechById(speechId)), "", ""));
|
||||
}
|
||||
|
||||
public static String getSpeechToTexComponent(Speech speech) {
|
||||
|
@ -223,4 +240,61 @@ public class TeXUtil {
|
|||
} catch (IOException ignored) {}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static String generateChartView(String bubbleChartTeX, String barChartTeX, String radarChartTeX, String sunburstCharTeX) {
|
||||
StringBuilder tex = new StringBuilder();
|
||||
// 2x2 minipage layout
|
||||
tex.append("\\begin{minipage}{0.5\\textwidth}\n")
|
||||
.append(bubbleChartTeX)
|
||||
.append("\\end{minipage}\n")
|
||||
.append("\\begin{minipage}{0.5\\textwidth}\n")
|
||||
.append(barChartTeX)
|
||||
.append("\\end{minipage}\n")
|
||||
.append("\\begin{minipage}{0.5\\textwidth}\n")
|
||||
.append(radarChartTeX)
|
||||
.append("\\end{minipage}\n")
|
||||
.append("\\begin{minipage}{0.5\\textwidth}\n")
|
||||
.append(sunburstCharTeX)
|
||||
.append("\\end{minipage}\n");
|
||||
|
||||
return tex.toString();
|
||||
}
|
||||
|
||||
public static String generateBubbleChartLatex(Map<String, Double> bubbleData) {
|
||||
StringBuilder tex = new StringBuilder();
|
||||
|
||||
tex.append("Topics Information\\\\\n");
|
||||
|
||||
// draw generic table with String | Double
|
||||
tex.append("\\begin{tabular}{|c|c|}\n")
|
||||
.append("\\hline\n")
|
||||
.append("Category & Value \\\\ \\hline\n");
|
||||
|
||||
for (Map.Entry<String, Double> entry : bubbleData.entrySet()) {
|
||||
tex.append(entry.getKey()).append(" & ").append(entry.getValue()).append(" \\\\ \\hline\n");
|
||||
}
|
||||
|
||||
tex.append("\\end{tabular}\n\n");
|
||||
|
||||
return tex.toString();
|
||||
}
|
||||
|
||||
public static String generateBarChartLatex(Map<String, Integer> barData) {
|
||||
StringBuilder tex = new StringBuilder();
|
||||
|
||||
tex.append("POS Information\\\\\n");
|
||||
|
||||
// draw generic table with String | Double
|
||||
tex.append("\\begin{tabular}{|c|c|}\n")
|
||||
.append("\\hline\n")
|
||||
.append("Category & Value \\\\ \\hline\n");
|
||||
|
||||
for (Map.Entry<String, Integer> entry : barData.entrySet()) {
|
||||
tex.append(entry.getKey()).append(" & ").append(entry.getValue()).append(" \\\\ \\hline\n");
|
||||
}
|
||||
|
||||
tex.append("\\end{tabular}\n\n");
|
||||
|
||||
return tex.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
\usepackage{geometry}
|
||||
\usepackage{xcolor}
|
||||
\usepackage[T1]{fontenc}
|
||||
\usepackage{tikz}
|
||||
\usepackage{pgfplots}
|
||||
|
||||
\pagestyle{fancy}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue