From 1cb5fdc15c5f8399ca08377eb498f7c27c2eee85 Mon Sep 17 00:00:00 2001 From: Benjamin Paassen Date: Thu, 6 Mar 2014 11:54:40 +0000 Subject: reworked the model classes according to manipulated GraphNode and removed some bugs resulting from a misunderstanding between abtract domain declarations and instances. git-svn-id: file:///var/local/svn/basicwriter@29 daaaf23c-2e50-4459-9457-1e69db5a47bf --- CMakeLists.txt | 11 ++++++ src/model/GraphNode.hpp | 3 +- src/model/RangeSet.hpp | 1 + src/model/domain/Annotation.cpp | 2 + src/model/domain/Annotation.hpp | 46 +++++++--------------- src/model/domain/Class.hpp | 68 +++++++++++++++++++++++++++++--- src/model/domain/ClassReferenceSet.hpp | 72 ++++++++++++++++++++++++++++++++++ src/model/domain/ClassSet.hpp | 33 ---------------- src/model/domain/Domain.cpp | 3 +- src/model/domain/Domain.hpp | 34 ++++++++-------- src/model/domain/Field.cpp | 2 + src/model/domain/Field.hpp | 23 +++-------- src/model/domain/Layer.hpp | 36 +++++++++++------ src/model/domain/Structure.cpp | 2 + src/model/domain/Structure.hpp | 22 +++++++++-- src/model/types/Type.hpp | 10 ++--- src/model/types/Value.hpp | 6 +-- test/model/GraphNode.cpp | 4 +- 18 files changed, 244 insertions(+), 134 deletions(-) create mode 100644 src/model/domain/ClassReferenceSet.hpp delete mode 100644 src/model/domain/ClassSet.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 26d695b..062d224 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -59,6 +59,17 @@ INCLUDE_DIRECTORIES( ADD_LIBRARY(ousia_model src/model/GraphNode src/model/domain/Domain + src/model/domain/Structure + src/model/domain/ClassCategory + src/model/domain/Class + src/model/domain/ClassReferenceSet + src/model/domain/ClassReference + src/model/domain/Layer + src/model/domain/AnnotationReference + src/model/domain/Field + src/model/domain/AnnotationCategory + src/model/domain/Annotation + src/model/types/Type ) # ousia_xml library (containing the XML serialization/deserializing code for the diff --git a/src/model/GraphNode.hpp b/src/model/GraphNode.hpp index 8ce1a39..73d26a0 100644 --- a/src/model/GraphNode.hpp +++ b/src/model/GraphNode.hpp @@ -26,8 +26,7 @@ namespace ousia { namespace model { enum class GraphNodeType { - None, Domain, Class, Annotation, Structure, ClassCategory, - AnnotationCategory + Domain, Class, Annotation, Structure, ClassCategory, AnnotationCategory }; class GraphNode { diff --git a/src/model/RangeSet.hpp b/src/model/RangeSet.hpp index e6e60e0..ef86363 100644 --- a/src/model/RangeSet.hpp +++ b/src/model/RangeSet.hpp @@ -20,6 +20,7 @@ #define _OUSIA_MODEL_RANGE_SET_HPP_ #include +#include namespace ousia { namespace model { diff --git a/src/model/domain/Annotation.cpp b/src/model/domain/Annotation.cpp index 8dabf5e..42e6ce8 100644 --- a/src/model/domain/Annotation.cpp +++ b/src/model/domain/Annotation.cpp @@ -19,10 +19,12 @@ #include namespace ousia { +namespace model { namespace domain { //This class is fully defined by its header. } } +} diff --git a/src/model/domain/Annotation.hpp b/src/model/domain/Annotation.hpp index 233b421..0e84d1c 100644 --- a/src/model/domain/Annotation.hpp +++ b/src/model/domain/Annotation.hpp @@ -16,22 +16,22 @@ along with this program. If not, see . */ -#ifndef _ANNOTATION_HPP_ -#define _ANNOTATION_HPP_ +#ifndef _OUSIA_MODEL_DOMAIN_ANNOTATION_HPP_ +#define _OUSIA_MODEL_DOMAIN_ANNOTATION_HPP_ #include +#include #include #include -#include -#include -#include +#include "Structure.hpp" +#include "Field.hpp" namespace ousia { +namespace model { namespace domain { //class Structure; -//class Anchor; //class Field; class Annotation : public GraphNode { @@ -39,11 +39,15 @@ class Annotation : public GraphNode { private: std::vector> structures; std::vector> fields; - std::shared_ptr start; - std::shared_ptr end; public: - using GraphNode::GraphNode; + + Annotation(std::shared_ptr parent = nullptr, + const std::string &name = "") : + GraphNode(GraphNodeType::Annotation, parent, name) + { + // Do nothing here + } std::vector>& getStructures() { @@ -54,28 +58,8 @@ public: { return fields; } - - std::shared_ptr getStart() - { - return start; - } - - void setStart(std::shared_ptr start) - { - this->start = start; - } - - std::shared_ptr getEnd() - { - return end; - } - - void setEnd(std::shared_ptr end) - { - this->end = end; - } }; } } - -#endif /* _ANNOTATION_HPP_ */ +} +#endif /* _OUSIA_MODEL_DOMAIN_ANNOTATION_HPP_ */ diff --git a/src/model/domain/Class.hpp b/src/model/domain/Class.hpp index 231bb80..6100214 100644 --- a/src/model/domain/Class.hpp +++ b/src/model/domain/Class.hpp @@ -16,26 +16,84 @@ along with this program. If not, see . */ -#ifndef _CLASS_HPP_ -#define _CLASS_HPP_ +#ifndef _OUSIA_MODEL_DOMAIN_CLASS_HPP_ +#define _OUSIA_MODEL_DOMAIN_CLASS_HPP_ #include +#include #include #include +#include "ClassReferenceSet.hpp" +#include "Field.hpp" +#include "Layer.hpp" namespace ousia { +namespace model { namespace domain { +/** + * A class represents some semantic concept in a given domain that has + * structural relevance, like headings in a text. Classes are usually expected + * to be in a "tree-esque" structure: It is not really a tree, but we still + * think about classes as nodes with children, even though children might be + * nodes higher up the tree, which leads to cycles. + */ class Class : public GraphNode { private: - std::vector> children; -}; + std::vector> children; + std::vector> fields; + std::vector> layers; + +public: + + Class(std::shared_ptr parent = nullptr, + const std::string &name = "") : + GraphNode(GraphNodeType::Class, parent, name) + { + // Do nothing here + } + + /** + * The children of a given class are not resolved on parsing time but lazily + * during document creation and validation time. This circumvents some + * problems we would have otherwise like: How do we treat the case that + * merging two domains adds more possible classes to some given category? + * How do we treat references to linked domains? + * + * Thus we do not specify the children that are allowed but a sequence of + * sets that define what set of classes is allowed at each point in the + * children sequence. Please note that each ClassReferenceSet also stores + * a cardinality, how many children, that are members of this set, have to + * exist. Therefore this construction can be interpreted as a quasi finite + * state automaton, e.g.: + * + * (class1|class2)* (class3){1,4} + */ + std::vector>& getChildren() + { + return children; + } + std::vector>& getFields() + { + return fields; + } + + /** + * Layers specify the annotations that are allowed upon instances of this + * class and its children. + */ + std::vector>& getLayers() + { + return layers; + } +}; +} } } -#endif /* _CLASS_HPP_ */ +#endif /* _OUSIA_MODEL_DOMAIN_CLASS_HPP_ */ diff --git a/src/model/domain/ClassReferenceSet.hpp b/src/model/domain/ClassReferenceSet.hpp new file mode 100644 index 0000000..61db014 --- /dev/null +++ b/src/model/domain/ClassReferenceSet.hpp @@ -0,0 +1,72 @@ +/* + Ousía + Copyright (C) 2014 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 _OUSIA_MODEL_DOMAIN_CLASSREFERENCESET_HPP_ +#define _OUSIA_MODEL_DOMAIN_CLASSREFERENCESET_HPP_ + +#include "ClassReference.hpp" +#include + +namespace ousia { +namespace model { +namespace domain { + +/** + * A ClassReferenceSet lazily defines references to classes that are allowed at + * this point of the domain description. It specifies a set in a twofold meaning: + * 1.) It defines the set of classes, that are allowed. + * 2.) It defines how many instances of those classes have to be instantiated + * in a document that implements this domain standard (cardinality). + */ +class ClassReferenceSet { + +private: + std::vector> conjunctions; + std::shared_ptr> cardinality; + +public: + + /** + * This defines the conjunctions of references to classes that are allowed + * Please note that each ClassReference again does not have to reference to + * a single class but can also reference to multiple classes in a * + * expression. + */ + std::vector>& getConjunctions() + { + return conjunctions; + } + + std::shared_ptr> getCardinality() + { + return cardinality; + } + + void setCardinality(std::shared_ptr>) + { + this->cardinality = cardinality; + } + +}; + +} +} +} + +#endif /* _OUSIA_MODEL_DOMAIN_CLASSREFERENCESET_HPP_ */ + diff --git a/src/model/domain/ClassSet.hpp b/src/model/domain/ClassSet.hpp deleted file mode 100644 index ebfe508..0000000 --- a/src/model/domain/ClassSet.hpp +++ /dev/null @@ -1,33 +0,0 @@ -/* - Ousía - Copyright (C) 2014 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 . -*/ - -namespace ousia { -namespace domain { - -#include "Class.hpp"; - -class ClassSet { - -private: - std::vector classes; - -}; - -} -} - diff --git a/src/model/domain/Domain.cpp b/src/model/domain/Domain.cpp index 3def24b..9b27e3a 100644 --- a/src/model/domain/Domain.cpp +++ b/src/model/domain/Domain.cpp @@ -19,8 +19,9 @@ #include "Domain.hpp" namespace ousia { +namespace model { namespace domain { } } - +} diff --git a/src/model/domain/Domain.hpp b/src/model/domain/Domain.hpp index 957ae4a..278adc5 100644 --- a/src/model/domain/Domain.hpp +++ b/src/model/domain/Domain.hpp @@ -19,16 +19,16 @@ #ifndef _OUSIA_MODEL_DOMAIN_DOMAIN_HPP_ #define _OUSIA_MODEL_DOMAIN_DOMAIN_HPP_ -//#include -//#include -//#include +#include +#include +#include #include -//#include "Class.hpp" -//#include "Structure.hpp" -//#include "Category.hpp" -//#include "Layer.hpp" +#include "Structure.hpp" +#include "ClassCategory.hpp" +#include "AnnotationCategory.hpp" +#include "ClassReferenceSet.hpp" namespace ousia { namespace model { @@ -37,10 +37,10 @@ namespace domain { class Domain : public GraphNode { private: -// std::shared_ptr root; -// std::vector> structures; -// std::vector> categories; -// std::vector> layers; + std::shared_ptr root; + std::vector> structures; + std::vector> classCategories; + std::vector> annotationCategories; public: @@ -51,7 +51,7 @@ public: // Do nothing here } -/* std::shared_ptr& getRoot() + std::shared_ptr& getRoot() { return root; } @@ -61,15 +61,15 @@ public: return structures; } - std::vector>& getCategories() + std::vector>& getClassCategories() { - return categories; + return classCategories; } - std::vector>& getLayers() + std::vector>& getAnnotationCategories() { - return layers; - }*/ + return annotationCategories; + } }; diff --git a/src/model/domain/Field.cpp b/src/model/domain/Field.cpp index 4fd06a3..af7f81e 100644 --- a/src/model/domain/Field.cpp +++ b/src/model/domain/Field.cpp @@ -19,9 +19,11 @@ #include namespace ousia { +namespace model { namespace domain { //This class is fully specified by its header. } } +} diff --git a/src/model/domain/Field.hpp b/src/model/domain/Field.hpp index d1944ee..293a361 100644 --- a/src/model/domain/Field.hpp +++ b/src/model/domain/Field.hpp @@ -16,29 +16,27 @@ along with this program. If not, see . */ -#ifndef _FIELD_HPP_ -#define _FIELD_HPP_ +#ifndef _OUSIA_MODEL_DOMAIN_FIELD_HPP_ +#define _OUSIA_MODEL_DOMAIN_FIELD_HPP_ #include #include #include -#include -namespace ousia { +namespace ousia{ //namespace types { // class Type; // class Value; //} - +namespace model { namespace domain { class Field : public GraphNode { private: std::shared_ptr type; - std::shared_ptr value; bool optional; public: @@ -54,16 +52,6 @@ public: this->type = type; } - std::shared_ptr getValue() - { - return value; - } - - void setValue(std::shared_ptr value) - { - this->value = value; - } - bool getOptional() { return optional; @@ -76,5 +64,6 @@ public: }; } } +} -#endif /* _FIELD_HPP_ */ +#endif /* _OUSIA_MODEL_DOMAIN_FIELD_HPP_ */ diff --git a/src/model/domain/Layer.hpp b/src/model/domain/Layer.hpp index 5d609ca..898c54d 100644 --- a/src/model/domain/Layer.hpp +++ b/src/model/domain/Layer.hpp @@ -16,32 +16,42 @@ along with this program. If not, see . */ -#ifndef _LAYER_HPP_ -#define _LAYER_HPP_ +#ifndef _OUSIA_MODEL_DOMAIN_LAYER_HPP_ +#define _OUSIA_MODEL_DOMAIN_LAYER_HPP_ -#include -#include - -#include -#include +#include "AnnotationReference.hpp" namespace ousia { +namespace model { namespace domain { -class Layer : public GraphNode { +/** + * A Layer lazily defines references to annotations that are allowed upon + * certain classes. You can interpret a layer as a ClassReferenceSet minus the + * cardinality. + */ +class Layer { private: - std::vector> annotations; + std::vector> conjunctions; public: - using GraphNode::GraphNode; - std::vector>& getAnnotations() + /** + * This defines the conjunctions of references to annotations that are allowed + * Please note that each AnnotationReference again does not have to reference to + * a single class but can also reference to multiple classes in a * + * expression. + */ + std::vector>& getConjunctions() { - return annotations; + return conjunctions; } }; + } } +} + +#endif /* _OUSIA_MODEL_DOMAIN_LAYER_HPP_ */ -#endif /* _LAYER_HPP_ */ diff --git a/src/model/domain/Structure.cpp b/src/model/domain/Structure.cpp index fd9f3ce..f0f9d1e 100644 --- a/src/model/domain/Structure.cpp +++ b/src/model/domain/Structure.cpp @@ -20,6 +20,7 @@ #include namespace ousia { +namespace model { namespace domain { //This class for now has no special features that would distinguish it @@ -27,3 +28,4 @@ namespace domain { } } +} diff --git a/src/model/domain/Structure.hpp b/src/model/domain/Structure.hpp index 897b265..4f0604a 100644 --- a/src/model/domain/Structure.hpp +++ b/src/model/domain/Structure.hpp @@ -16,18 +16,32 @@ along with this program. If not, see . */ -#ifndef _STRUCTURE_HPP_ -#define _STRUCTURE_HPP_ +#ifndef _OUSIA_MODEL_DOMAIN_STRUCTURE_HPP_ +#define _OUSIA_MODEL_DOMAIN_STRUCTURE_HPP_ + +#include +#include #include namespace ousia { +namespace model { namespace domain { class Structure : public GraphNode { - using GraphNode::GraphNode; + +public: + Structure(std::shared_ptr parent = nullptr, + const std::string &name = "") : + GraphNode(GraphNodeType::Structure, parent, name) + { + // Do nothing here + } + + }; } } +} -#endif /* _STRUCTURE_HPP_ */ +#endif /* _OUSIA_MODEL_DOMAIN_STRUCTURE_HPP_ */ diff --git a/src/model/types/Type.hpp b/src/model/types/Type.hpp index 155f898..c4a9900 100644 --- a/src/model/types/Type.hpp +++ b/src/model/types/Type.hpp @@ -16,18 +16,16 @@ along with this program. If not, see . */ -#ifndef _TYPE_HPP_ -#define _TYPE_HPP_ - -#include +#ifndef _OUSIA_TYPES_TYPE_HPP_ +#define _OUSIA_TYPES_TYPE_HPP_ namespace ousia { namespace types { -class Type : public GraphNode { +class Type { //TODO: THIS IS A DUMMY CLASS DECLARATION }; } } -#endif /* _TYPE_HPP_ */ +#endif /* _OUSIA_TYPES_TYPE_HPP_ */ diff --git a/src/model/types/Value.hpp b/src/model/types/Value.hpp index 3076dd2..ec9f354 100644 --- a/src/model/types/Value.hpp +++ b/src/model/types/Value.hpp @@ -16,8 +16,8 @@ along with this program. If not, see . */ -#ifndef _VALUE_HPP_ -#define _VALUE_HPP_ +#ifndef _OUSIA_TYPES_VALUE_HPP_ +#define _OUSIA_TYPES_VALUE_HPP_ namespace ousia { namespace types { @@ -28,4 +28,4 @@ class Value { }; } } -#endif /* _VALUE_HPP_ */ +#endif /* _OUSIA_TYPES_VALUE_HPP_ */ diff --git a/test/model/GraphNode.cpp b/test/model/GraphNode.cpp index 7f6f2f9..bdb633c 100644 --- a/test/model/GraphNode.cpp +++ b/test/model/GraphNode.cpp @@ -39,9 +39,9 @@ public: TEST(GraphNodeTest, FullyQuallifiedNameTest) { std::shared_ptr nd1{new TestGraphNode( - GraphNodeType::None, nullptr, "node1")}; + GraphNodeType::Domain, nullptr, "node1")}; std::shared_ptr nd2{new TestGraphNode( - GraphNodeType::None, nd1, "node2")}; + GraphNodeType::Domain, nd1, "node2")}; ASSERT_STREQ("node1.node2", nd2->getFullyQualifiedName().c_str()); } -- cgit v1.2.3