From 235cf24518ca40bec59b497a416d9831db12eaa3 Mon Sep 17 00:00:00 2001 From: Benjamin Paassen Date: Thu, 8 Jan 2015 21:30:31 +0100 Subject: further extended example to include annotations (emphasized and strong). The DemoOutput for that is still missing, though. convenience build functions have also been implemented in Document.cpp. --- test/core/model/TestAdvanced.hpp | 117 ++++++++++++++++++++++++++++++++------- 1 file changed, 98 insertions(+), 19 deletions(-) (limited to 'test/core') diff --git a/test/core/model/TestAdvanced.hpp b/test/core/model/TestAdvanced.hpp index bec00f9..5af6003 100644 --- a/test/core/model/TestAdvanced.hpp +++ b/test/core/model/TestAdvanced.hpp @@ -109,6 +109,25 @@ static Rooted constructListDomain(Manager &mgr, return domain; } +/** + * This constructs the "emphasis" domain. + */ +static Rooted constructEmphasisDomain(Manager &mgr, + Handle sys, + Logger &logger) +{ + // set up domain node. + Rooted domain{new Domain(mgr, sys, "emphasis")}; + // create AnnotationClasses + Rooted em{ + new AnnotationClass(mgr, "emphasized", domain, {nullptr})}; + domain->getAnnotationClasses().push_back(em); + Rooted strong{ + new AnnotationClass(mgr, "strong", domain, {nullptr})}; + domain->getAnnotationClasses().push_back(strong); + return domain; +} + static bool addText(Handle parent, std::vector> &doms, const std::string &content) @@ -147,6 +166,34 @@ static bool addHeading(Handle parent, return true; } +static int annoIdx = 1; + +// Only works for non-overlapping annotations! +static bool addAnnotation(Handle doc, Handle parent, + std::vector> &doms, + const std::string &text, const std::string &annoClass) +{ + Rooted start = + AnnotationEntity::buildAnchor(parent, std::to_string(annoIdx++)); + if (start.isNull()) { + return false; + } + if (!addText(parent, doms, text)) { + return false; + } + Rooted end = + AnnotationEntity::buildAnchor(parent, std::to_string(annoIdx++)); + if (end.isNull()) { + return false; + } + Rooted anno = + AnnotationEntity::buildEntity(doc, doms, annoClass, start, end); + if (anno.isNull()) { + return false; + } + return true; +} + /** * This constructs a more advanced book document using not only the book * domain but also headings, emphasis and lists. @@ -170,10 +217,19 @@ static Rooted constructAdvancedDocument(Manager &mgr, } // Add the heading. - // TODO: use em here. - if (!addHeading(book, doms, - "Beantwortung der Frage: Was ist Aufklärung?")) { - return {nullptr}; + { + Rooted heading = StructuredEntity::buildEntity( + book, doms, "heading", "heading", {}, ""); + if (heading.isNull()) { + return {nullptr}; + } + if (!addText(heading, doms, "Beantwortung der Frage: ")) { + return {nullptr}; + } + if (!addAnnotation(doc, heading, doms, "Was ist Aufklärung?", + "emphasized")) { + return {nullptr}; + } } // Add the main section. @@ -196,20 +252,43 @@ static Rooted constructAdvancedDocument(Manager &mgr, return {nullptr}; } // Add its text. - // TODO: Use em and strong here - if (!addText(p, doms, - " Aufklärung ist der Ausgang des Menschen aus " - "seiner selbstverschuldeten Unmündigkeit. " - "Unmündigkeit ist das Unvermögen, sich seines " - "Verstandes ohne Leitung eines anderen zu bedienen. " - "Selbstverschuldet ist diese Unmündigkeit, wenn " - "die Ursache derselben nicht am Mangel des Verstandes, " - "sondern der Entschließung und des Mutes liegt, sich " - "seiner ohne Leitung eines andern zu bedienen. Sapere " - "aude! Habe Mut, dich deines eigenen Verstandes zu " - "bedienen! ist also der Wahlspruch der " - "Aufklärung.")) { - return {nullptr}; + { + if (!addAnnotation(doc, p, doms, + "Aufklärung ist der Ausgang des Menschen aus " + "seiner selbstverschuldeten Unmündigkeit", + "strong")) { + return {nullptr}; + } + if (!addAnnotation(doc, p, doms, "Unmündigkeit", + "emphasized")) { + return {nullptr}; + } + if (!addText(p, doms, + "ist das Unvermögen, sich seines Verstandes ohne " + "Leitung eines anderen zu bedienen. ")) { + return {nullptr}; + } + if (!addAnnotation(doc, p, doms, "Selbstverschuldet", + "emphasized")) { + return {nullptr}; + } + if (!addText(p, doms, + " ist diese Unmündigkeit, wenn die Ursache derselben " + "nicht am Mangel des Verstandes, sondern der " + "Entschließung und des Mutes liegt, sich seiner ohne " + "Leitung eines andern zu bedienen.")) { + return {nullptr}; + } + if (!addAnnotation(doc, p, doms, + "Sapere aude! Habe Mut, dich deines eigenen " + "Verstandes zu bedienen!", + "emphasized")) { + return {nullptr}; + } + if (!addText(p, doms, + " ist also der Wahlspruch der Aufklärung.")) { + return {nullptr}; + } } } @@ -225,7 +304,7 @@ static Rooted constructAdvancedDocument(Manager &mgr, } // Add list with citations { - //TODO: We need to restrict this to the list domain. Otherwise + // TODO: We need to restrict this to the list domain. Otherwise // this leads to resolve errors for some reason. Rooted ul = StructuredEntity::buildEntity(lesarten, {listDom}, "ul"); -- cgit v1.2.3