summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorCarlos Garnacho <carlos@lanedo.com>2009-12-16 17:45:45 +0100
committerCarlos Garnacho <carlos@lanedo.com>2009-12-16 17:50:20 +0100
commit8110061904d25e2f55c3afb09de09e84f5f822a4 (patch)
tree1c50502bcc3d53936afe3d1088f4500de3ed3144 /utils
parentfad8db3fceb6246d938bcacfd00c957f09846513 (diff)
downloadtracker-8110061904d25e2f55c3afb09de09e84f5f822a4.tar.gz
Autogenerate ontology documentation.
There is now a new gtk-doc reference for ontology, which is created from data/ontologies/*. docs/tools contains the programs to generate both docbook and graphs, these are dumped on docs/reference/ontology, which is compiled afterwards. Documentation generation happens on make, ontology graphs require graphviz and are only generated on distcheck, A base image is committed, so people don't need graphviz to have a peek.
Diffstat (limited to 'utils')
-rw-r--r--utils/Makefile.am1
-rw-r--r--utils/ontology/Makefile.am29
-rwxr-xr-xutils/ontology/generate-ontology.sh5
-rw-r--r--utils/ontology/ontology-graph.c677
-rwxr-xr-xutils/services/gen-doc.sh54
-rw-r--r--utils/services/qname.c229
-rw-r--r--utils/services/qname.h23
-rw-r--r--utils/services/ttl2html.c97
-rw-r--r--utils/services/ttl_html.c312
-rw-r--r--utils/services/ttl_html.h20
-rw-r--r--utils/services/ttl_loader.c363
-rw-r--r--utils/services/ttl_loader.h21
-rw-r--r--utils/services/ttl_model.c123
-rw-r--r--utils/services/ttl_model.h62
14 files changed, 0 insertions, 2016 deletions
diff --git a/utils/Makefile.am b/utils/Makefile.am
index ad3a6ea6b..f10bdbcec 100644
--- a/utils/Makefile.am
+++ b/utils/Makefile.am
@@ -5,5 +5,4 @@ SUBDIRS = \
lyrics \
ontology \
playlists \
- services \
tracker-fts
diff --git a/utils/ontology/Makefile.am b/utils/ontology/Makefile.am
deleted file mode 100644
index b41939191..000000000
--- a/utils/ontology/Makefile.am
+++ /dev/null
@@ -1,29 +0,0 @@
-include $(top_srcdir)/Makefile.decl
-
-noinst_PROGRAMS = ontology-graph
-
-INCLUDES = \
- -DG_LOG_DOMAIN=\"Tracker\" \
- -DTRACKER_COMPILATION \
- -DTOP_SRCDIR=\"$(top_srcdir)\" \
- -I$(top_srcdir)/src \
- $(WARN_CFLAGS) \
- $(GLIB2_CFLAGS) \
- $(GIO_CFLAGS) \
- $(DBUS_CFLAGS)
-
-ontology_graph_SOURCES = \
- ontology-graph.c
-
-ontology_graph_LDADD = \
- $(top_builddir)/src/libtracker-data/libtracker-data.la \
- $(top_builddir)/src/libtracker-common/libtracker-common.la \
- $(DBUS_LIBS) \
- $(GIO_LIBS) \
- $(GLIB2_LIBS)
-
-EXTRA_DIST = generate-ontology.sh
-
-GENERATED_FILES = ontology.png ontology.dot
-
-CLEANFILES = $(GENERATED_FILES) \ No newline at end of file
diff --git a/utils/ontology/generate-ontology.sh b/utils/ontology/generate-ontology.sh
deleted file mode 100755
index 2c5bede0f..000000000
--- a/utils/ontology/generate-ontology.sh
+++ /dev/null
@@ -1,5 +0,0 @@
-#!/bin/sh
-
-./ontology-graph -d ../../data/ontologies -o ontology.dot
-fdp -Tpng -o ontology.png ontology.dot
-rm ontology.dot
diff --git a/utils/ontology/ontology-graph.c b/utils/ontology/ontology-graph.c
deleted file mode 100644
index 89de85663..000000000
--- a/utils/ontology/ontology-graph.c
+++ /dev/null
@@ -1,677 +0,0 @@
-#include <glib-object.h>
-#include <gio/gio.h>
-#include <glib/gprintf.h>
-#include <libtracker-common/tracker-common.h>
-#include <libtracker-data/tracker-sparql-query.h>
-
-#define RDF_PREFIX TRACKER_RDF_PREFIX
-#define RDF_PROPERTY RDF_PREFIX "Property"
-#define RDF_TYPE RDF_PREFIX "type"
-
-#define RDFS_PREFIX TRACKER_RDFS_PREFIX
-#define RDFS_CLASS RDFS_PREFIX "Class"
-#define RDFS_DOMAIN RDFS_PREFIX "domain"
-#define RDFS_RANGE RDFS_PREFIX "range"
-#define RDFS_SUB_CLASS_OF RDFS_PREFIX "subClassOf"
-#define RDFS_SUB_PROPERTY_OF RDFS_PREFIX "subPropertyOf"
-
-#define NRL_PREFIX TRACKER_NRL_PREFIX
-#define NRL_INVERSE_FUNCTIONAL_PROPERTY TRACKER_NRL_PREFIX "InverseFunctionalProperty"
-#define NRL_MAX_CARDINALITY NRL_PREFIX "maxCardinality"
-
-#define TRACKER_PREFIX TRACKER_TRACKER_PREFIX
-
-static gchar *ontology_dir = NULL;
-static gchar *output_file = NULL;
-
-static gint indenting = 0;
-static GList *context = NULL;
-
-enum {
- CONTEXT_GRAPH,
- CONTEXT_SUBGRAPH,
- CONTEXT_PROPERTY
-};
-
-static gchar *colors[] = {
- "#dd0000",
- "#00dd00",
- "#0000dd",
- "#dd00dd",
- "#dddd00",
- "#00dddd",
- "#dddddd"
- "#bb0000",
- "#00bb00",
- "#0000bb",
- "#bb00bb",
- "#bbbb00",
- "#00bbbb",
- "#bbbbbb"
-};
-
-static GOptionEntry entries[] = {
- { "ontology-dir", 'd', 0, G_OPTION_ARG_FILENAME, &ontology_dir,
- "Ontology directory",
- NULL
- },
- { "output", 'o', 0, G_OPTION_ARG_FILENAME, &output_file,
- "File to write the output (default stdout)",
- NULL
- },
- { NULL }
-};
-
-/* Stripped from tracker-data-manager.h */
-static void
-load_ontology_file_from_path (const gchar *ontology_file)
-{
- TrackerTurtleReader *reader;
- GError *error = NULL;
-
- reader = tracker_turtle_reader_new (ontology_file, &error);
- if (error) {
- g_critical ("Turtle parse error: %s", error->message);
- g_error_free (error);
- return;
- }
-
- while (error == NULL && tracker_turtle_reader_next (reader, &error)) {
- const gchar *subject, *predicate, *object;
-
- subject = tracker_turtle_reader_get_subject (reader);
- predicate = tracker_turtle_reader_get_predicate (reader);
- object = tracker_turtle_reader_get_object (reader);
-
- if (g_strcmp0 (predicate, RDF_TYPE) == 0) {
- if (g_strcmp0 (object, RDFS_CLASS) == 0) {
- TrackerClass *class;
-
- if (tracker_ontology_get_class_by_uri (subject) != NULL) {
- g_critical ("%s: Duplicate definition of class %s", ontology_file, subject);
- continue;
- }
-
- class = tracker_class_new ();
- tracker_class_set_uri (class, subject);
- tracker_ontology_add_class (class);
- g_object_unref (class);
- } else if (g_strcmp0 (object, RDF_PROPERTY) == 0) {
- TrackerProperty *property;
-
- if (tracker_ontology_get_property_by_uri (subject) != NULL) {
- g_critical ("%s: Duplicate definition of property %s", ontology_file, subject);
- continue;
- }
-
- property = tracker_property_new ();
- tracker_property_set_uri (property, subject);
- tracker_ontology_add_property (property);
- g_object_unref (property);
- } else if (g_strcmp0 (object, NRL_INVERSE_FUNCTIONAL_PROPERTY) == 0) {
- TrackerProperty *property;
-
- property = tracker_ontology_get_property_by_uri (subject);
- if (property == NULL) {
- g_critical ("%s: Unknown property %s", ontology_file, subject);
- continue;
- }
-
- tracker_property_set_is_inverse_functional_property (property, TRUE);
- } else if (g_strcmp0 (object, TRACKER_PREFIX "Namespace") == 0) {
- TrackerNamespace *namespace;
-
- if (tracker_ontology_get_namespace_by_uri (subject) != NULL) {
- g_critical ("%s: Duplicate definition of namespace %s", ontology_file, subject);
- continue;
- }
-
- namespace = tracker_namespace_new ();
- tracker_namespace_set_uri (namespace, subject);
- tracker_ontology_add_namespace (namespace);
- g_object_unref (namespace);
- }
- } else if (g_strcmp0 (predicate, RDFS_SUB_CLASS_OF) == 0) {
- TrackerClass *class, *super_class;
-
- class = tracker_ontology_get_class_by_uri (subject);
- if (class == NULL) {
- g_critical ("%s: Unknown class %s", ontology_file, subject);
- continue;
- }
-
- super_class = tracker_ontology_get_class_by_uri (object);
- if (super_class == NULL) {
- g_critical ("%s: Unknown class %s", ontology_file, object);
- continue;
- }
-
- tracker_class_add_super_class (class, super_class);
- } else if (g_strcmp0 (predicate, RDFS_SUB_PROPERTY_OF) == 0) {
- TrackerProperty *property, *super_property;
-
- property = tracker_ontology_get_property_by_uri (subject);
- if (property == NULL) {
- g_critical ("%s: Unknown property %s", ontology_file, subject);
- continue;
- }
-
- super_property = tracker_ontology_get_property_by_uri (object);
- if (super_property == NULL) {
- g_critical ("%s: Unknown property %s", ontology_file, object);
- continue;
- }
-
- tracker_property_add_super_property (property, super_property);
- } else if (g_strcmp0 (predicate, RDFS_DOMAIN) == 0) {
- TrackerProperty *property;
- TrackerClass *domain;
-
- property = tracker_ontology_get_property_by_uri (subject);
- if (property == NULL) {
- g_critical ("%s: Unknown property %s", ontology_file, subject);
- continue;
- }
-
- domain = tracker_ontology_get_class_by_uri (object);
- if (domain == NULL) {
- g_critical ("%s: Unknown class %s", ontology_file, object);
- continue;
- }
-
- tracker_property_set_domain (property, domain);
- } else if (g_strcmp0 (predicate, RDFS_RANGE) == 0) {
- TrackerProperty *property;
- TrackerClass *range;
-
- property = tracker_ontology_get_property_by_uri (subject);
- if (property == NULL) {
- g_critical ("%s: Unknown property %s", ontology_file, subject);
- continue;
- }
-
- range = tracker_ontology_get_class_by_uri (object);
- if (range == NULL) {
- g_critical ("%s: Unknown class %s", ontology_file, object);
- continue;
- }
-
- tracker_property_set_range (property, range);
- } else if (g_strcmp0 (predicate, NRL_MAX_CARDINALITY) == 0) {
- TrackerProperty *property;
-
- property = tracker_ontology_get_property_by_uri (subject);
- if (property == NULL) {
- g_critical ("%s: Unknown property %s", ontology_file, subject);
- continue;
- }
-
- if (atoi (object) == 1) {
- tracker_property_set_multiple_values (property, FALSE);
- }
- } else if (g_strcmp0 (predicate, TRACKER_PREFIX "indexed") == 0) {
- TrackerProperty *property;
-
- property = tracker_ontology_get_property_by_uri (subject);
- if (property == NULL) {
- g_critical ("%s: Unknown property %s", ontology_file, subject);
- continue;
- }
-
- if (strcmp (object, "true") == 0) {
- tracker_property_set_indexed (property, TRUE);
- }
- } else if (g_strcmp0 (predicate, TRACKER_PREFIX "transient") == 0) {
- TrackerProperty *property;
-
- property = tracker_ontology_get_property_by_uri (subject);
- if (property == NULL) {
- g_critical ("%s: Unknown property %s", ontology_file, subject);
- continue;
- }
-
- if (g_strcmp0 (object, "true") == 0) {
- tracker_property_set_transient (property, TRUE);
- }
- } else if (g_strcmp0 (predicate, TRACKER_PREFIX "isAnnotation") == 0) {
- TrackerProperty *property;
-
- property = tracker_ontology_get_property_by_uri (subject);
- if (property == NULL) {
- g_critical ("%s: Unknown property %s", ontology_file, subject);
- continue;
- }
-
- if (g_strcmp0 (object, "true") == 0) {
- tracker_property_set_embedded (property, FALSE);
- }
- } else if (g_strcmp0 (predicate, TRACKER_PREFIX "fulltextIndexed") == 0) {
- TrackerProperty *property;
-
- property = tracker_ontology_get_property_by_uri (subject);
- if (property == NULL) {
- g_critical ("%s: Unknown property %s", ontology_file, subject);
- continue;
- }
-
- if (strcmp (object, "true") == 0) {
- tracker_property_set_fulltext_indexed (property, TRUE);
- }
- } else if (g_strcmp0 (predicate, TRACKER_PREFIX "prefix") == 0) {
- TrackerNamespace *namespace;
-
- namespace = tracker_ontology_get_namespace_by_uri (subject);
- if (namespace == NULL) {
- g_critical ("%s: Unknown namespace %s", ontology_file, subject);
- continue;
- }
-
- tracker_namespace_set_prefix (namespace, object);
- }
- }
-
- g_object_unref (reader);
-
- if (error) {
- g_critical ("Turtle parse error: %s", error->message);
- g_error_free (error);
- }
-}
-
-static void
-load_ontology_file (GFile *file)
-{
- gchar *path;
-
- path = g_file_get_path (file);
- load_ontology_file_from_path (path);
- g_free (path);
-}
-
-static gboolean
-load_ontology_dir (GFile *dir)
-{
- GFileEnumerator *enumerator;
- GFileInfo *info;
- GList *files, *f;
- const gchar *name;
-
- enumerator = g_file_enumerate_children (dir,
- G_FILE_ATTRIBUTE_STANDARD_NAME,
- G_FILE_QUERY_INFO_NONE,
- NULL, NULL);
-
- if (!enumerator) {
- return FALSE;
- }
-
- while ((info = g_file_enumerator_next_file (enumerator, NULL, NULL)) != NULL) {
- name = g_file_info_get_name (info);
-
- if (g_str_has_suffix (name, ".ontology")) {
- files = g_list_insert_sorted (files, g_strdup (name),
- (GCompareFunc) g_strcmp0);
- }
-
- g_object_unref (info);
- }
-
- g_object_unref (enumerator);
-
- for (f = files; f; f = f->next) {
- GFile *child;
-
- child = g_file_get_child (dir, f->data);
- load_ontology_file (child);
- g_object_unref (child);
- }
-
- g_list_foreach (files, (GFunc) g_free, NULL);
- g_list_free (files);
-
- return TRUE;
-}
-
-static const gchar *
-snip_name (const gchar *name)
-{
- const gchar *subname;
-
- subname = strchr (name, ':');
- subname++;
-
- return subname;
-}
-
-static gchar *
-get_prefix (const gchar *name)
-{
- const gchar *str;
- gchar *prefix;
-
- str = strchr (name, ':');
- prefix = g_strndup (name, str - name);
-
- return prefix;
-}
-
-static void
-print_string (FILE *f,
- const gchar *format,
- ...)
-{
- va_list args;
-
- va_start (args, format);
-
- if (indenting > 0) {
- g_fprintf (f, "%*s", indenting, " ");
- }
- g_vfprintf (f, format, args);
- g_fprintf (f, "\n");
-
- va_end (args);
-}
-
-static void
-push_context_graph (FILE *f,
- const gchar *name,
- gboolean directed)
-{
- if (directed) {
- print_string (f, "digraph %s {", name);
- } else {
- print_string (f, "graph %s {", name);
- }
-
- indenting += 2;
- context = g_list_prepend (context, GINT_TO_POINTER (CONTEXT_GRAPH));
-}
-
-static void
-push_context_subgraph (FILE *f,
- const gchar *name)
-{
- print_string (f, "subgraph \"%s\" {", name);
- indenting += 2;
- context = g_list_prepend (context, GINT_TO_POINTER (CONTEXT_SUBGRAPH));
-}
-
-static void
-pop_context (FILE *f)
-{
- guint c;
-
- g_assert (context != NULL);
-
- c = GPOINTER_TO_INT (context->data);
- context = g_list_remove (context, context);
-
- indenting -= 2;
- g_assert (indenting >= 0);
-
- switch (c) {
- case CONTEXT_GRAPH:
- case CONTEXT_SUBGRAPH:
- print_string (f, "}\n");
- break;
- case CONTEXT_PROPERTY:
- print_string (f, "];\n");
- break;
- default:
- g_assert_not_reached ();
- }
-
-}
-
-static void
-print_properties (FILE *f,
- const gchar *separator,
- ...)
-{
- va_list args;
- const gchar *prop, *value;
-
- va_start (args, separator);
-
- prop = va_arg (args, gchar *);
-
- while (prop) {
- value = va_arg (args, gchar *);
-
- print_string (f, "%s = \"%s\"%s", prop, value, separator);
-
- prop = va_arg (args, gchar *);
- }
-
- va_end (args);
-}
-
-static void
-print_element (FILE *f,
- const gchar *name,
- gboolean push_property)
-{
- if (push_property) {
- print_string (f, "%s [", name);
- context = g_list_prepend (context, GINT_TO_POINTER (CONTEXT_PROPERTY));
- indenting += 2;
- } else {
- print_string (f, "%s;", name);
- }
-}
-
-static void
-print_relation (FILE *f,
- const gchar *from,
- const gchar *to,
- gboolean directed,
- gboolean push_property)
-{
- if (directed) {
- if (push_property) {
- print_string (f, "%s -> %s [", from, to);
- } else {
- print_string (f, "%s -> %s;", from, to);
- }
- } else {
- if (push_property) {
- print_string (f, "%s -- %s [", from, to);
- } else {
- print_string (f, "%s -- %s;", from, to);
- }
- }
-
- if (push_property) {
- context = g_list_prepend (context, GINT_TO_POINTER (CONTEXT_PROPERTY));
- indenting += 2;
- }
-}
-
-static void
-generate_class_info (FILE *f)
-{
- TrackerClass **classes;
- GHashTable *info;
- guint length, i, j;
- GHashTableIter iter;
- gpointer key, value;
- gint cur_color = 0;
-
- info = g_hash_table_new_full (g_str_hash,
- g_str_equal,
- NULL, NULL);
-
- classes = tracker_ontology_get_classes (&length);
-
- push_context_graph (f, "G", FALSE);
-
- print_properties (f, ";",
- "size", "22,22",
- "shape", "record",
- "ratio", "1.0",
- "concentrate", "true",
- "compound", "true",
- "dim", "10",
- "rankdir", "LR",
- NULL);
-
- for (i = 0; i < length; i++) {
- const gchar *name;
- TrackerClass **superclasses;
- gchar *prefix;
- GList *subgraph_elements;
- gchar *elem_name, *elem_label;
-
- name = snip_name (tracker_class_get_name (classes[i]));
- prefix = get_prefix (tracker_class_get_name (classes[i]));
- superclasses = tracker_class_get_super_classes (classes[i]);
-
- subgraph_elements = g_hash_table_lookup (info, prefix);
- subgraph_elements = g_list_prepend (subgraph_elements, (gpointer) name);
- g_hash_table_replace (info, prefix, subgraph_elements);
-
- elem_name = g_strdup_printf ("%s_%s", prefix, name);
- elem_label = g_strdup_printf ("%s:%s", prefix, name);
-
- print_element (f, elem_name, TRUE);
-
- print_properties (f, ",",
- "label", elem_label,
- "style", "filled",
- NULL);
-
- pop_context (f);
-
- g_free (elem_name);
- g_free (elem_label);
-
- for (j = 0; superclasses[j]; j++) {
- const gchar *super_name;
- gchar *super_prefix;
- gchar *from_name, *to_name;
-
- super_name = snip_name (tracker_class_get_name (superclasses[j]));
- super_prefix = get_prefix (tracker_class_get_name (superclasses[j]));
-
- from_name = g_strdup_printf ("%s_%s", prefix, name);
- to_name = g_strdup_printf ("%s_%s", super_prefix, super_name);
-
- print_relation (f, from_name, to_name, FALSE, TRUE);
- print_properties (f, ",", "dir", "forward", NULL);
-
- if (g_strcmp0 (prefix, super_prefix) != 0) {
- gchar *cluster_from, *cluster_to;
-
- cluster_from = g_strdup_printf ("cluster_%s", prefix);
- cluster_to = g_strdup_printf ("cluster_%s", super_prefix);
-
- print_properties (f, ",",
- "ltail", cluster_from,
- "lhead", cluster_to,
- NULL);
-
- g_free (cluster_from);
- g_free (cluster_to);
- }
-
- pop_context (f);
- g_free (super_prefix);
- }
- }
-
- g_hash_table_iter_init (&iter, info);
-
- while (g_hash_table_iter_next (&iter, &key, &value)) {
- gchar *prefix = key;
- gchar *subgraph_name, *subgraph_label;
- GList *subgraph_elements = value;
-
- subgraph_name = g_strdup_printf ("cluster_%s", prefix);
- subgraph_label = g_strdup_printf ("%s ontology", prefix);
-
- push_context_subgraph (f, subgraph_name);
-
- print_properties (f, ";",
- "label", subgraph_label,
- "fontsize", "30",
- "bgcolor", colors[cur_color],
- NULL);
-
- while (subgraph_elements) {
- gchar *subelement_name;
-
- subelement_name = g_strdup_printf ("%s_%s", prefix, (gchar *) subgraph_elements->data);
- print_element (f, subelement_name, FALSE);
- g_free (subelement_name);
-
- subgraph_elements = subgraph_elements->next;
- }
-
- pop_context (f);
-
- cur_color++;
-
- if (cur_color >= G_N_ELEMENTS (colors)) {
- cur_color = 0;
- }
- }
-
- g_hash_table_destroy (info);
-
- pop_context (f);
-}
-
-int
-main (int argc, char *argv[])
-{
- GOptionContext *context;
- FILE *f = NULL;
- GFile *dir;
-
- g_type_init ();
-
- /* Translators: this messagge will apper immediately after the */
- /* usage string - Usage: COMMAND [OPTION]... <THIS_MESSAGE> */
- context = g_option_context_new ("- Generates graphviz for a TTL file");
-
- /* Translators: this message will appear after the usage string */
- /* and before the list of options. */
- g_option_context_add_main_entries (context, entries, NULL);
- g_option_context_parse (context, &argc, &argv, NULL);
-
- if (!ontology_dir) {
- gchar *help;
-
- g_printerr ("%s\n\n",
- "Ontology dir is mandatory");
-
- help = g_option_context_get_help (context, TRUE, NULL);
- g_option_context_free (context);
- g_printerr ("%s", help);
- g_free (help);
-
- return -1;
- }
-
- if (output_file) {
- f = fopen (output_file, "w");
- } else {
- f = stdout;
- }
- g_assert (f != NULL);
-
- tracker_ontology_init ();
-
- dir = g_file_new_for_commandline_arg (ontology_dir);
- load_ontology_dir (dir);
- g_object_unref (dir);
-
- generate_class_info (f);
-
- tracker_ontology_shutdown ();
-
- fclose (f);
-
- return 0;
-}
diff --git a/utils/services/gen-doc.sh b/utils/services/gen-doc.sh
deleted file mode 100755
index 9882aaa6b..000000000
--- a/utils/services/gen-doc.sh
+++ /dev/null
@@ -1,54 +0,0 @@
-#!/bin/bash
-
-#
-# This script generates the HTML documentation from TTL description
-# for the tracker specific ontologies
-#
-BUILD_DIR="./build/ontologies"
-
-if [ -e $BUILD_DIR ]; then
- echo "Removing old " $BUILD_DIR "directory"
- rm -rf $BUILD_DIR
-fi
-
-echo "Creating new directory"
-mkdir -p $BUILD_DIR
-
-echo "Compiling the tools"
-make
-
-echo "Generating list of classes-properties and files (file-class.cache)"
-if [ -e file-class.cache ]; then
- rm -f file-class.cache ;
-fi
-
-for f in `find ../../data/ontologies -name "*.ontology"` ; do
- TMPNAME=${f%.ontology}
- PREFIX=${TMPNAME#*-}
- grep "^[a-z]\{1,\}\:[a-zA-Z]" $f |awk -v pr=$PREFIX '{print pr " " $1}' >> file-class.cache
-done
-
-echo "Converting all dia diagrams to png"
-for image in `find ../../docs/ontologies -name "*.dia"` ; do
- dia -t png $image -e $BUILD_DIR/$(basename ${image/.dia/.png})
-done
-
-for f in `find ../../data/ontologies -name "*.description"` ; do
- # ../../data/ontologies/XX-aaa.description -> PREFIX=aaa
- TMPNAME=${f%.description}
- PREFIX=${TMPNAME#*-}
- echo "Generating $PREFIX"
- mkdir -p $BUILD_DIR/$PREFIX
- # Copy before because we check in the code if the documentation exists
- if [ -e ../../docs/ontologies/$PREFIX ]; then
- cp -r ../../docs/ontologies/$PREFIX/* $BUILD_DIR/$PREFIX/ ;
- fi
- ./ttl2html -d $f -o $BUILD_DIR/$PREFIX/index.html -l file-class.cache \
- -e ../../docs/ontologies/$PREFIX/explanation.html
-done
-
-echo "Copying resources"
-cp -R resources/ $BUILD_DIR
-cp ../../docs/ontologies/index.html $BUILD_DIR
-
-echo "Visit documentation here: $BUILD_DIR/index.html"
diff --git a/utils/services/qname.c b/utils/services/qname.c
deleted file mode 100644
index c3857aa14..000000000
--- a/utils/services/qname.c
+++ /dev/null
@@ -1,229 +0,0 @@
-#include "qname.h"
-#include <glib/gstdio.h>
-#include <string.h>
-
-//static gchar *local_uri = NULL;
-//static gchar *local_prefix = NULL;
-
-typedef struct {
- gchar *namespace;
- gchar *uri;
-} Namespace;
-
-static GHashTable *class_deffile = NULL;
-
-Namespace NAMESPACES [] = {
- {NULL, NULL}, /* Save this for the local_uri and prefix */
- {"dc", "http://purl.org/dc/elements/1.1/"},
- {"xsd", "http://www.w3.org/2001/XMLSchema#"},
- {"fts", "http://www.tracker-project.org/ontologies/fts#"},
- {"mto", "http://www.tracker-project.org/temp/mto#"},
- {"mlo", "http://www.tracker-project.org/temp/mlo#"},
- {"nao", "http://www.semanticdesktop.org/ontologies/2007/08/15/nao#"},
- {"ncal", "http://www.semanticdesktop.org/ontologies/2007/04/02/ncal#"},
- {"nco", "http://www.semanticdesktop.org/ontologies/2007/03/22/nco#"},
- {"nfo", "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#"},
- {"nid3", "http://www.semanticdesktop.org/ontologies/2007/05/10/nid3#"},
- {"nie", "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#"},
- {"nmm", "http://www.tracker-project.org/temp/nmm#"},
- {"nmo", "http://www.semanticdesktop.org/ontologies/2007/03/22/nmo#"},
- {"nrl", "http://www.semanticdesktop.org/ontologies/2007/08/15/nrl#"},
- {"rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#"},
- {"rdfs", "http://www.w3.org/2000/01/rdf-schema#"},
- {"tracker", "http://www.tracker-project.org/ontologies/tracker#"},
- {NULL, NULL}
-};
-
-
-void
-qname_init (const gchar *luri, const gchar *lprefix, const gchar *class_location)
-{
- g_return_if_fail (luri != NULL);
-
- if (NAMESPACES[0].namespace || NAMESPACES[0].uri) {
- g_warning ("Reinitializing qname_module");
- g_free (NAMESPACES[0].namespace);
- g_free (NAMESPACES[0].uri);
- if (class_deffile) {
- g_hash_table_destroy (class_deffile);
- }
- }
-
- NAMESPACES[0].uri = g_strdup (luri);
- NAMESPACES[0].namespace = (lprefix != NULL ? g_strdup (lprefix) : g_strdup (""));
-
- if (class_location) {
- /* Process a file that contains: dir class pairs by line
- */
- gint i;
- gchar *raw_content = NULL;
- gchar **lines;
- gsize length;
-
- if (!g_file_get_contents (class_location, &raw_content, &length, NULL)) {
- g_error ("Unable to load '%s'", class_location);
- }
-
- class_deffile = g_hash_table_new_full (g_str_hash,
- g_str_equal,
- g_free,
- g_free);
-
- lines = g_strsplit (raw_content, "\n", -1);
- for (i = 0; lines[i] != NULL; i++) {
- if (strlen (lines[i]) < 1) {
- continue;
- }
-
- gchar **pieces = NULL;
-
- pieces = g_strsplit (lines[i], " ", -1);
- g_assert (g_strv_length (pieces) == 2);
- g_hash_table_insert (class_deffile,
- g_strdup(pieces[1]),
- g_strdup(pieces[0]));
- g_strfreev (pieces);
-
- }
- g_strfreev (lines);
- g_free (raw_content);
- }
-
-}
-
-void
-qname_shutdown (void)
-{
- g_free (NAMESPACES[0].namespace);
- NAMESPACES[0].namespace = NULL;
-
- g_free (NAMESPACES[0].uri);
- NAMESPACES[0].uri = NULL;
-
- if (class_deffile) {
- g_hash_table_destroy (class_deffile);
- class_deffile = NULL;
- }
-}
-
-static gchar **
-split_qname (const gchar *qname, GError **error)
-{
- gchar **pieces;
- gint i;
-
- /* Try by '#' */
- pieces = g_strsplit (qname, "#", 2);
- if (g_strv_length (pieces) == 2) {
- return pieces;
- }
- g_strfreev (pieces);
- pieces = NULL;
-
- /* Try by last '/' */
- for (i = strlen (qname); i >= 0; i--) {
- if (qname[i] == '/') {
- pieces = g_new0 (gchar*, 3);
- pieces[0] = g_strndup (qname, i);
- pieces[1] = g_strdup (&qname[i+1]);
- pieces[2] = NULL;
- break;
- }
- }
-
- if (pieces == NULL) {
- g_warning ("Unable to split '%s' in prefix and class", qname);
- }
- return pieces;
-}
-
-gchar *
-qname_to_link (const gchar *qname)
-{
- gchar **pieces;
- gchar *name;
-
- if (NAMESPACES[0].uri) {
-
- /* There is a local URI! */
- if (g_str_has_prefix (qname, NAMESPACES[0].uri)) {
- pieces = split_qname (qname, NULL);
- name = g_strdup_printf ("#%s", pieces[1]);
- g_strfreev (pieces);
- return name;
- }
- }
-
- if (class_deffile) {
- gchar *dir, *shortname;
- shortname = qname_to_shortname (qname);
- dir = g_hash_table_lookup (class_deffile, shortname);
- g_free (shortname);
- if (dir) {
- return g_strdup_printf ("../%s/index.html#%s",
- dir, qname_to_classname (qname));
- }
- }
-
- return g_strdup (qname);
-}
-
-
-gchar *
-qname_to_shortname (const gchar *qname)
-{
- gchar **pieces;
- gchar *name = NULL;
- gint i;
-
- for (i = 0; NAMESPACES[i].namespace != NULL; i++) {
- if (g_str_has_prefix (qname, NAMESPACES[i].uri)) {
-
- pieces = split_qname (qname, NULL);
- name = g_strdup_printf ("%s:%s",
- NAMESPACES[i].namespace,
- pieces[1]);
- g_strfreev (pieces);
- break;
- }
- }
-
- if (!name) {
- return g_strdup (qname);
- } else {
- return name;
- }
-}
-
-gchar *
-qname_to_classname (const gchar *qname) {
-
- gchar *shortname;
- gchar **pieces;
- gchar *classname = NULL;
-
- shortname = qname_to_shortname (qname);
- if (g_strcmp0 (qname, shortname) == 0) {
- return shortname;
- }
- pieces = g_strsplit (shortname, ":", -1);
- g_assert (g_strv_length (pieces) == 2);
-
- classname = g_strdup (pieces[1]);
- g_strfreev (pieces);
- g_free (shortname);
- return classname;
-}
-
-gboolean
-qname_is_basic_type (const gchar *qname)
-{
- gint i;
- /* dc: or xsd: are basic types */
- for (i = 1; NAMESPACES[i].namespace != NULL && i < 3; i++) {
- if (g_str_has_prefix (qname, NAMESPACES[i].uri)) {
- return TRUE;
- }
- }
- return FALSE;
-}
diff --git a/utils/services/qname.h b/utils/services/qname.h
deleted file mode 100644
index 459751621..000000000
--- a/utils/services/qname.h
+++ /dev/null
@@ -1,23 +0,0 @@
-#ifndef __TTL_QNAME_H__
-#define __TTL_QNAME_H__
-
-#include <glib.h>
-
-G_BEGIN_DECLS
-
-void qname_init (const gchar *local_uri,
- const gchar *local_prefix,
- const gchar *class_location);
-void qname_shutdown (void);
-
-gchar * qname_to_link (const gchar *qname);
-gchar * qname_to_shortname (const gchar *qname);
-gchar * qname_to_classname (const gchar *qname);
-
-
-gboolean qname_is_basic_type (const gchar *qname);
-
-
-G_END_DECLS
-
-#endif
diff --git a/utils/services/ttl2html.c b/utils/services/ttl2html.c
deleted file mode 100644
index 6af1293ab..000000000
--- a/utils/services/ttl2html.c
+++ /dev/null
@@ -1,97 +0,0 @@
-#include <glib.h>
-#include <gio/gio.h>
-#include <string.h>
-#include <stdio.h>
-#include "ttl_loader.h"
-#include "ttl_model.h"
-#include "ttl_html.h"
-
-static gchar *desc_file = NULL;
-static gchar *output_file = NULL;
-static gchar *class_location_file = NULL;
-static gchar *explanation_file = NULL;
-
-static GOptionEntry entries[] = {
- { "desc", 'd', 0, G_OPTION_ARG_FILENAME, &desc_file,
- "TTL file with the ontology description and documentation",
- NULL
- },
- { "output", 'o', 0, G_OPTION_ARG_FILENAME, &output_file,
- "File to write the output (default stdout)",
- NULL
- },
- { "links", 'l', 0, G_OPTION_ARG_FILENAME, &class_location_file,
- "File with pairs: (prefix where the class is defined, class)",
- NULL
- },
- { "explanation", 'e', 0, G_OPTION_ARG_FILENAME, &explanation_file,
- "Verbosy explanation file in HTML format to include in the webpage",
- NULL
- },
- { NULL }
-};
-
-gint
-main (gint argc, gchar **argv)
-{
- GOptionContext *context;
- Ontology *ontology = NULL;
- OntologyDescription *description = NULL;
- gchar *ttl_file = NULL;
- gchar *dirname = NULL;
- FILE *f = NULL;
-
- g_type_init ();
-
- /* Translators: this messagge will apper immediately after the */
- /* usage string - Usage: COMMAND [OPTION]... <THIS_MESSAGE> */
- context = g_option_context_new ("- Generates HTML doc for a TTL file");
-
- /* Translators: this message will appear after the usage string */
- /* and before the list of options. */
- g_option_context_add_main_entries (context, entries, NULL);
- g_option_context_parse (context, &argc, &argv, NULL);
-
- if (!desc_file) {
- gchar *help;
-
- g_printerr ("%s\n\n",
- "Description file is mandatory");
-
- help = g_option_context_get_help (context, TRUE, NULL);
- g_option_context_free (context);
- g_printerr ("%s", help);
- g_free (help);
-
- return -1;
- }
-
- if (output_file) {
- f = fopen (output_file, "w");
- } else {
- f = stdout;
- }
- g_assert (f != NULL);
-
- description = ttl_loader_load_description (desc_file);
-
- dirname = g_path_get_dirname (desc_file);
- ttl_file = g_build_filename (dirname,
- description->relativePath,
- NULL);
-
- ontology = ttl_loader_load_ontology (ttl_file);
- g_free (ttl_file);
- g_free (dirname);
-
- ttl_html_print (description, ontology, f, class_location_file, explanation_file);
-
- ttl_loader_free_ontology (ontology);
- ttl_loader_free_description (description);
-
- g_option_context_free (context);
-
- fclose (f);
-
- return 0;
-}
diff --git a/utils/services/ttl_html.c b/utils/services/ttl_html.c
deleted file mode 100644
index 8dc0b6a5c..000000000
--- a/utils/services/ttl_html.c
+++ /dev/null
@@ -1,312 +0,0 @@
-#include "ttl_html.h"
-#include <glib/gprintf.h>
-#include "qname.h"
-
-#define DEFAULT_COPYRIGHT "Copyright &copy; 2009 <a href=\"http://www.nokia.com/\">Nokia</a>"
-#define SIGNALS_DOC "http://live.gnome.org/Tracker/Documentation/SignalsOnChanges"
-
-typedef struct {
- Ontology *ontology;
- OntologyDescription *description;
- FILE *output;
-} CallbackInfo;
-
-
-static void
-print_author (gpointer item, gpointer user_data) {
- FILE *f = (FILE *)user_data;
- g_fprintf (f,"<dd>%s</dd>", (gchar *)item);
-}
-
-static void
-print_reference (gpointer item, gpointer user_data)
-{
- gchar *shortname;
- gchar *link;
- FILE *f = (FILE *)user_data;
-
- shortname = qname_to_shortname ((gchar *)item);
- link = qname_to_link ((gchar *)item);
-
- g_fprintf (f,"<a href=\"%s\">%s</a>, ", link , shortname);
-
- g_free (shortname);
- g_free (link);
-}
-
-
-
-static void
-print_references_list (FILE *f, GList *list)
-{
- g_fprintf (f,"<td>");
- if (list == NULL) {
- g_fprintf (f,"--");
- } else {
- g_list_foreach (list, print_reference, f);
- }
- g_fprintf (f,"</td>");
-}
-
-static void
-print_list (FILE *f, GList *list)
-{
- GList *it;
- gchar *shortname;
-
-
- g_fprintf (f, "<td>");
- for (it = list; it != NULL; it = it->next) {
- shortname = qname_to_shortname ((gchar *)it->data);
- g_fprintf (f, "%s%s", shortname, (it->next ? ", " : ""));
- g_free (shortname);
- }
- g_fprintf (f, "</td>");
-}
-
-static void
-print_deprecated_message (FILE *f)
-{
- g_fprintf (f,"<tr>");
- g_fprintf (f,"<td class=\"deprecated\" colspan=\"2\">This item is deprecated.</td>\n");
- g_fprintf (f,"</tr>\n");
-}
-
-static void
-print_html_header (FILE *f, OntologyDescription *desc)
-{
- g_fprintf (f,"<html>\n");
- g_fprintf (f,"<head>\n");
- g_fprintf (f,"\t<link rel=\"stylesheet\" type=\"text/css\"");
- g_fprintf (f," href=\"../resources/nie-maemo.css\" />\n");
- g_fprintf (f,"<title>%s</title>\n", desc->title);
- g_fprintf (f,"</head>\n");
- g_fprintf (f,"<body>\n");
- g_fprintf (f,"<div class=\"head\">\n");
- g_fprintf (f," <div class=\"nav\">\n");
-
- /* Three logos at the top. Tracker, maemo, nepomuk */
- g_fprintf (f, " <a href=\"http://www.tracker-project.org\">");
- g_fprintf (f, "<img alt=\"Tracker logo\" src=\"../resources/tracker-logo.png\" /></a> \n");
- g_fprintf (f, " <a href=\"http://www.maemo.org\"> <img alt=\"MAEMO logo\" ");
- g_fprintf (f, " src=\"../resources/maemo-logo.gif\" /></a>\n");
- g_fprintf (f, " <a href=\"http://nepomuk.semanticdesktop.org\"> ");
- g_fprintf (f, "<img alt=\"Nepomuk logo\" src=\"../resources/nepomuk-logo.png\"/></a>\n");
-
- g_fprintf (f,"</div>\n");
- g_fprintf (f,"</div>\n");
-
- g_fprintf (f,"<h1>%s</h1>\n", desc->title);
- g_fprintf (f," <dl>\n");
- if (desc->upstream) {
- g_fprintf (f," <dt>Upstream:</dt><dd><a href=\"%s\">Upstream version</a></dd>\n",
- desc->upstream);
- } else {
- g_fprintf (f," <dt>Upstream:</dt><dd>Not available</dd>\n");
- }
- g_fprintf (f," <dt></dt>\n");
- g_fprintf (f," <dt></dt>\n");
- g_fprintf (f, "</dl>\n <dl>\n");
- g_fprintf (f," <dt>Authors:</dt>\n");
- g_list_foreach (desc->authors, print_author, f);
- g_fprintf (f, "</dl>\n <dl>\n");
- g_fprintf (f," <dt>Editors:</dt>\n");
- g_list_foreach (desc->editors, print_author, f);
- if (desc->contributors) {
- g_fprintf (f, "</dl>\n <dl>\n");
- g_fprintf (f," <dt>Contributors:</dt>\n");
- g_list_foreach (desc->contributors, print_author, f);
- }
- g_fprintf (f, "</dl>\n <dl>\n");
- g_fprintf (f," <dt>Changelog:</dt>\n");
- g_fprintf (f," <dd><a href=\"%s\">Tracker changes</a>",
- (desc->gitlog ? desc->gitlog : "#"));
- g_fprintf (f," </dl>\n");
- g_fprintf (f,"</div>\n");
- g_fprintf (f,"<p class=\"copyright\">%s</p>\n",
- (desc->copyright ? desc->copyright : DEFAULT_COPYRIGHT));
-
- g_fprintf (f,"<hr />\n");
-
-}
-
-static void
-print_html_explanation (FILE *f, const gchar *explanation_file)
-{
- gchar *raw_content;
- gint length;
-
- if (explanation_file && g_file_test (explanation_file, G_FILE_TEST_EXISTS)) {
- if (!g_file_get_contents (explanation_file, &raw_content, &length, NULL)) {
- g_error ("Unable to load '%s'", explanation_file );
- }
- g_fprintf (f, "%s", raw_content);
- }
- g_fprintf (f,"<hr />\n");
-
-}
-
-static void
-print_html_footer (FILE *f)
-{
- g_fprintf (f,"</body>\n");
- g_fprintf (f,"</html>\n");
-}
-
-
-static void
-print_ontology_class (gpointer key, gpointer value, gpointer user_data)
-{
- OntologyClass *def = (OntologyClass *)value;
- gchar *name, *anchor;
- FILE *f = (FILE *)user_data;
-
- g_return_if_fail (f != NULL);
-
- name = qname_to_shortname (def->classname);
- anchor = qname_to_link (def->classname);
-
- /* Anchor without initial '#' */
- g_fprintf (f,"<a name=\"%s\">\n", &anchor[1]);
- g_free (anchor);
-
- if (def->deprecated) {
- g_fprintf (f,"<h3 class=\"deprecated\">%s</h3>\n", name);
- g_fprintf (f,"<table class=\"deprecated\">\n");
- print_deprecated_message (f);
- } else {
- g_fprintf (f,"<h3>%s</h3>\n", name);
- g_fprintf (f,"<table class=\"doctable\">\n");
- }
- g_free (name);
-
- g_fprintf (f,"<tr>");
- g_fprintf (f,"<td class=\"rowheader\">Superclasses</td>");
- print_references_list (f, def->superclasses);
- g_fprintf (f,"</tr>\n");
-
- g_fprintf (f,"<tr>");
- g_fprintf (f,"<td class=\"rowheader\">Subclasses</td>");
- print_references_list (f, def->subclasses);
- g_fprintf (f,"</tr>\n");
-
- g_fprintf (f,"<tr>");
- g_fprintf (f,"<td class=\"rowheader\">In domain of</td>");
- print_references_list (f, def->in_domain_of);
- g_fprintf (f,"</tr>\n");
-
- g_fprintf (f,"<tr>");
- g_fprintf (f,"<td class=\"rowheader\">In range of</td>");
- print_references_list (f, def->in_range_of);
- g_fprintf (f,"</tr>\n");
-
- g_fprintf (f,"<tr>");
- g_fprintf (f,"<td class=\"rowheader\">Description</td>");
- g_fprintf (f,"<td>%s</td>\n", (def->description ? def->description : "--"));
- g_fprintf (f,"</tr>\n");
-
- if (def->notify) {
- g_fprintf (f,"<tr>");
- g_fprintf (f,"<td colspan=\"2\">This class <a href=\"%s\">notifies changes</a></td>\n", SIGNALS_DOC);
- g_fprintf (f,"</tr>\n");
- }
-
- if (def->instances) {
- g_fprintf (f,"<tr>");
- g_fprintf (f,"<td class=\"rowheader\">Predefined instances</td>");
- print_list (f, def->instances);
- g_fprintf (f,"</tr>\n");
- }
-
-
- g_fprintf (f,"</table>\n\n");
-
-}
-
-static void
-print_ontology_property (gpointer key, gpointer value, gpointer user_data)
-{
- OntologyProperty *def = (OntologyProperty *)value;
- gchar *name, *anchor;
- FILE *f = (FILE *)user_data;
-
- g_return_if_fail (f != NULL);
-
- name = qname_to_shortname (def->propertyname);
- anchor = qname_to_link (def->propertyname);
-
- /* Anchor without initial '#' */
- g_fprintf (f,"<a name=\"%s\">", &anchor[1]);
- g_free (anchor);
-
- if (def->deprecated) {
- g_fprintf (f,"<h3 class=\"deprecated\">%s</h3>\n", name);
- g_fprintf (f,"<table class=\"deprecated\">\n");
- print_deprecated_message (f);
- } else {
- g_fprintf (f,"<h3>%s</h3>\n", name);
- g_fprintf (f,"<table class=\"doctable\">\n");
- }
- g_free (name);
-
-
- g_fprintf (f,"<tr>");
- g_fprintf (f,"<td class=\"rowheader\">Type</td>");
- print_references_list (f, def->type);
- g_fprintf (f,"</tr>\n");
-
- g_fprintf (f,"<tr>");
- g_fprintf (f,"<td class=\"rowheader\">Domain</td>");
- print_references_list (f, def->domain);
- g_fprintf (f,"</tr>\n");
-
- g_fprintf (f,"<tr>");
- g_fprintf (f,"<td class=\"rowheader\">Range</td>");
- print_references_list (f, def->range);
- g_fprintf (f,"</tr>\n");
-
- g_fprintf (f,"<tr>");
- g_fprintf (f,"<td class=\"rowheader\">Superproperties</td>");
- print_references_list (f, def->superproperties);
- g_fprintf (f,"</tr>\n");
-
- g_fprintf (f,"<tr>");
- g_fprintf (f,"<td class=\"rowheader\">Subproperties</td>");
- print_references_list (f, def->subproperties);
- g_fprintf (f,"</tr>\n");
-
- if (def->max_cardinality) {
- g_fprintf (f,"<tr>");
- g_fprintf (f,"<td class=\"rowheader\">Maximal cardinality</td>");
- g_fprintf (f,"<td>%s</td", def->max_cardinality);
- g_fprintf (f,"</tr>\n");
- }
-
- g_fprintf (f,"<tr>");
- g_fprintf (f,"<td class=\"rowheader\">Description</td>");
- g_fprintf (f,"<td>%s</td>\n", (def->description ? def->description : "--"));
- g_fprintf (f,"</tr>\n");
-
- g_fprintf (f,"</table>\n\n");
-}
-
-
-
-void
-ttl_html_print (OntologyDescription *description,
- Ontology *ontology,
- FILE *f,
- const gchar *class_location_file,
- const gchar *explanation_file)
-{
-
- qname_init (description->baseUrl, description->localPrefix, class_location_file);
- print_html_header (f, description);
- print_html_explanation (f, explanation_file);
- g_fprintf (f,"<h2>Ontology Classes Descriptions</h2>");
- g_hash_table_foreach (ontology->classes, print_ontology_class, f);
- g_fprintf (f,"<h2>Ontology Properties Descriptions</h2>");
- g_hash_table_foreach (ontology->properties, print_ontology_property, f);
-
- print_html_footer (f);
-}
diff --git a/utils/services/ttl_html.h b/utils/services/ttl_html.h
deleted file mode 100644
index b85463c1e..000000000
--- a/utils/services/ttl_html.h
+++ /dev/null
@@ -1,20 +0,0 @@
-#ifndef __TTL_HTML_H__
-#define __TTL_HTML_H__
-
-#include <gio/gio.h>
-#include "ttl_model.h"
-#include <stdio.h>
-
-G_BEGIN_DECLS
-
-void ttl_html_print (OntologyDescription *description,
- Ontology *ontology,
- FILE *output,
- const gchar *class_location,
- const gchar *explanation_file);
-
-
-
-G_END_DECLS
-
-#endif
diff --git a/utils/services/ttl_loader.c b/utils/services/ttl_loader.c
deleted file mode 100644
index d490925d5..000000000
--- a/utils/services/ttl_loader.c
+++ /dev/null
@@ -1,363 +0,0 @@
-#include "ttl_loader.h"
-#include <glib/gstdio.h>
-
-#include <libtracker-data/tracker-sparql-query.h>
-
-/* Ontology classes */
-#define RDFS_CLASS "http://www.w3.org/2000/01/rdf-schema#Class"
-#define RDF_PROPERTY "http://www.w3.org/1999/02/22-rdf-syntax-ns#Property"
-#define RDFS_SUBCLASSOF "http://www.w3.org/2000/01/rdf-schema#subClassOf"
-#define RDFS_TYPE "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"
-#define RDFS_RANGE "http://www.w3.org/2000/01/rdf-schema#range"
-#define RDFS_DOMAIN "http://www.w3.org/2000/01/rdf-schema#domain"
-#define RDFS_COMMENT "http://www.w3.org/2000/01/rdf-schema#comment"
-#define RDFS_LABEL "http://www.w3.org/2000/01/rdf-schema#label"
-#define RDFS_SUBPROPERTYOF "http://www.w3.org/2000/01/rdf-schema#subPropertyOf"
-
-#define NRL_MAX_CARDINALITY "http://www.semanticdesktop.org/ontologies/2007/08/15/nrl#maxCardinality"
-
-/* #define TRACKER_NAMESPACE "http://www.tracker-project.org/ontologies/tracker#Namespace" */
-#define TRACKER_NS "http://www.tracker-project.org/ontologies/tracker#"
-#define TRACKER_NOTIFY TRACKER_NS "notify"
-
-#define NAO_DEPRECATED "http://www.semanticdesktop.org/ontologies/2007/08/15/nao#deprecated"
-
-/* Ontology description */
-#define DSC_PREFIX "http://www.tracker-project.org/temp/dsc#"
-
-#define DSC_ONTOLOGY DSC_PREFIX "Ontology"
-#define DSC_TITLE DSC_PREFIX "title"
-#define DSC_AUTHOR DSC_PREFIX "author"
-#define DSC_EDITOR DSC_PREFIX "editor"
-#define DSC_CONTRIBUTOR DSC_PREFIX "contributor"
-#define DSC_GITLOG DSC_PREFIX "gitlog"
-#define DSC_UPSTREAM DSC_PREFIX "upstream"
-#define DSC_BASEURI DSC_PREFIX "baseUrl"
-#define DSC_RELPATH DSC_PREFIX "relativePath"
-#define DSC_LOCALPREFIX DSC_PREFIX "localPrefix"
-#define DSC_COPYRIGHT DSC_PREFIX "copyright"
-
-static gboolean
-string_to_boolean (const gchar *str) {
- if (!g_strcmp0 (str, "true")) {
- return TRUE;
- } else if (!g_strcmp0 (str, "false")) {
- return FALSE;
- } else {
- g_error ("Unable to map '%s' into boolean", str);
- }
-}
-
-
-static void
-load_in_memory (Ontology *ontology,
- const gchar *turtle_subject,
- const gchar *turtle_predicate,
- const gchar *turtle_object)
-{
- g_return_if_fail (ontology != NULL);
-
- if (!g_strcmp0 (turtle_predicate, RDFS_TYPE)) {
- /* It is a definition of class or property */
- if (!g_strcmp0 (turtle_object, RDFS_CLASS)) {
- g_hash_table_insert (ontology->classes,
- g_strdup (turtle_subject),
- ttl_model_class_new (turtle_subject));
-
- } else if (!g_strcmp0 (turtle_object, RDF_PROPERTY)) {
- g_hash_table_insert (ontology->properties,
- g_strdup (turtle_subject),
- ttl_model_property_new (turtle_subject));
-
- } else {
- /* xxx:a-default-instance a xxx:Class */
- OntologyClass *def;
-
- def = g_hash_table_lookup (ontology->classes, turtle_object);
- if (def) {
- def->instances = g_list_prepend (def->instances,
- g_strdup (turtle_subject));
- }
- /* g_print ("FIXME Ignoring %s %s %s\n",
- turtle_subject, turtle_predicate, turtle_object);
- */
- }
-
- } else if (!g_strcmp0 (turtle_predicate, RDFS_SUBCLASSOF)) {
- /*
- * A subclass of B:
- * - Add B in A->superclasses list
- * - Add A in B->subclasses list (if B is in this ontology!)
- */
- OntologyClass *def;
-
- def = g_hash_table_lookup (ontology->classes, turtle_subject);
- if (!def) {
- g_error ("Something wrong");
- }
-
- def->superclasses = g_list_prepend (def->superclasses,
- g_strdup (turtle_object));
-
- def = g_hash_table_lookup (ontology->classes, turtle_object);
- if (def) {
- def->subclasses = g_list_prepend (def->subclasses,
- g_strdup (turtle_subject));
- }
- } else if (!g_strcmp0 (turtle_predicate, TRACKER_NOTIFY)) {
- /*
- * A tracker:notify TRUE
- */
- OntologyClass *def;
-
- def = g_hash_table_lookup (ontology->classes, turtle_subject);
- if (!def) {
- g_error ("Something wrong");
- }
-
- def->notify = string_to_boolean (turtle_object);
-
- } else if (!g_strcmp0 (turtle_predicate, RDFS_COMMENT)) {
- OntologyClass *klass;
- OntologyProperty *prop;
-
- klass = g_hash_table_lookup (ontology->classes, turtle_subject);
- if (klass) {
- klass->description = g_strdup (turtle_object);
- } else {
- prop = g_hash_table_lookup (ontology->properties, turtle_subject);
- if (prop) {
- prop->description = g_strdup (turtle_object);
- } else {
- g_error ("UHUMMM %s", turtle_subject);
- }
- }
-
- } else if (!g_strcmp0 (turtle_predicate, RDFS_DOMAIN)) {
- /*
- * (prop A) has domain (class B)
- * -> add B in A->domain
- * -> add A in B->in_domain_of (if B is defined in this ontology!)
- */
- OntologyProperty *prop;
- OntologyClass *klass;
-
- prop = g_hash_table_lookup (ontology->properties, turtle_subject);
- if (!prop) {
- g_error ("Strange error in domain (%s doesnt exist!)",
- turtle_subject);
- }
- prop->domain = g_list_prepend (prop->domain, g_strdup (turtle_object));
-
- klass = g_hash_table_lookup (ontology->classes, turtle_object);
- if (klass) {
- klass->in_domain_of = g_list_prepend (klass->in_domain_of,
- g_strdup (turtle_subject));
- }
-
- } else if (!g_strcmp0 (turtle_predicate, RDFS_RANGE)) {
- /*
- * (prop A) has range (class B)
- * -> add B in A->range
- * -> add A in B->in_range_of (if B is defined in this ontology!)
- */
- OntologyProperty *prop;
- OntologyClass *klass;
-
- prop = g_hash_table_lookup (ontology->properties, turtle_subject);
- if (!prop) {
- g_error ("Strange error in domain (%s doesnt exist!)",
- turtle_subject);
- }
- prop->range = g_list_prepend (prop->range, g_strdup (turtle_object));
-
- klass = g_hash_table_lookup (ontology->classes, turtle_object);
- if (klass) {
- klass->in_range_of = g_list_prepend (klass->in_range_of,
- g_strdup (turtle_subject));
- }
- } else if (!g_strcmp0 (turtle_predicate, NRL_MAX_CARDINALITY)) {
- OntologyProperty *prop;
-
- prop = g_hash_table_lookup (ontology->properties, turtle_subject);
- if (!prop) {
- g_error ("Strange error in max cardinality (%s doesnt exist!)",
- turtle_subject);
- }
- prop->max_cardinality = g_strdup (turtle_object);
-
- } else if (!g_strcmp0 (turtle_predicate, RDFS_SUBPROPERTYOF)) {
- /*
- * (prop A) is subproperty of (prop B)
- * -> add B in A->superproperties
- * -> add A in B->subproperties (if B is in this ontology)
- */
- OntologyProperty *propA, *propB;
-
- propA = g_hash_table_lookup (ontology->properties, turtle_subject);
- if (!propA) {
- g_error ("Strange error in subpropertyof (%s doesnt exist!)",
- turtle_subject);
- }
- propA->superproperties = g_list_prepend (propA->superproperties,
- g_strdup (turtle_object));
-
- propB = g_hash_table_lookup (ontology->properties, turtle_object);
- if (propB) {
- propB->subproperties = g_list_prepend (propB->subproperties,
- g_strdup (turtle_subject));
- }
-
- } else if (!g_strcmp0 (turtle_predicate, NAO_DEPRECATED)) {
- /*
- * X nao:deprecated true
- *
- * This can apply to classes OR properties!
- */
- OntologyProperty *prop;
- OntologyClass *klass;
-
- prop = g_hash_table_lookup (ontology->properties, turtle_subject);
- if (prop) {
- prop->deprecated = string_to_boolean (turtle_object);
- } else {
- /* Try with a class */
- klass = g_hash_table_lookup (ontology->classes, turtle_subject);
- if (klass) {
- klass->deprecated = string_to_boolean (turtle_object);
- } else {
- g_error ("'%s' is not a class nor a property!?", turtle_subject);
- }
- }
-
- } else if (!g_strcmp0 (turtle_predicate, RDFS_LABEL)) {
- /* Intentionaly ignored */
- } else {
- /* DEBUG
- g_print ("UNHANDLED %s %s %s\n",
- turtle_subject, turtle_predicate, turtle_object);
- */
- }
-
-}
-
-static void
-load_description (OntologyDescription *desc,
- const gchar *turtle_subject,
- const gchar *turtle_predicate,
- const gchar *turtle_object)
-{
- if (!g_strcmp0 (turtle_predicate, RDFS_TYPE)) {
- g_assert (!g_strcmp0 (turtle_object, DSC_ONTOLOGY));
- } else if (!g_strcmp0 (turtle_predicate, DSC_TITLE)) {
- desc->title = g_strdup (turtle_object);
- } else if (!g_strcmp0 (turtle_predicate, DSC_UPSTREAM)) {
- desc->upstream = g_strdup (turtle_object);
- } else if (!g_strcmp0 (turtle_predicate, DSC_AUTHOR)) {
- desc->authors = g_list_prepend (desc->authors, g_strdup (turtle_object));
- } else if (!g_strcmp0 (turtle_predicate, DSC_EDITOR)) {
- desc->editors = g_list_prepend (desc->editors, g_strdup (turtle_object));
- } else if (!g_strcmp0 (turtle_predicate, DSC_CONTRIBUTOR)) {
- desc->contributors = g_list_prepend (desc->contributors,
- g_strdup (turtle_object));
- } else if (!g_strcmp0 (turtle_predicate, DSC_GITLOG)) {
- desc->gitlog = g_strdup (turtle_object);
- } else if (!g_strcmp0 (turtle_predicate, DSC_BASEURI)) {
- desc->baseUrl = g_strdup (turtle_object);
- } else if (!g_strcmp0 (turtle_predicate, DSC_RELPATH)) {
- desc->relativePath = g_strdup (turtle_object);
- } else if (!g_strcmp0 (turtle_predicate, DSC_LOCALPREFIX)) {
- desc->localPrefix = g_strdup (turtle_object);
- } else if (!g_strcmp0 (turtle_predicate, DSC_COPYRIGHT)) {
- desc->copyright = g_strdup (turtle_object);
- } else {
- g_critical ("Unhandled element %s", turtle_predicate);
- }
-}
-
-
-Ontology *
-ttl_loader_load_ontology (const gchar *ttl_file)
-{
- Ontology *ontology;
-
- ontology = g_new0 (Ontology, 1);
- ontology->classes = g_hash_table_new_full (g_str_hash,
- g_str_equal,
- g_free,
- (GDestroyNotify)ttl_model_class_free);
-
- ontology->properties = g_hash_table_new_full (g_str_hash,
- g_str_equal,
- g_free,
- (GDestroyNotify)ttl_model_property_free);
-
- if (ttl_file) {
- TrackerTurtleReader *reader;
- GError *error = NULL;
-
- reader = tracker_turtle_reader_new (ttl_file, NULL);
-
- while (error == NULL && tracker_turtle_reader_next (reader, &error)) {
- load_in_memory (ontology,
- tracker_turtle_reader_get_subject (reader),
- tracker_turtle_reader_get_predicate (reader),
- tracker_turtle_reader_get_object (reader));
- }
-
- g_object_unref (reader);
-
- if (error) {
- g_message ("Turtle parse error: %s", error->message);
- g_error_free (error);
- }
- } else {
- g_warning ("Unable to open '%s'", ttl_file);
- }
-
- return ontology;
-}
-
-OntologyDescription *
-ttl_loader_load_description (const gchar *filename)
-{
- OntologyDescription *desc;
- TrackerTurtleReader *reader;
- GError *error = NULL;
-
- desc = ttl_model_description_new ();
-
-
- reader = tracker_turtle_reader_new (filename, NULL);
-
- while (error == NULL && tracker_turtle_reader_next (reader, &error)) {
- load_description (desc,
- tracker_turtle_reader_get_subject (reader),
- tracker_turtle_reader_get_predicate (reader),
- tracker_turtle_reader_get_object (reader));
- }
-
- g_object_unref (reader);
-
- if (error) {
- g_message ("Turtle parse error: %s", error->message);
- g_error_free (error);
- }
-
- return desc;
-}
-
-
-void
-ttl_loader_free_ontology (Ontology *ontology)
-{
- g_hash_table_destroy (ontology->classes);
- g_hash_table_destroy (ontology->properties);
- g_free (ontology);
-}
-
-void
-ttl_loader_free_description (OntologyDescription *desc)
-{
- ttl_model_description_free (desc);
-}
diff --git a/utils/services/ttl_loader.h b/utils/services/ttl_loader.h
deleted file mode 100644
index 9fd791ba0..000000000
--- a/utils/services/ttl_loader.h
+++ /dev/null
@@ -1,21 +0,0 @@
-#ifndef __TTL_LOADER_H__
-#define __TTL_LOADER_H__
-
-#include <glib.h>
-#include "ttl_model.h"
-
-G_BEGIN_DECLS
-
-void ttl_loader_init (void);
-void ttl_loader_shutdown (void);
-
-Ontology *ttl_loader_load_ontology (const gchar *filename);
-OntologyDescription *ttl_loader_load_description (const gchar *filename);
-
-void ttl_loader_free_ontology (Ontology *ontology);
-void ttl_loader_free_description (OntologyDescription *desc);
-
-
-G_END_DECLS
-
-#endif /* __TTL_LOADER_H__ */
diff --git a/utils/services/ttl_model.c b/utils/services/ttl_model.c
deleted file mode 100644
index 3510e2ed1..000000000
--- a/utils/services/ttl_model.c
+++ /dev/null
@@ -1,123 +0,0 @@
-#include "ttl_model.h"
-
-OntologyClass *
-ttl_model_class_new (const gchar *classname)
-{
- OntologyClass *def = NULL;
-
- def = g_new0 (OntologyClass, 1);
-
- def->classname = g_strdup (classname);
- def->superclasses = NULL;
- def->subclasses = NULL;
- def->in_domain_of = NULL;
- def->in_range_of = NULL;
- def->description = NULL;
- def->instances = NULL;
- def->notify = FALSE;
- def->deprecated = FALSE;
- return def;
-}
-
-void
-ttl_model_class_free (OntologyClass *def)
-{
- if (def->classname) {
- g_free (def->classname);
- }
-
- g_list_foreach (def->superclasses, (GFunc) g_free, NULL);
- g_list_foreach (def->subclasses, (GFunc) g_free, NULL);
- g_list_foreach (def->in_domain_of, (GFunc) g_free, NULL);
- g_list_foreach (def->in_range_of, (GFunc) g_free, NULL);
-
- if (def->description) {
- g_free (def->description);
- }
- g_list_foreach (def->instances, (GFunc) g_free, NULL);
-
- g_free (def);
-}
-
-OntologyProperty *
-ttl_model_property_new (const gchar *propname)
-{
- OntologyProperty *prop;
-
- prop = g_new0 (OntologyProperty, 1);
-
- prop->propertyname = g_strdup (propname);
- prop->type = NULL;
- prop->domain = NULL;
- prop->range = NULL;
- prop->superproperties = NULL;
- prop->subproperties = NULL;
- prop->max_cardinality = NULL;
- prop->description = NULL;
- prop->deprecated = FALSE;
-
- return prop;
-}
-
-void
-ttl_model_property_free (OntologyProperty *def)
-{
- if (def->propertyname) {
- g_free (def->propertyname);
- }
-
- g_list_foreach (def->type, (GFunc) g_free, NULL);
- g_list_foreach (def->domain, (GFunc) g_free, NULL);
- g_list_foreach (def->range, (GFunc) g_free, NULL);
- g_list_foreach (def->superproperties, (GFunc) g_free, NULL);
- g_list_foreach (def->subproperties, (GFunc) g_free, NULL);
-
- if (def->max_cardinality) {
- g_free (def->max_cardinality);
- }
-
- if (def->description) {
- g_free (def->description);
- }
-
- g_free (def);
-}
-
-OntologyDescription *
-ttl_model_description_new (void)
-{
- OntologyDescription *desc;
-
- desc = g_new0 (OntologyDescription, 1);
- desc->title = NULL;
- desc->authors = NULL;
- desc->editors = NULL;
- desc->contributors = NULL;
- desc->gitlog = NULL;
- desc->upstream = NULL;
- desc->copyright = NULL;
- desc->baseUrl = NULL;
- desc->localPrefix = NULL;
- desc->relativePath = NULL;
- return desc;
-}
-
-void
-ttl_model_description_free (OntologyDescription *desc)
-{
- g_free (desc->title);
-
- g_list_foreach (desc->authors, (GFunc)g_free, NULL);
- g_list_foreach (desc->editors, (GFunc)g_free, NULL);
- g_list_foreach (desc->contributors, (GFunc)g_free, NULL);
-
- g_free (desc->gitlog);
- g_free (desc->upstream);
- g_free (desc->copyright);
-
- g_free (desc->baseUrl);
- g_free (desc->relativePath);
- g_free (desc->localPrefix);
-
- g_free (desc);
-}
diff --git a/utils/services/ttl_model.h b/utils/services/ttl_model.h
deleted file mode 100644
index 927af4470..000000000
--- a/utils/services/ttl_model.h
+++ /dev/null
@@ -1,62 +0,0 @@
-#ifndef __TTL_MODEL_H__
-#define __TTL_MODEL_H__
-
-#include <glib.h>
-
-G_BEGIN_DECLS
-
-typedef struct {
- gchar *classname;
- GList *superclasses;
- GList *subclasses;
- GList *in_domain_of;
- GList *in_range_of;
- gchar *description;
- GList *instances;
- gboolean notify;
- gboolean deprecated;
-} OntologyClass;
-
-typedef struct {
- gchar *propertyname;
- GList *type;
- GList *domain;
- GList *range;
- GList *superproperties;
- GList *subproperties;
- gchar *max_cardinality;
- gchar *description;
- gboolean deprecated;
-} OntologyProperty;
-
-typedef struct {
- gchar *title;
- GList *authors;
- GList *editors;
- GList *contributors;
- gchar *gitlog;
- gchar *upstream;
- gchar *copyright;
- gchar *baseUrl;
- gchar *localPrefix;
- gchar *relativePath;
-} OntologyDescription;
-
-typedef struct {
- GHashTable *classes;
- GHashTable *properties;
-} Ontology;
-
-
-OntologyClass * ttl_model_class_new (const gchar *classname);
-void ttl_model_class_free (OntologyClass *klass);
-
-OntologyDescription *ttl_model_description_new (void);
-void ttl_model_description_free (OntologyDescription *desc);
-
-OntologyProperty *ttl_model_property_new (const gchar *propname);
-void ttl_model_property_free (OntologyProperty *property);
-
-G_END_DECLS
-
-#endif /* __TRACKER_TTL_MODEL_H__ */