From b08c271ca4401ac8e99d49885da600122e5aa398 Mon Sep 17 00:00:00 2001 From: Benjamin Paassen Date: Tue, 16 Dec 2014 15:55:14 +0100 Subject: finished first draft of Document.hpp, but this is not yet compiled nor tested. --- src/core/model/Document.hpp | 101 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) (limited to 'src/core') diff --git a/src/core/model/Document.hpp b/src/core/model/Document.hpp index 925570b..ede07d6 100644 --- a/src/core/model/Document.hpp +++ b/src/core/model/Document.hpp @@ -77,6 +77,7 @@ namespace ousia { namespace model { class StructuredEntity; +class AnnotationEntity; /** * A DocumentEntity is the common superclass for StructuredEntities and @@ -186,6 +187,106 @@ public: ManagedVector &getField( Rooted fieldDescriptor); }; + +/** + * 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 annotations; + +public: + StructuredEntity(Manager &mgr, std::string name = "", Handle parent, + Handle descriptor, Variant attributes) + : DocumentEntity(mgr, std::move(name), parent, descriptor, attributes), + annotations(this) + { + } + + ManagedVector &getAnnotations() { return annotations; } +}; + +/** + * 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. + */ +class DocumentPrimitive : public StructuredEntity { +public: + DocumentPrimitive(Manager &mgr, Handle parent, + Variant content) + : StructuredEntity(mgr, "", parent, nullptr, content) + { + } + + Variant getContent() const { return getAttributes(); } + const Variant& getContent() const { return getAttributes(); } + + // TODO: Override such methods like "getField" to disable them? +} + +/** + * 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 + * the markups "emphasized" and "strong". In HTML like markup languages these + * concepts are handeled as structure elements, like this: + * + * emphasized and strong + * + * which is neither intuitive nor semantically sound. Therefore we take the + * approach of anchoring the Annotation entities in the text like this: + * + * emphasized and strong + * + * + * + * Which signifies that indeed the text "emphasized and" is emphasized, not + * the two text exerpts "emphasized" and "and" separately. + * + */ +class AnnotationEntity : public DocumentEntity { +public: + /** + * An Anchor is an elementary StructuredEntity without any children that + * marks a point in the text content of the document that can later be + * referenced by an AnnotationEntity as it start and end point. + * Please refer to the AnnotationEntity documentation for more information. + */ + class Anchor : public StructuredEntity { + public: + /** + * @param mgr is the Manager instance. + * @param name is the Anchor id. + * @param parent is the parent of this Anchor in the Structure Tree (!), + * not the AnnotationEntity that references this Anchor. + */ + Anchor(Manager &mgr, std::string name = "", + Handle parent) + : StructuredEntity(mgr, name, parent, nullptr, Variant()) + { + } + }; + +private: + Owned start; + Owned end; + +public: + AnnotationEntity(Manager &mgr, std::string name = "", Handle parent, + Handle descriptor, Variant attributes, + Handle start, Handle end) + : DocumentEntity(mgr, std::move(name), parent, descriptor, attributes), + start(acquire(start)), + end(acquire(end)) + { + } + + Rooted getStart() { return start; } + + Rooted getEnd() { return end; } +}; } } -- cgit v1.2.3