1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
/*
* Copyright (C) 2009, Nokia <ivan.frade@nokia.com>
*
* 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 2
* 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
#include "ttl_graphviz.h"
#include <glib.h>
#include <glib/gprintf.h>
#include "qname.h"
static void
generate_class_nodes (gpointer key, gpointer value, gpointer user_data)
{
FILE *output = (FILE *)user_data;
OntologyClass *klass = (OntologyClass *)value;
GList *it = NULL;
g_fprintf (output, "\t \"%s\" [fillcolor=\"greenyellow\"];\n",
qname_to_shortname (klass->classname));
for (it = klass->superclasses; it != NULL; it = it->next) {
g_fprintf (output,
"\t \"%s\" -> \"%s\" [arrowhead=\"empty\"];\n",
qname_to_shortname (klass->classname),
qname_to_shortname (it->data));
}
}
static void
generate_property_edges (gpointer key, gpointer value, gpointer user_data)
{
FILE *output = (FILE *)user_data;
OntologyProperty *prop = (OntologyProperty *)value;
static gint counter = 0;
g_assert (g_list_length (prop->domain) == 1);
g_assert (g_list_length (prop->range) == 1);
if (qname_is_basic_type (prop->range->data)) {
/*
"_str_1" [label="_str_", shape="box"];
"nfo:Video" -> "_str_1" [label="name"];
*/
g_fprintf (output,
"\t \"_str_%d\" [label=\"%s\", shape=\"box\", fontsize=\"8\", height=\"0.2\"];\n",
counter,
qname_to_shortname (prop->range->data));
g_fprintf (output,
"\t \"%s\" -> \"_str_%d\" [label=\"%s\"];\n",
qname_to_shortname (prop->domain->data),
counter,
qname_to_shortname (prop->propertyname));
counter += 1;
} else {
g_fprintf (output,
"\t \"%s\" -> \"%s\" [label=\"%s\"];\n",
qname_to_shortname (prop->domain->data),
qname_to_shortname (prop->range->data),
qname_to_shortname (prop->propertyname));
}
}
void
ttl_graphviz_print (OntologyDescription *description,
Ontology *ontology,
FILE *output)
{
qname_init (description->baseUrl, description->localPrefix, NULL);
g_fprintf (output, "digraph \"%s\" {\n", description->title);
g_fprintf (output, " label=\"%s\";\n", description->title);
g_fprintf (output, " rankdir=BT;\n");
g_fprintf (output, " node [style=filled];\n");
g_hash_table_foreach (ontology->classes,
generate_class_nodes,
output);
g_hash_table_foreach (ontology->properties,
generate_property_edges,
output);
g_fprintf (output, "}\n");
}
|