/* 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_ */