fixed bad merge
This commit is contained in:
parent
4db18688b5
commit
67e117b647
2 changed files with 72 additions and 2 deletions
|
@ -111,4 +111,76 @@ public class FrontEndController {
|
|||
public static void getAboutPage(Context ctx) {
|
||||
ctx.render("about.ftl");
|
||||
}
|
||||
|
||||
/**
|
||||
* Aggregiert für alle Reden die NLP‑Ergebnisse (Topics, POS, Named Entities, erste Sentiment‑Objekte)
|
||||
* und liefert die zusammengefassten Daten an die Charts‑Ansicht.
|
||||
* @param ctx Javalin Context zum Rendern der Seite mit den aggregierten Chart‑Daten
|
||||
* Implementiert von Leon
|
||||
*/
|
||||
public static void getCharts(Context ctx) {
|
||||
MongoCollection<Document> col = MongoPprUtils.getSpeechCollection();
|
||||
|
||||
List<Bson> topicsPipeline = List.of(
|
||||
Aggregates.match(Filters.exists("analysisResults.topics.0")),
|
||||
Aggregates.unwind("$analysisResults.topics"),
|
||||
Aggregates.group(
|
||||
"$analysisResults.topics.topic",
|
||||
Accumulators.sum("totalScore", "$analysisResults.topics.score")
|
||||
)
|
||||
);
|
||||
List<Bson> posPipeline = List.of(
|
||||
Aggregates.match(Filters.exists("analysisResults.tokens")),
|
||||
Aggregates.unwind("$analysisResults.tokens"),
|
||||
Aggregates.group("$analysisResults.tokens.pos", Accumulators.sum("count", 1))
|
||||
);
|
||||
List<Bson> nePipeline = List.of(
|
||||
Aggregates.match(Filters.exists("analysisResults.namedEntities")),
|
||||
Aggregates.unwind("$analysisResults.namedEntities"),
|
||||
Aggregates.group("$analysisResults.namedEntities.type", Accumulators.sum("count", 1))
|
||||
);
|
||||
List<Bson> sentimentsPipeline = List.of(
|
||||
Aggregates.match(Filters.exists("analysisResults.sentiments")),
|
||||
Aggregates.project(Projections.computed("firstSentiment",
|
||||
new Document("$arrayElemAt", List.of("$analysisResults.sentiments", 0)))),
|
||||
Aggregates.replaceRoot("$firstSentiment")
|
||||
);
|
||||
|
||||
CompletableFuture<List<Document>> topicsF = CompletableFuture.supplyAsync(() -> col.aggregate(topicsPipeline).into(new ArrayList<>()));
|
||||
CompletableFuture<List<Document>> posF = CompletableFuture.supplyAsync(() -> col.aggregate(posPipeline).into(new ArrayList<>()));
|
||||
CompletableFuture<List<Document>> neF = CompletableFuture.supplyAsync(() -> col.aggregate(nePipeline).into(new ArrayList<>()));
|
||||
CompletableFuture<List<Document>> sentF = CompletableFuture.supplyAsync(() -> col.aggregate(sentimentsPipeline).into(new ArrayList<>()));
|
||||
|
||||
CompletableFuture.allOf(topicsF, posF, neF, sentF).join();
|
||||
|
||||
List<Topic> aggregatedTopics = topicsF.join().stream()
|
||||
.map(d -> new Topic(d.getString("_id"), d.getDouble("totalScore"), null))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
List<Token> aggregatedPOS = posF.join().stream()
|
||||
.map(d -> new Token(d.getString("_id"), String.valueOf(d.getInteger("count")), ""))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
Map<String, Map<String, Integer>> aggregatedNE = new HashMap<>();
|
||||
neF.join().forEach(d -> {
|
||||
List<Document> entities = d.getList("entities", Document.class);
|
||||
Map<String, Integer> typeMap = (entities == null)
|
||||
? new HashMap<>()
|
||||
: entities.stream()
|
||||
.collect(Collectors.toMap(
|
||||
e -> e.getString("text"),
|
||||
e -> e.getInteger("count")
|
||||
));
|
||||
aggregatedNE.put(d.getString("_id"), typeMap);
|
||||
});
|
||||
|
||||
List<Sentiment> aggregatedSentiments = Sentiment.readSentimentsFromMongo(sentF.join());
|
||||
|
||||
ctx.render("charts.ftl", Map.of(
|
||||
"aggregatedTopics", aggregatedTopics,
|
||||
"aggregatedPOS", aggregatedPOS,
|
||||
"aggregatedNE", aggregatedNE,
|
||||
"aggregatedSentiments", aggregatedSentiments
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -75,8 +75,6 @@ public class RESTHandler {
|
|||
// Charts
|
||||
app.get("/charts", FrontEndController::getCharts);
|
||||
|
||||
app.get("/about", FrontEndController::getAbout);
|
||||
|
||||
app.get("/export/pdf/speech/{id}", SpeechesLatexExportController::exportSpeech); // exportiere eine Rede als PDF
|
||||
app.get("/export/pdf/speech", SpeechesLatexExportController::exportSpeech); // exportiere eine Rede als PDF
|
||||
app.get("/export/pdf/speaker/{id}", SpeechesLatexExportController::exportSpeechesFromSpeaker); // exportiere alle Reden eines Parlamentariers als PDF
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue