summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/model/Document.hpp21
-rw-r--r--src/core/model/Ontology.cpp36
-rw-r--r--src/core/model/Syntax.hpp4
-rw-r--r--src/core/parser/stack/Handler.hpp4
4 files changed, 39 insertions, 26 deletions
diff --git a/src/core/model/Document.hpp b/src/core/model/Document.hpp
index 48a291f..1ac913d 100644
--- a/src/core/model/Document.hpp
+++ b/src/core/model/Document.hpp
@@ -138,7 +138,6 @@ class Anchor;
* fields while the inner vector contains all children in this field.
* We provide, however, convenience functions for better access via the field
* name.
- *
*/
class DocumentEntity {
private:
@@ -274,6 +273,7 @@ public:
* FieldDescriptor in the Ontology description.
*/
void addStructureNode(Handle<StructureNode> s, size_t fieldIdx);
+
/**
* This adds a StructureNode to the field with the given name.
*
@@ -305,6 +305,7 @@ public:
*/
void addStructureNodes(const std::vector<Handle<StructureNode>> &ss,
const std::string &fieldName = DEFAULT_FIELD_NAME);
+
/**
* This removes a StructureNode from the field with the given index.
*
@@ -317,6 +318,7 @@ public:
* if was not found.
*/
bool removeStructureNodeFromField(Handle<StructureNode> s, size_t fieldIdx);
+
/**
* This removes a StructureNode from the field with the given name.
*
@@ -378,10 +380,9 @@ public:
* @param s is the StructureNode that shall be removed.
* @param fieldDescriptor is a FieldDescriptor defined in the Descriptor for
* this DocumentEntity.
-
* @return true if this StructureNode was a child here and false if
* if was not found.
- */
+ */
bool removeStructureNodeFromField(Handle<StructureNode> s,
Handle<FieldDescriptor> fieldDescriptor);
@@ -392,10 +393,9 @@ public:
* This method also changes the parent of the removed StructureNode to null.
*
* @param s is the StructureNode that shall be removed.
-
* @return true if this StructureNode was a child here and false if if was
* not found.
- */
+ */
bool removeStructureNode(Handle<StructureNode> s);
/**
@@ -408,7 +408,6 @@ public:
* StructuredEntity shall be added to this DocumentEntity.
* @param name is some name for this StructuredEntity that may be used
* for later reference. It is empty per default.
- *
* @return the newly created StructuredEntity.
*/
Rooted<StructuredEntity> createChildStructuredEntity(
@@ -427,12 +426,12 @@ public:
* StructuredEntity shall be added to this DocumentEntity.
* @param name is some name for this StructuredEntity that may be used
* for later reference. It is empty per default.
- *
* @return the newly created StructuredEntity.
*/
Rooted<StructuredEntity> createChildStructuredEntity(
Handle<StructuredClass> descriptor, size_t fieldIdx,
Variant attributes = Variant::mapType{}, std::string name = "");
+
/**
* Creates a new DocumentPrimitive as child of this DocumentEntity.
*
@@ -442,11 +441,11 @@ public:
* fieldName.
* @param fieldName is the name of the field, where the newly created
* StructuredEntity shall be added to this DocumentEntity.
- *
* @return the newly created DocumentPrimitive.
*/
Rooted<DocumentPrimitive> createChildDocumentPrimitive(
Variant content, const std::string &fieldName = DEFAULT_FIELD_NAME);
+
/**
* Creates a new DocumentPrimitive as child of this DocumentEntity.
*
@@ -456,7 +455,6 @@ public:
* DocumentPrimitive. The Type of this Variant is
* specified at the parents Descriptor for the given
* fieldName.
- *
* @return the newly created DocumentPrimitive.
*/
Rooted<DocumentPrimitive> createChildDocumentPrimitive(Variant content,
@@ -467,7 +465,6 @@ public:
*
* @param fieldName is the name of the field, where the newly created
* Anchor shall be added to this DocumentEntity.
- *
* @return the newly created Anchor.
*/
Rooted<Anchor> createChildAnchor(
@@ -478,7 +475,6 @@ public:
*
* @param fieldIdx is the index of the field, where the newly created
* Anchor shall be added to this DocumentEntity.
- *
* @return the newly created Anchor.
*/
Rooted<Anchor> createChildAnchor(size_t fieldIdx);
@@ -517,6 +513,7 @@ public:
*/
StructureNode(Manager &mgr, std::string name, Handle<Node> parent,
const std::string &fieldName);
+
/**
* Constructor for a StructureNode in the StructureTree.
*/
@@ -748,6 +745,7 @@ public:
: StructureNode(mgr, "", parent, fieldName)
{
}
+
/**
* Constructor for Anchor.
*
@@ -886,6 +884,7 @@ public:
* @param s is the new start Anchor for this AnnotationEntity.
*/
void setStart(Handle<Anchor> s);
+
/**
* Sets the end Anchor of this AnnotationEntity.
*
diff --git a/src/core/model/Ontology.cpp b/src/core/model/Ontology.cpp
index 0341df8..d63c5e7 100644
--- a/src/core/model/Ontology.cpp
+++ b/src/core/model/Ontology.cpp
@@ -30,6 +30,7 @@ namespace ousia {
/* Helper Functions */
+namespace {
struct PathState {
std::shared_ptr<PathState> pred;
Node *node;
@@ -177,21 +178,25 @@ struct CollectState {
CollectState(Node *n, size_t depth) : n(n), depth(depth) {}
};
+/**
+ * TODO: @Benjmin Documentation!
+ */
template <typename F>
static NodeVector<Node> collect(const Node *start, F match)
{
- // result
NodeVector<Node> res;
- // queue for breadth-first search of graph.
+
+ // Queue and set for breadth-first search of the document graph
std::queue<CollectState> q;
- // put the initial node on the stack.
- q.push(CollectState(const_cast<Node *>(start), 0));
- // set of visited nodes.
std::unordered_set<const Node *> visited;
+
+ // Put the start node onto the stack.
+ q.push(CollectState(const_cast<Node *>(start), 0));
while (!q.empty()) {
CollectState state = q.front();
q.pop();
- // do not proceed if this node was already visited.
+
+ // Do not proceed if this node was already visited.
if (!visited.insert(state.n).second) {
continue;
}
@@ -202,11 +207,12 @@ static NodeVector<Node> collect(const Node *start, F match)
// look through all fields.
NodeVector<FieldDescriptor> fields = strct->getFieldDescriptors();
for (auto fd : fields) {
- // note matches.
+ // Store all matching items
if (match(fd, state.depth)) {
res.push_back(fd);
}
- // only continue in the TREE field.
+
+ // Only continue in the TREE field.
if (fd->getFieldType() == FieldDescriptor::FieldType::TREE) {
q.push(CollectState(fd.get(), state.depth));
}
@@ -221,6 +227,7 @@ static NodeVector<Node> collect(const Node *start, F match)
if (match(c, state.depth)) {
res.push_back(c);
}
+
// We only continue our search via transparent children.
if (c->isTransparent()) {
q.push(CollectState(c.get(), state.depth + 1));
@@ -234,7 +241,7 @@ static NodeVector<Node> collect(const Node *start, F match)
static std::vector<SyntaxDescriptor> collectPermittedTokens(
const Node *start, Handle<Ontology> ontology)
{
- // gather SyntaxDescriptors for structure children first.
+ // Gather SyntaxDescriptors for structure children first
std::vector<SyntaxDescriptor> res;
collect(start, [&res](Handle<Node> n, size_t depth) {
SyntaxDescriptor stx;
@@ -243,21 +250,24 @@ static std::vector<SyntaxDescriptor> collectPermittedTokens(
} else {
stx = n.cast<Descriptor>()->getSyntaxDescriptor(depth);
}
- // do not add trivial SyntaxDescriptors.
+
+ // Do not add trivial SyntaxDescriptors
if (!stx.isEmpty()) {
- res.push_back(stx);
+ res.emplace_back(stx);
}
return false;
});
- // gather SyntaxDescriptors for AnnotationClasses.
+
+ // Gather SyntaxDescriptors for AnnotationClasses.
for (auto a : ontology->getAnnotationClasses()) {
SyntaxDescriptor stx = a->getSyntaxDescriptor();
if (!stx.isEmpty()) {
- res.push_back(stx);
+ res.emplace_back(stx);
}
}
return res;
}
+}
/* Class FieldDescriptor */
diff --git a/src/core/model/Syntax.hpp b/src/core/model/Syntax.hpp
index 91b2226..e525224 100644
--- a/src/core/model/Syntax.hpp
+++ b/src/core/model/Syntax.hpp
@@ -39,10 +39,12 @@ struct TokenDescriptor {
* The string content of this token, if it is not a special one.
*/
std::string token;
+
/**
* A flag to be set true if this TokenDescriptor uses a special token.
*/
bool special;
+
/**
* An id to uniquely identify this token.
*/
@@ -120,6 +122,8 @@ struct SyntaxDescriptor {
* Given the current leaf in the parsed document the depth of a
* SyntaxDescriptor is defined as the number of transparent elements that
* would be needed to construct an instance of the referenced descriptor.
+ *
+ * TODO: What do negative values mean?
*/
ssize_t depth;
diff --git a/src/core/parser/stack/Handler.hpp b/src/core/parser/stack/Handler.hpp
index 17c91d8..9355e09 100644
--- a/src/core/parser/stack/Handler.hpp
+++ b/src/core/parser/stack/Handler.hpp
@@ -370,8 +370,8 @@ public:
* <li>The token marks the end of some element that is unknown the calling
* code. So the operation itself was a success, but the calling code
* should not call the "end" method.
- * <li>The token did not anything in this context. Basically this shuold
- * never happen, but who knows.</li>
+ * <li>The token did not match anything in this context. Basically this
+ * should never happen, but who knows.</li>
* </ol>
*
* @param id is the Token for which the handler should be started.