smntc
an in-memory multimodal graph database
Loading...
Searching...
No Matches
Textual.c
Go to the documentation of this file.
1#include <stdlib.h>
2#include "errors.h"
3#include "Graph.h"
4#include "Binary.h"
5
6#define CLUSTER_LENGTH 3
7
8struct Textual {
9 unsigned int modality;
10 unsigned int wordType;
11 unsigned int phraseType;
12 struct Binary *binary;
13 struct Graph *graph;
14};
15
16struct Textual *Textual_construct(unsigned int modality, struct Graph *graph, int *error)
17{
18 struct Textual *this = malloc(sizeof(struct Textual));
19
20 if (0 == this) {
21 *error = ERROR_NO_MEMORY;
22 return 0;
23 }
24
25 this->graph = graph;
26 this->modality = modality;
27
28 unsigned int cluster[CLUSTER_LENGTH] = { 0, 0, 0 };
29
30 unsigned int clusterStart = Graph_readLastSource(this->graph, modality, error);
31
32 if (*error) {
33 return 0;
34 }
35
36 if (0 == clusterStart) {
37
38 Graph_addCluster(this->graph, CLUSTER_LENGTH, cluster, error);
39
40 if (*error) {
41 return 0;
42 }
43
44 Graph_addEdge(graph, modality, cluster[0], error);
45
46 if (*error) {
47 return 0;
48 }
49
50 } else {
51
52 Graph_readCluster(this->graph, clusterStart, CLUSTER_LENGTH, cluster, error);
53
54 if (*error) {
55 return 0;
56 }
57
58 }
59
60 this->binary = Binary_construct(cluster[0], this->graph, error);
61
62 if (*error) {
63 return 0;
64 }
65
66 this->wordType = cluster[1];
67 this->phraseType = cluster[2];
68
69 return this;
70}
71
72struct Textual *Textual_destruct(struct Textual *this)
73{
74 if (0 != this) {
76 free(this);
77 }
78
79 return 0;
80}
struct Binary * Binary_destruct(struct Binary *this)
Definition Binary.c:87
struct Binary * Binary_construct(unsigned int root, struct Graph *graph, int *error)
ssssw
Definition Binary.c:42
void Graph_addEdge(struct Graph *this, unsigned int source, unsigned int target, int *error)
It adds a directed edge from a source vertex to a target vertex.
Definition Graph.c:298
unsigned int Graph_readLastSource(const struct Graph *this, unsigned int target, int *error)
It reads the last source vertex of a target vertex, if it exists.
Definition Graph.c:680
void Graph_readCluster(const struct Graph *this, unsigned int predecessor, unsigned int length, unsigned int *vertices, int *error)
Definition Graph.c:776
void Graph_addCluster(struct Graph *this, unsigned int length, unsigned int *vertices, int *error)
Definition Graph.c:744
struct Textual * Textual_destruct(struct Textual *this)
Definition Textual.c:72
#define CLUSTER_LENGTH
Definition Textual.c:6
struct Textual * Textual_construct(unsigned int modality, struct Graph *graph, int *error)
Definition Textual.c:16
#define ERROR_NO_MEMORY
Definition errors.h:5
Definition Graph.c:20
unsigned int phraseType
Definition Textual.c:11
unsigned int wordType
Definition Textual.c:10
struct Graph * graph
Definition Textual.c:13
struct Binary * binary
Definition Textual.c:12
unsigned int modality
Definition Textual.c:9