diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/rest/SpeechController.java b/src/main/java/org/texttechnologylab/project/gruppe_05_1/rest/SpeechController.java index 032561d..c48556d 100644 --- a/src/main/java/org/texttechnologylab/project/gruppe_05_1/rest/SpeechController.java +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/rest/SpeechController.java @@ -1,11 +1,11 @@ package org.texttechnologylab.project.gruppe_05_1.rest; -import de.tudarmstadt.ukp.dkpro.core.api.syntax.type.constituent.S; import io.javalin.http.Context; import io.javalin.openapi.*; import org.texttechnologylab.project.gruppe_05_1.database.MongoPprUtils; import org.texttechnologylab.project.gruppe_05_1.domain.html.HtmlSpeech; 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.nlp.Topic; import org.texttechnologylab.project.gruppe_05_1.domain.speech.SpeechMetaData; @@ -117,9 +117,49 @@ public class SpeechController { speech.getNlp().setPosList((List) new ArrayList()); // Ensure it's never null } + // NLP: Named Entities + if ((speech.getNlp().getNamedEntities() != null) + && (speech.getNlp().getNamedEntities().size() > 0)) { + + Map> namedEntitiesMapOfMaps = new HashMap<>(); + + for (NamedEntity ne : speech.getNlp().getNamedEntities()) { + String type = ne.getType(); + String text = ne.getText(); + + if (namedEntitiesMapOfMaps.containsKey(type)) { + // Named Entity Type bekannt... + Map 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 { + // ... aber der Text unbekannt --> erstelle einen neuen Eintrag für den Text und füge diesen dem Type-Eintrag hinzu + // TODO: DELETE + //Map firstTextAppearance = new HashMap<>(); + //firstTextAppearance.put(type, 1); + + typeAppearance.put(text, 1); + //namedEntitiesMapOfMaps.put(type, firstTextAppearance); + } + } else { + // Named Entity Type unbekannt: erstelle einen neuen Eintrag für Type sowie einen Eintrag für den ihm gehörigen Text + Map firstTextAppearance = new HashMap<>(); + firstTextAppearance.put(text, 1); + namedEntitiesMapOfMaps.put(type, firstTextAppearance); + } + } + + attributes.put("na_info", namedEntitiesMapOfMaps); + } else { + attributes.put("na_info", null); + } + // TODO: Token wird momentan etwas komisch abgespeichert, da im Attribut text die POS art steht, und in pos die Anzahl dieser POS arten. Umstrukturieren damit keine Verwirrung herrscht - // NLP: Sentiments + // NLP: Sentiments - TODO if (speech.getNlp().getSentiments() != null) { } diff --git a/src/main/resources/templates/namedEntitiesSunburstChart.ftl b/src/main/resources/templates/namedEntitiesSunburstChart.ftl index e69de29..371523f 100644 --- a/src/main/resources/templates/namedEntitiesSunburstChart.ftl +++ b/src/main/resources/templates/namedEntitiesSunburstChart.ftl @@ -0,0 +1,68 @@ + + + + \ No newline at end of file diff --git a/src/main/resources/templates/namedEntitiesTextEntry.ftl b/src/main/resources/templates/namedEntitiesTextEntry.ftl new file mode 100644 index 0000000..9c835cb --- /dev/null +++ b/src/main/resources/templates/namedEntitiesTextEntry.ftl @@ -0,0 +1 @@ + {"name": "${neText}", "size": ${count}} \ No newline at end of file diff --git a/src/main/resources/templates/namedEntitiesTypeEntry.ftl b/src/main/resources/templates/namedEntitiesTypeEntry.ftl new file mode 100644 index 0000000..7e83fb1 --- /dev/null +++ b/src/main/resources/templates/namedEntitiesTypeEntry.ftl @@ -0,0 +1,10 @@ + + { + "name": "${neType}", + "children": [ + <#list innerMap as neText, count> + <#include "namedEntitiesTextEntry.ftl"> <#sep>, + + ] + } + diff --git a/src/main/resources/templates/nlp.ftl b/src/main/resources/templates/nlp.ftl index 0f0b3a1..46adcf4 100644 --- a/src/main/resources/templates/nlp.ftl +++ b/src/main/resources/templates/nlp.ftl @@ -29,9 +29,9 @@
- <#if s.nlp.namedEntities??> + <#if na_info??>

Named Entities Information (als Sunburst Chart)

- <#assign nea = s.nlp.namedEntities> + <#assign neMap = na_info> <#include "namedEntitiesSunburstChart.ftl"> <#else>

Keine Named Entities Information für diese Rede verfügbar