summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2014-12-20 15:51:07 +0100
committerAndreas Stöckel <andreas@somweyr.de>2014-12-20 15:51:07 +0100
commit4294735304bb89fe603a9d5f73717a09959d3c8b (patch)
treeb96f62f3e579b799cdfc0e76c755fc2a306590b3
parenta7567d08e4d5869833069ec7211785af350aea88 (diff)
parentf77ec7ae614810bc317c23138279e115f930aa06 (diff)
Merge branch 'master' of somweyr.de:ousia
-rw-r--r--src/core/model/Document.cpp16
-rw-r--r--src/core/model/Document.hpp60
-rw-r--r--src/core/model/Domain.hpp81
-rw-r--r--test/core/model/DomainTest.cpp24
4 files changed, 116 insertions, 65 deletions
diff --git a/src/core/model/Document.cpp b/src/core/model/Document.cpp
index 709981b..497bb43 100644
--- a/src/core/model/Document.cpp
+++ b/src/core/model/Document.cpp
@@ -25,7 +25,7 @@ namespace model {
int DocumentEntity::getFieldDescriptorIndex(const std::string &fieldName)
{
- const ManagedVector<FieldDescriptor> &fds =
+ const NodeVector<FieldDescriptor> &fds =
descriptor->getFieldDescriptors();
unsigned int f = 0;
@@ -57,21 +57,21 @@ int DocumentEntity::getFieldDescriptorIndex(const std::string &fieldName)
return -1;
}
-void DocumentEntity::getField(ManagedVector<StructuredEntity> &res,
+void DocumentEntity::getField(NodeVector<StructuredEntity> &res,
const std::string &fieldName)
{
int f = getFieldDescriptorIndex(fieldName);
if (f < 0) {
- ManagedVector<StructuredEntity> empty{this};
- res = ManagedVector<StructuredEntity>(this);
+ NodeVector<StructuredEntity> empty{this};
+ res = NodeVector<StructuredEntity>(this);
}
res = fields[f];
}
-ManagedVector<StructuredEntity> &DocumentEntity::getField(
+NodeVector<StructuredEntity> &DocumentEntity::getField(
Rooted<FieldDescriptor> fieldDescriptor)
{
- const ManagedVector<FieldDescriptor> &fds =
+ const NodeVector<FieldDescriptor> &fds =
descriptor->getFieldDescriptors();
int f = 0;
for (auto &fd : fds) {
@@ -156,7 +156,7 @@ Rooted<StructuredEntity> StructuredEntity::buildEntity(
return {nullptr};
}
// append the new entity to the right field.
- ManagedVector<StructuredEntity> field{parent};
+ NodeVector<StructuredEntity> field{parent};
parent->getField(field, fieldName);
field.push_back(entity);
@@ -180,7 +180,7 @@ Rooted<DocumentPrimitive> DocumentPrimitive::buildEntity(
return {nullptr};
}
// append the new entity to the right field.
- ManagedVector<StructuredEntity> field{parent};
+ NodeVector<StructuredEntity> field{parent};
parent->getField(field, fieldName);
field.push_back(entity);
diff --git a/src/core/model/Document.hpp b/src/core/model/Document.hpp
index 15a4599..0e0a416 100644
--- a/src/core/model/Document.hpp
+++ b/src/core/model/Document.hpp
@@ -97,7 +97,7 @@ class DocumentEntity : public Node {
private:
Owned<Descriptor> descriptor;
const Variant attributes;
- std::vector<ManagedVector<StructuredEntity>> fields;
+ std::vector<NodeVector<StructuredEntity>> fields;
int getFieldDescriptorIndex(const std::string &fieldName);
@@ -114,7 +114,7 @@ public:
if (!descriptor.isNull()) {
for (size_t f = 0; f < descriptor->getFieldDescriptors().size();
f++) {
- fields.push_back(ManagedVector<StructuredEntity>(this));
+ fields.push_back(NodeVector<StructuredEntity>(this));
}
}
}
@@ -127,7 +127,7 @@ public:
* This allows a direct manipulation of the internal data structure of a
* DocumentEntity and is not recommended. TODO: Delete this?
*/
- std::vector<ManagedVector<StructuredEntity>> &getFields() { return fields; }
+ std::vector<NodeVector<StructuredEntity>> &getFields() { return fields; }
/**
* This returns true if there is a FieldDescriptor in the Descriptor for
@@ -155,7 +155,7 @@ public:
* 2.) the only FieldDescriptor (if only one is specified).
*
* Note that the output of this method might well be ambigous: If no
- * FieldDescriptor matches the given name an empty ManagedVector is
+ * FieldDescriptor matches the given name an empty NodeVector is
* returned. This is also the case, however, if there are no members for an
* existing field. Therefore it is recommended to additionally check the
* output of "hasField" or use the version of this method with
@@ -163,13 +163,13 @@ public:
*
* @param fieldName is the name of the field as specified in the
* FieldDescriptor in the Domain description.
- * @param res is a ManagedVector reference where the result will be
+ * @param res is a NodeVector reference where the result will be
* stored. After using this method the reference will
* either refer to all StructuredEntities in that field. If
* the field is unknown or if no members exist in that
- * field yet, the ManagedVector will be empty.
+ * field yet, the NodeVector will be empty.
*/
- void getField(ManagedVector<StructuredEntity> &res,
+ void getField(NodeVector<StructuredEntity> &res,
const std::string &fieldName = "");
/**
@@ -181,19 +181,24 @@ public:
*
* @param fieldDescriptor is a FieldDescriptor defined in the Descriptor for
* this DocumentEntity.
- * @return a ManagedVector of all StructuredEntities in that field.
+ * @return a NodeVector of all StructuredEntities in that field.
*/
- ManagedVector<StructuredEntity> &getField(
+ NodeVector<StructuredEntity> &getField(
Rooted<FieldDescriptor> fieldDescriptor);
};
/**
+ * 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.
*/
class StructuredEntity : public DocumentEntity {
private:
- ManagedVector<AnnotationEntity> annotations;
+ NodeVector<AnnotationEntity> annotations;
public:
StructuredEntity(Manager &mgr, Handle<Node> parent,
@@ -205,7 +210,7 @@ public:
{
}
- ManagedVector<AnnotationEntity> &getAnnotations() { return annotations; }
+ NodeVector<AnnotationEntity> &getAnnotations() { return annotations; }
/**
* This builds the root StructuredEntity for the given document. It
@@ -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 112f2fa..d19558e 100644
--- a/src/core/model/Domain.hpp
+++ b/src/core/model/Domain.hpp
@@ -135,7 +135,7 @@ public:
enum class FieldType { TREE, SUBTREE, PRIMITIVE };
private:
- ManagedVector<StructuredClass> children;
+ NodeVector<StructuredClass> children;
FieldType fieldType;
Owned<Type> primitiveType;
@@ -200,13 +200,10 @@ public:
{
}
- // TODO: Is returning a ManagedVector alright?
- ManagedVector<StructuredClass> &getChildren() { return children; }
+ // TODO: Is returning a NodeVector alright?
+ NodeVector<StructuredClass> &getChildren() { return children; }
- const ManagedVector<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
@@ -245,7 +248,7 @@ public:
class Descriptor : public Node {
private:
Owned<StructType> attributesDescriptor;
- ManagedVector<FieldDescriptor> fieldDescriptors;
+ NodeVector<FieldDescriptor> fieldDescriptors;
protected:
void doResolve(std::vector<Rooted<Managed>> &res,
@@ -268,18 +271,23 @@ public:
return attributesDescriptor;
}
- // TODO: Is returning a ManagedVector alright?
- ManagedVector<FieldDescriptor> &getFieldDescriptors()
+ // TODO: Is returning a NodeVector alright?
+ NodeVector<FieldDescriptor> &getFieldDescriptors()
{
return fieldDescriptors;
}
- const ManagedVector<FieldDescriptor> &getFieldDescriptors() const
+ const NodeVector<FieldDescriptor> &getFieldDescriptors() const
{
return fieldDescriptors;
}
};
+/**
+ * A global variable for the ManagedType of a Descriptor.
+ */
+static ManagedType DescriptorType{"Descriptor", typeid(Descriptor)};
+
typedef RangeSet<size_t> Cardinality;
/**
@@ -361,7 +369,7 @@ class StructuredClass : public Descriptor {
private:
const Cardinality cardinality;
Owned<StructuredClass> isa;
- ManagedVector<FieldDescriptor> parents;
+ NodeVector<FieldDescriptor> parents;
protected:
void doResolve(std::vector<Rooted<Managed>> &res,
@@ -390,13 +398,19 @@ public:
Rooted<StructuredClass> getIsA() const { return isa; }
- // TODO: Is returning a ManagedVector alright?
- ManagedVector<FieldDescriptor> &getParents() { return parents; }
+ // TODO: Is returning a NodeVector alright?
+ NodeVector<FieldDescriptor> &getParents() { return parents; }
- const ManagedVector<FieldDescriptor> &getParents() const { return parents; }
+ const NodeVector<FieldDescriptor> &getParents() const { return parents; }
};
/**
+ * 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
@@ -413,9 +433,9 @@ class AnnotationClass : public Descriptor {
*/
class Domain : public Node {
private:
- ManagedVector<StructuredClass> rootStructures;
- ManagedVector<AnnotationClass> annotationClasses;
- ManagedVector<Typesystem> typesystems;
+ NodeVector<StructuredClass> rootStructures;
+ NodeVector<AnnotationClass> annotationClasses;
+ NodeVector<Typesystem> typesystems;
protected:
void doResolve(std::vector<Rooted<Managed>> &res,
@@ -433,34 +453,33 @@ public:
{
}
- // TODO: Is returning a ManagedVector alright?
- ManagedVector<StructuredClass> &getRootStructures()
- {
- return rootStructures;
- }
+ // TODO: Is returning a NodeVector alright?
+ NodeVector<StructuredClass> &getRootStructures() { return rootStructures; }
- const ManagedVector<StructuredClass> &getRootStructures() const
+ const NodeVector<StructuredClass> &getRootStructures() const
{
return rootStructures;
}
- ManagedVector<AnnotationClass> &getAnnotationClasses()
+ NodeVector<AnnotationClass> &getAnnotationClasses()
{
return annotationClasses;
}
- const ManagedVector<AnnotationClass> &getAnnotationClasses() const
+ const NodeVector<AnnotationClass> &getAnnotationClasses() const
{
return annotationClasses;
}
- ManagedVector<Typesystem> &getTypesystems() { return typesystems; }
+ NodeVector<Typesystem> &getTypesystems() { return typesystems; }
- const ManagedVector<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());
}
}