added bar chart

This commit is contained in:
Jonas Werner 2025-03-23 14:28:44 +01:00
parent 9332ceab03
commit f0d1fffec4

View file

@ -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.Sentiment;
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;
@ -66,7 +67,8 @@ public class TeXUtil {
return tex.toString().replace("$$SPEAKERINFO$$", speaker.toTeX())
.replace("$$NLPMETADATA$$",
generateChartView(generateBubbleChartLatex(topics),
generateBarChartLatex(getPOSInformationCardinalitiesForSpeechById(speechId)), "", ""));
generateBarChartLatex(getPOSInformationCardinalitiesForSpeechById(speechId)),
generateRadarChartLatex(getHTMLSpeechByKey(speechId).getNlp().getSentiments()), ""));
}
public static String getSpeechToTexComponent(Speech speech) {
@ -244,10 +246,10 @@ public class TeXUtil {
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")
tex.append("\\begin{minipage}{1\\textwidth}\n")
.append(bubbleChartTeX)
.append("\\end{minipage}\n")
.append("\\begin{minipage}{0.5\\textwidth}\n")
.append("\\begin{minipage}{1\\textwidth}\n")
.append(barChartTeX)
.append("\\end{minipage}\n")
.append("\\begin{minipage}{0.5\\textwidth}\n")
@ -284,17 +286,69 @@ public class TeXUtil {
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");
tex.append("\n" +
"\\scalebox{0.25}{" + // the only way to reliably show most of the POS is by scaling it down this far
"\\begin{tikzpicture}\n" +
"\n" +
"\\begin{axis}[\n" +
" ybar,\n" +
" width=4\\textwidth,\n" +
" height=0.5\\textwidth,\n");
StringBuilder graphData = new StringBuilder();
StringBuilder xCords = new StringBuilder();
xCords.append("{");
for (Map.Entry<String, Integer> entry : barData.entrySet()) {
tex.append(entry.getKey()).append(" & ").append(entry.getValue()).append(" \\\\ \\hline\n");
xCords.append(entry.getKey()).append(", ");
graphData.append("\t(").append(entry.getKey()).append(", ").append(entry.getValue()).append(")\n");
}
xCords.append("}");
String xCordsString = xCords.toString().replace("$", "\\$");
tex.append("\\end{tabular}\n\n");
tex.append(" symbolic x coords=").append(xCordsString).append(",\n" +
" xtick=data,\n" +
" ylabel={Value},\n" +
" xlabel={Category},\n" +
" ymin=0, ymax=800\n" +
" ]" +
"\\addplot coordinates {\n");
tex.append(graphData.toString().replace("$", "\\$"));
tex.append("};\n" +
"\\end{axis}\n" +
"\n" +
"\\end{tikzpicture}" +
"}");
return tex.toString();
}
public static String generateRadarChartLatex(List<Sentiment> sentimets) {
StringBuilder tex = new StringBuilder();
tex.append("\\begin{tikzpicture}\n" +
" \\coordinate (origin) at (0, 0);\n" +
"\n" +
" % Define the axes (3 axes) with unit length (1)\n" +
" \\foreach[count=\\i] \\dim in {Negative, Neutral, Positive}{\n" +
" \\coordinate (\\i) at (\\i * 360 / 3: 1); % Set radius to 1 for unit length axes\n" +
" \\node at (\\i * 360 / 3: 1.1) {\\huge\\dim}; % Axis labels (slightly outside)\n" +
" \\draw (origin) -- (\\i); % Draw the axes\n" +
" }");
for (Sentiment sentiment : sentimets) {
tex.append("\\foreach \\i/\\value in {1/")
.append(sentiment.getNegative())
.append(", 2/")
.append(sentiment.getNeutral())
.append(", 3/")
.append(sentiment.getPositive())
.append("}{\n")
.append(" \\coordinate (point-\\i) at (\\i * 360 / 3: \\value);\n")
.append(" }\n");
}
tex.append("\\draw [fill=blue!20, opacity=.7] (point-1) -- (point-2) -- (point-3) -- cycle;\n" +
"\\end{tikzpicture}");
return tex.toString();
}
}