From 7269e0e232c7971248ffa47aa2ae44786f3d303a Mon Sep 17 00:00:00 2001 From: Benjamin Paassen Date: Thu, 8 Jan 2015 17:20:56 +0100 Subject: slight changes to Domain and Document. Started to add a more advanced test document creation function as well as the respective domain creation functions. The DemoOutputTest for it looks good so far. --- test/core/model/TestAdvanced.hpp | 129 +++++++++++++++++++++++++++++++++++++++ test/core/model/TestDomain.hpp | 12 ++++ 2 files changed, 141 insertions(+) create mode 100644 test/core/model/TestAdvanced.hpp (limited to 'test/core') diff --git a/test/core/model/TestAdvanced.hpp b/test/core/model/TestAdvanced.hpp new file mode 100644 index 0000000..95c5402 --- /dev/null +++ b/test/core/model/TestAdvanced.hpp @@ -0,0 +1,129 @@ +/* + Ousía + Copyright (C) 2014, 2015 Benjamin Paaßen, Andreas Stöckel + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef _MODEL_TEST_DOCUMENT_HPP_ +#define _MODEL_TEST_DOCUMENT_HPP_ + +#include +#include +#include + +namespace ousia { +namespace model { + + +static Rooted resolveDescriptor(Handle domain, + const std::string &className) +{ + // use the actual resolve method. + std::vector> resolved = domain->resolve(className); + // take the first valid result. + for (auto &r : resolved) { + if (r->isa(typeOf())) { + return r.cast(); + } + } + // if no valid result exists, return nullptr. + return {nullptr}; +} + +/** + * This constructs the "heading" domain given the book domain. + */ +static Rooted constructHeadingDomain(Manager &mgr, + Handle sys, + Handle bookDomain, + Logger &logger) +{ + // set up domain node. + Rooted domain{new Domain(mgr, sys, "headings")}; + // set up cardinality (every section may have at most one heading). + Cardinality card; + card.merge({0, 1}); + // set up heading StructuredClass. + Rooted heading{new StructuredClass( + mgr, "heading", {nullptr}, 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]); + // add the class to the domain. + domain->getStructureClasses().push_back(heading); + // create a new field for headings in each section type. + std::vector secclasses{"book", "section", "subsection", + "paragraph"}; + for (auto &s : secclasses) { + Rooted desc = resolveDescriptor(bookDomain, s); + Rooted heading_field{new FieldDescriptor( + mgr, desc, FieldDescriptor::FieldType::SUBTREE, "heading")}; + heading_field->getChildren().push_back(heading); + desc->getFieldDescriptors().push_back(heading_field); + } + return domain; +} + +/** + * This constructs a more advanced book document using not only the book + * domain but also headings, emphasis and lists. + * TODO: insert emphasis and lists. + */ +static Rooted constructAdvancedDocument(Manager &mgr, + Rooted bookDom, + Rooted headingDom) +{ + std::vector> doms{bookDom, headingDom}; + + // Start with the (empty) document. + Rooted doc{new Document(mgr, "kant_was_ist_aufklaerung.oxd")}; + + // Add the root. + Rooted book = + StructuredEntity::buildRootEntity(doc, doms, "book"); + if (book.isNull()) { + return {nullptr}; + } + { + // Add the heading. + Rooted heading = StructuredEntity::buildEntity( + book, doms, "heading", "heading", {}, ""); + if (heading.isNull()) { + return {nullptr}; + } + { + // Add its text. + Rooted text = + StructuredEntity::buildEntity(heading, doms, "text"); + if (text.isNull()) { + return {nullptr}; + } + // And its primitive content + // TODO: use em here. + Variant content {"Beantwortung der Frage: Was ist Aufklärung?"}; + Rooted main_primitive = + DocumentPrimitive::buildEntity(text, content, "content"); + if (main_primitive.isNull()) { + return {nullptr}; + } + }} + + return doc; +} +} +} + +#endif /* _TEST_DOCUMENT_HPP_ */ + diff --git a/test/core/model/TestDomain.hpp b/test/core/model/TestDomain.hpp index 54e79ee..aa3096d 100644 --- a/test/core/model/TestDomain.hpp +++ b/test/core/model/TestDomain.hpp @@ -69,6 +69,18 @@ static Rooted constructBookDomain(Manager &mgr, new FieldDescriptor(mgr, paragraph)}; paragraph->getFieldDescriptors().push_back(paragraph_field); + // We append "subsection" to section. + Rooted subsection{ + new StructuredClass(mgr, "subsection", domain, any)}; + section_field->getChildren().push_back(subsection); + domain->getStructureClasses().push_back(subsection); + // And the field of it. + Rooted subsection_field{ + new FieldDescriptor(mgr, subsection)}; + subsection->getFieldDescriptors().push_back(subsection_field); + // and we add the paragraph to subsections fields + subsection_field->getChildren().push_back(paragraph); + // Finally we add the "text" node, which is transparent as well. Rooted text{new StructuredClass( mgr, "text", domain, any, {nullptr}, {nullptr}, true)}; -- cgit v1.2.3