From b05499223916879e051d102e1b7e2fd080f46e7d Mon Sep 17 00:00:00 2001 From: Benjamin Paassen Date: Thu, 8 Jan 2015 20:31:30 +0100 Subject: further extended advanced document (now list domain is supported as well) and extended DemoOutput accordingly. --- test/core/model/TestAdvanced.hpp | 92 ++++++++++++++++++++++++++++++++++-- test/plugins/html/DemoOutputTest.cpp | 5 +- 2 files changed, 93 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/core/model/TestAdvanced.hpp b/test/core/model/TestAdvanced.hpp index bb7671a..bec00f9 100644 --- a/test/core/model/TestAdvanced.hpp +++ b/test/core/model/TestAdvanced.hpp @@ -56,7 +56,7 @@ static Rooted constructHeadingDomain(Manager &mgr, card.merge({0, 1}); // set up heading StructuredClass. Rooted heading{new StructuredClass( - mgr, "heading", {nullptr}, card, {nullptr}, {nullptr}, true)}; + mgr, "heading", domain, card, {nullptr}, {nullptr}, true)}; // as field we actually want to refer to the field of paragraph. Rooted p = resolveDescriptor(bookDomain, "paragraph"); heading->getFieldDescriptors().push_back(p->getFieldDescriptors()[0]); @@ -75,6 +75,40 @@ static Rooted constructHeadingDomain(Manager &mgr, return domain; } +/** + * This constructs the "list" domain given the book domain. + */ +static Rooted constructListDomain(Manager &mgr, + Handle sys, + Handle bookDomain, + Logger &logger) +{ + // set up domain node. + Rooted domain{new Domain(mgr, sys, "list")}; + // set up cardinality + Cardinality any; + any.merge(Range::typeRangeFrom(0)); + // get book.paragraph + Rooted p = resolveDescriptor(bookDomain, "paragraph"); + // set up item StructuredClass; + Rooted item{new StructuredClass( + mgr, "item", domain, any, {nullptr}, {nullptr}, false)}; + domain->getStructureClasses().push_back(item); + // as field we actually want to refer to the field of paragraph. + item->getFieldDescriptors().push_back(p->getFieldDescriptors()[0]); + // set up list StructuredClasses. + std::vector listTypes{"ol", "ul"}; + for (auto &listType : listTypes) { + Rooted list{new StructuredClass( + mgr, listType, domain, any, {nullptr}, p, false)}; + Rooted list_field{new FieldDescriptor(mgr, list)}; + list_field->getChildren().push_back(item); + list->getFieldDescriptors().push_back(list_field); + domain->getStructureClasses().push_back(list); + } + return domain; +} + static bool addText(Handle parent, std::vector> &doms, const std::string &content) @@ -120,9 +154,10 @@ static bool addHeading(Handle parent, */ static Rooted constructAdvancedDocument(Manager &mgr, Rooted bookDom, - Rooted headingDom) + Rooted headingDom, + Rooted listDom) { - std::vector> doms{bookDom, headingDom}; + std::vector> doms{bookDom, headingDom, listDom}; // Start with the (empty) document. Rooted doc{new Document(mgr, "kant_was_ist_aufklaerung.oxd")}; @@ -144,6 +179,9 @@ static Rooted constructAdvancedDocument(Manager &mgr, // Add the main section. Rooted sec = StructuredEntity::buildEntity(book, doms, "section"); + if (sec.isNull()) { + return {nullptr}; + } // Add the heading. if (!addHeading(sec, doms, "Was ist Aufklärung?")) { @@ -154,6 +192,9 @@ static Rooted constructAdvancedDocument(Manager &mgr, { Rooted p = StructuredEntity::buildEntity(sec, doms, "paragraph"); + if (p.isNull()) { + return {nullptr}; + } // Add its text. // TODO: Use em and strong here if (!addText(p, doms, @@ -172,6 +213,51 @@ static Rooted constructAdvancedDocument(Manager &mgr, } } + // Add the "Lesarten" section + Rooted lesarten = + StructuredEntity::buildEntity(book, doms, "section"); + if (lesarten.isNull()) { + return {nullptr}; + } + // Add the heading. + if (!addHeading(lesarten, doms, "Lesarten")) { + return {nullptr}; + } + // Add list with citations + { + //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"); + if (ul.isNull()) { + return {nullptr}; + } + std::vector citations{ + "Berlinische Monatsschrift. Dezember-Heft 1784. S. 481–494.", + "Kant. Kleine Schriften. Neuwied 1793. Haupt. 8o. S. 34–50.", + "I. Kant. Zerstreute Aufsätze. Frankfurt und Leipzig 1793. 8o. S. " + "25–37.", + "I. Kant. Sämmtliche kleine Schriften. 4 Bände. 1797–98. 8o. " + "Königsberg u. Leipzig (Voigt, Jena). Nachdruck. Bd. III, S. " + "159–172.", + " I. Kant's vermischte Schriften. 3 Bände. Halle 1799. " + "(Tieftrunk). Bd. II. S. 687–700.", + "Kant. Vorzügliche kleine Schriften und Aufsätze, hrsg. mit Noten " + "von F. Ch. Starke. 2 Bände. Leipzig 1833 und Quedlinburg 1838. " + "Bd. I, S. 75–84."}; + for (auto &cit : citations) { + // TODO: This needs to be restricted as well. + Rooted item = + StructuredEntity::buildEntity(ul, {listDom}, "item"); + if (item.isNull()) { + return {nullptr}; + } + if (!addText(item, doms, cit)) { + return {nullptr}; + } + } + } + return doc; } } diff --git a/test/plugins/html/DemoOutputTest.cpp b/test/plugins/html/DemoOutputTest.cpp index 7857314..471ccc3 100644 --- a/test/plugins/html/DemoOutputTest.cpp +++ b/test/plugins/html/DemoOutputTest.cpp @@ -43,8 +43,11 @@ TEST(DemoHTMLTransformer, writeHTML) model::constructBookDomain(mgr, sys, logger); Rooted headingDom = model::constructHeadingDomain(mgr, sys, bookDom, logger); + Rooted listDom = + model::constructListDomain(mgr, sys, bookDom, logger); // Construct the document. - Rooted doc = model::constructAdvancedDocument(mgr, bookDom, headingDom); + Rooted doc = + model::constructAdvancedDocument(mgr, bookDom, headingDom, listDom); #ifdef MANAGER_GRAPHVIZ_EXPORT // dump the manager state -- cgit v1.2.3