summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/model/Domain.cpp20
-rw-r--r--src/core/model/Domain.hpp6
-rw-r--r--src/plugins/html/DemoOutput.cpp38
-rw-r--r--src/plugins/html/DemoOutput.hpp4
-rw-r--r--test/core/model/TestAdvanced.hpp92
-rw-r--r--test/plugins/html/DemoOutputTest.cpp5
6 files changed, 132 insertions, 33 deletions
diff --git a/src/core/model/Domain.cpp b/src/core/model/Domain.cpp
index f9e2a55..49a3200 100644
--- a/src/core/model/Domain.cpp
+++ b/src/core/model/Domain.cpp
@@ -53,16 +53,16 @@ void Descriptor::doResolve(std::vector<Rooted<Managed>> &res,
// &DESCRIPTOR_ATTRIBUTES_ALIAS);
}
-void StructuredClass::doResolve(std::vector<Rooted<Managed>> &res,
- const std::vector<std::string> &path,
- Filter filter, void *filterData, unsigned idx,
- VisitorSet &visited)
-{
- Descriptor::doResolve(res, path, filter, filterData, idx, visited);
- if (!isa.isNull()) {
- isa->doResolve(res, path, filter, filterData, idx, visited);
- }
-}
+//void StructuredClass::doResolve(std::vector<Rooted<Managed>> &res,
+// const std::vector<std::string> &path,
+// Filter filter, void *filterData, unsigned idx,
+// VisitorSet &visited)
+//{
+// Descriptor::doResolve(res, path, filter, filterData, idx, visited);
+// if (!isa.isNull()) {
+// isa->doResolve(res, path, filter, filterData, idx, visited);
+// }
+//}
void Domain::doResolve(std::vector<Rooted<Managed>> &res,
const std::vector<std::string> &path, Filter filter,
diff --git a/src/core/model/Domain.hpp b/src/core/model/Domain.hpp
index 8d5de0c..6a07b32 100644
--- a/src/core/model/Domain.hpp
+++ b/src/core/model/Domain.hpp
@@ -468,12 +468,6 @@ private:
Owned<StructuredClass> isa;
NodeVector<FieldDescriptor> parents;
-protected:
- void doResolve(std::vector<Rooted<Managed>> &res,
- const std::vector<std::string> &path, Filter filter,
- void *filterData, unsigned idx,
- VisitorSet &visited) override;
-
public:
const bool transparent;
// TODO: Is it possible to have root=true and cardinality other than 1?
diff --git a/src/plugins/html/DemoOutput.cpp b/src/plugins/html/DemoOutput.cpp
index eac240b..307d37a 100644
--- a/src/plugins/html/DemoOutput.cpp
+++ b/src/plugins/html/DemoOutput.cpp
@@ -147,9 +147,8 @@ Rooted<xml::Element> DemoHTMLTransformer::transformSection(
Rooted<xml::Element> child;
if (childDescriptorName == "paragraph") {
child = transformParagraph(n);
- // TODO: Implement
- // } else if(childDescriptorName == "ul"){
- // writeList(n, out);
+ } else if (childDescriptorName == "ul" || childDescriptorName == "ol") {
+ child = transformList(n);
} else {
child = transformSection(n);
}
@@ -199,13 +198,30 @@ Rooted<xml::Element> DemoHTMLTransformer::transformParagraph(
return p;
}
-// Rooted<xml::Element>
-// DemoHTMLTransformer::transformList(Handle<model::StructuredEntity> list){
-// Manager &mgr = list->getManager();
-// // create the list Element, which is either ul or ol (depends on descriptor)
-// std::string listclass = list->getDescriptor()->getName();
-// Rooted<xml::Element> l{new xml::Element{mgr, listclass}};
-// // iterate through
-//}
+Rooted<xml::Element> DemoHTMLTransformer::transformList(
+ Handle<model::StructuredEntity> list)
+{
+ Manager &mgr = list->getManager();
+ // create the list Element, which is either ul or ol (depends on descriptor)
+ std::string listclass = list->getDescriptor()->getName();
+ Rooted<xml::Element> l{new xml::Element{mgr, listclass}};
+ // iterate through list items.
+ for (auto &item : list->getField()) {
+ std::string itDescrName = item->getDescriptor()->getName();
+ if (itDescrName == "item") {
+ // create the list item.
+ Rooted<xml::Element> li{new xml::Element{mgr, "li"}};
+ l->children.push_back(li);
+ // extract the item text, enveloped in a paragraph Element.
+ Rooted<xml::Element> li_content = transformParagraph(item);
+ // We omit the paragraph Element and add the children directly to
+ // the list item
+ for (auto &n : li_content->children) {
+ li->children.push_back(n);
+ }
+ }
+ }
+ return l;
+}
}
}
diff --git a/src/plugins/html/DemoOutput.hpp b/src/plugins/html/DemoOutput.hpp
index 0819d7f..6c046e7 100644
--- a/src/plugins/html/DemoOutput.hpp
+++ b/src/plugins/html/DemoOutput.hpp
@@ -46,8 +46,8 @@ private:
*/
Rooted<xml::Element> transformSection(Handle<model::StructuredEntity> sec);
Rooted<xml::Element> transformParagraph(Handle<model::StructuredEntity> par);
-// Rooted<xml::Element> transformList(Handle<model::StructuredEntity> list);
- //TODO: Implement emphasis.
+ Rooted<xml::Element> transformList(Handle<model::StructuredEntity> list);
+// TODO: Implement emphasis.
public:
/**
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<Domain> constructHeadingDomain(Manager &mgr,
card.merge({0, 1});
// set up heading StructuredClass.
Rooted<StructuredClass> 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<StructuredClass> p = resolveDescriptor(bookDomain, "paragraph");
heading->getFieldDescriptors().push_back(p->getFieldDescriptors()[0]);
@@ -75,6 +75,40 @@ static Rooted<Domain> constructHeadingDomain(Manager &mgr,
return domain;
}
+/**
+ * This constructs the "list" domain given the book domain.
+ */
+static Rooted<Domain> constructListDomain(Manager &mgr,
+ Handle<SystemTypesystem> sys,
+ Handle<Domain> bookDomain,
+ Logger &logger)
+{
+ // set up domain node.
+ Rooted<Domain> domain{new Domain(mgr, sys, "list")};
+ // set up cardinality
+ Cardinality any;
+ any.merge(Range<size_t>::typeRangeFrom(0));
+ // get book.paragraph
+ Rooted<StructuredClass> p = resolveDescriptor(bookDomain, "paragraph");
+ // set up item StructuredClass;
+ Rooted<StructuredClass> 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<std::string> listTypes{"ol", "ul"};
+ for (auto &listType : listTypes) {
+ Rooted<StructuredClass> list{new StructuredClass(
+ mgr, listType, domain, any, {nullptr}, p, false)};
+ Rooted<FieldDescriptor> 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<StructuredEntity> parent,
std::vector<Handle<Domain>> &doms,
const std::string &content)
@@ -120,9 +154,10 @@ static bool addHeading(Handle<StructuredEntity> parent,
*/
static Rooted<Document> constructAdvancedDocument(Manager &mgr,
Rooted<Domain> bookDom,
- Rooted<Domain> headingDom)
+ Rooted<Domain> headingDom,
+ Rooted<Domain> listDom)
{
- std::vector<Handle<Domain>> doms{bookDom, headingDom};
+ std::vector<Handle<Domain>> doms{bookDom, headingDom, listDom};
// Start with the (empty) document.
Rooted<Document> doc{new Document(mgr, "kant_was_ist_aufklaerung.oxd")};
@@ -144,6 +179,9 @@ static Rooted<Document> constructAdvancedDocument(Manager &mgr,
// Add the main section.
Rooted<StructuredEntity> 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<Document> constructAdvancedDocument(Manager &mgr,
{
Rooted<StructuredEntity> 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<Document> constructAdvancedDocument(Manager &mgr,
}
}
+ // Add the "Lesarten" section
+ Rooted<StructuredEntity> 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<StructuredEntity> ul =
+ StructuredEntity::buildEntity(lesarten, {listDom}, "ul");
+ if (ul.isNull()) {
+ return {nullptr};
+ }
+ std::vector<std::string> 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<StructuredEntity> 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<model::Domain> headingDom =
model::constructHeadingDomain(mgr, sys, bookDom, logger);
+ Rooted<model::Domain> listDom =
+ model::constructListDomain(mgr, sys, bookDom, logger);
// Construct the document.
- Rooted<model::Document> doc = model::constructAdvancedDocument(mgr, bookDom, headingDom);
+ Rooted<model::Document> doc =
+ model::constructAdvancedDocument(mgr, bookDom, headingDom, listDom);
#ifdef MANAGER_GRAPHVIZ_EXPORT
// dump the manager state