diff options
author | Benjamin Paassen <bpaassen@techfak.uni-bielefeld.de> | 2014-12-20 15:14:28 +0100 |
---|---|---|
committer | Benjamin Paassen <bpaassen@techfak.uni-bielefeld.de> | 2014-12-20 15:14:28 +0100 |
commit | f77ec7ae614810bc317c23138279e115f930aa06 (patch) | |
tree | bbd57ad043f124b2bdf6aeebd9c5fda91e4ca679 | |
parent | f93c95dbd4aab6ebbccc647da5d1d2da437417ce (diff) |
Introduced global type variables for model classes and used them in the Domain resolve test, which makes it much easier to understand.
-rw-r--r-- | src/core/model/Document.hpp | 38 | ||||
-rw-r--r-- | src/core/model/Domain.hpp | 43 | ||||
-rw-r--r-- | test/core/model/DomainTest.cpp | 24 |
3 files changed, 78 insertions, 27 deletions
diff --git a/src/core/model/Document.hpp b/src/core/model/Document.hpp index a660da7..0e0a416 100644 --- a/src/core/model/Document.hpp +++ b/src/core/model/Document.hpp @@ -188,6 +188,11 @@ public: }; /** + * A global variable for the ManagedType of a DocumentEntity. + */ +static ManagedType DocumentEntityType{"DocumentEntity", typeid(DocumentEntity)}; + +/** * A StructuredEntity is a node in the Structure Tree of a document. For more * information please refer to the header documentation above. */ @@ -260,6 +265,12 @@ public: }; /** + * A global variable for the ManagedType of a StructuredEntity. + */ +static ManagedType StructuredEntityType{ + "StructuredEntity", typeid(StructuredEntity), {&DocumentEntityType}}; + +/** * This is a wrapper for primitive types (Variants) inside the document graph. * The most straightforward example for this is the actual document text, e.g. * inside a paragraph. In that case this would represent a mere string. @@ -292,11 +303,17 @@ public: * contain a StructuredClass with the given name. */ static Rooted<DocumentPrimitive> buildEntity( - Handle<DocumentEntity> parent, - Variant content, const std::string &fieldName = ""); + Handle<DocumentEntity> parent, Variant content, + const std::string &fieldName = ""); }; /** + * A global variable for the ManagedType of a DocumentPrimitive. + */ +static ManagedType DocumentPrimitiveType{ + "DocumentPrimitive", typeid(DocumentPrimitive), {&StructuredEntityType}}; + +/** * An AnnotationEntity is a span-like instance that is not bound by the elements * of the Structure Tree. An annotation may very well overlap and cross the * limits of StructureEntities. A typical example for AnnotationEntities are @@ -360,6 +377,18 @@ public: }; /** + * A global variable for the ManagedType of an Anchor. + */ +static ManagedType AnchorType{ + "Anchor", typeid(AnnotationEntity::Anchor), {&StructuredEntityType}}; + +/** + * A global variable for the ManagedType of an AnnotationEntity. + */ +static ManagedType AnnotationEntityType{ + "AnnotationEntity", typeid(AnnotationEntity), {&DocumentEntityType}}; + +/** * A Document is mainly a wrapper for the Root structure node of the Document * Graph. */ @@ -378,6 +407,11 @@ public: Rooted<StructuredEntity> getRoot() const { return root; } }; + +/** + * A global variable for the ManagedType of a Document. + */ +static ManagedType DocumentType{"Document", typeid(Document)}; } } diff --git a/src/core/model/Domain.hpp b/src/core/model/Domain.hpp index d0227bd..d19558e 100644 --- a/src/core/model/Domain.hpp +++ b/src/core/model/Domain.hpp @@ -203,10 +203,7 @@ public: // TODO: Is returning a NodeVector alright? NodeVector<StructuredClass> &getChildren() { return children; } - const NodeVector<StructuredClass> &getChildren() const - { - return children; - } + const NodeVector<StructuredClass> &getChildren() const { return children; } FieldType getFieldType() const { return fieldType; } @@ -216,6 +213,12 @@ public: }; /** + * A global variable for the ManagedType of a FieldDescriptor. + */ +static ManagedType FieldDescriptorType{"FieldDescriptor", + typeid(FieldDescriptor)}; + +/** * This is a super class for StructuredClasses and AnnotationClasses and is, * in itself, not supposed to be instantiated. It defines that both, Annotations * and StructuredEntities, may have attributes and fields. For more information @@ -280,6 +283,11 @@ public: } }; +/** + * A global variable for the ManagedType of a Descriptor. + */ +static ManagedType DescriptorType{"Descriptor", typeid(Descriptor)}; + typedef RangeSet<size_t> Cardinality; /** @@ -397,6 +405,12 @@ public: }; /** + * A global variable for the ManagedType of a StructuredClass. + */ +static ManagedType StructuredClassType{ + "StructuredClass", typeid(StructuredClass), {&DescriptorType}}; + +/** * An AnnotationClass defines allowed Annotations. For more information on * Annotations please refer to the Document.hpp. * @@ -406,6 +420,12 @@ class AnnotationClass : public Descriptor { }; /** + * A global variable for the ManagedType of an AnnotationClass. + */ +static ManagedType AnnotationClassType{ + "AnnotationClass", typeid(AnnotationClass), {&DescriptorType}}; + +/** * A Domain node specifies which StructuredClasses are allowed at the root * level (or which Nonterminals are axioms of the grammar) and which Annotations * are allowed globally. TODO: Do we want to be able to restrict Annotations to @@ -434,10 +454,7 @@ public: } // TODO: Is returning a NodeVector alright? - NodeVector<StructuredClass> &getRootStructures() - { - return rootStructures; - } + NodeVector<StructuredClass> &getRootStructures() { return rootStructures; } const NodeVector<StructuredClass> &getRootStructures() const { @@ -456,11 +473,13 @@ public: NodeVector<Typesystem> &getTypesystems() { return typesystems; } - const NodeVector<Typesystem> &getTypesystems() const - { - return typesystems; - } + const NodeVector<Typesystem> &getTypesystems() const { return typesystems; } }; + +/** + * A global variable for the ManagedType of a Domain. + */ +static ManagedType DomainType{"Domain", typeid(Domain)}; } } diff --git a/test/core/model/DomainTest.cpp b/test/core/model/DomainTest.cpp index f6dff3c..204a862 100644 --- a/test/core/model/DomainTest.cpp +++ b/test/core/model/DomainTest.cpp @@ -28,23 +28,21 @@ namespace ousia { namespace model { void assert_path(std::vector<Rooted<Managed>> &result, size_t idx, - const std::type_info &expected_type, + const ManagedType &expected_type, std::vector<std::string> expected_path) { ASSERT_TRUE(result.size() > idx); // check class/type - ASSERT_EQ(expected_type, typeid(*result[idx])); - // transform to node - Managed *m = &(*result[idx]); - Node *n = dynamic_cast<Node *>(m); - ASSERT_TRUE(n); + ASSERT_TRUE(result[idx]->isa(expected_type)); + // cast to node + Rooted<Node> n = result[idx].cast<Node>(); // extract actual path std::vector<std::string> actual_path = n->path(); // check path ASSERT_EQ(expected_path, actual_path); } -TEST(Document, testDomainResolving) +TEST(Domain, testDomainResolving) { // Construct Manager Manager mgr{1}; @@ -59,9 +57,9 @@ TEST(Document, testDomainResolving) std::vector<Rooted<Managed>> res = domain->resolve(std::vector<std::string>{"book"}); // First we expect the book domain. - assert_path(res, 0, typeid(Domain), {"book"}); + assert_path(res, 0, DomainType, {"book"}); // Then the book structure. - assert_path(res, 1, typeid(StructuredClass), {"book", "book"}); + assert_path(res, 1, StructuredClassType, {"book", "book"}); ASSERT_EQ(2, res.size()); /* @@ -69,7 +67,7 @@ TEST(Document, testDomainResolving) * StructuredClass should be returned. */ res = domain->resolve(std::vector<std::string>{"book", "book"}); - assert_path(res, 0, typeid(StructuredClass), {"book", "book"}); + assert_path(res, 0, StructuredClassType, {"book", "book"}); ASSERT_EQ(1, res.size()); /* @@ -77,7 +75,7 @@ TEST(Document, testDomainResolving) */ res = domain->resolve(std::vector<std::string>{"section"}); // TODO: Is that the path result we want? - assert_path(res, 0, typeid(StructuredClass), {"book", "section"}); + assert_path(res, 0, StructuredClassType, {"book", "section"}); ASSERT_EQ(1, res.size()); /* @@ -85,7 +83,7 @@ TEST(Document, testDomainResolving) * FieldDescriptor of the StructuredClass "book". */ res = domain->resolve(std::vector<std::string>{"book", "book", ""}); - assert_path(res, 0, typeid(FieldDescriptor), {"book", "book", ""}); + assert_path(res, 0, FieldDescriptorType, {"book", "book", ""}); ASSERT_EQ(1, res.size()); /* @@ -93,7 +91,7 @@ TEST(Document, testDomainResolving) * but should be returned only once. */ res = domain->resolve("paragraph"); - assert_path(res, 0, typeid(StructuredClass), {"book", "paragraph"}); + assert_path(res, 0, StructuredClassType, {"book", "paragraph"}); ASSERT_EQ(1, res.size()); } } |