diff options
Diffstat (limited to 'docs/tools/tracker-utils.c')
-rw-r--r-- | docs/tools/tracker-utils.c | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/docs/tools/tracker-utils.c b/docs/tools/tracker-utils.c index 498ff4a4a..15eb5f448 100644 --- a/docs/tools/tracker-utils.c +++ b/docs/tools/tracker-utils.c @@ -396,3 +396,128 @@ class_get_parent_hierarchy_strings (TrackerOntologyClass *klass, return strings; } + +static gchar * +link_from_shortname (const gchar *shortname) +{ + const gchar *sep; + gchar *link, *prefix; + + sep = strstr (shortname, ":"); + g_assert (sep != NULL); + + prefix = g_strndup (shortname, sep - shortname); + link = g_strdup_printf ("%s-ontology.html#%s", prefix, shortname); + g_free (prefix); + + return link; +} + +static void +describe_class (FILE *f, + TrackerOntologyModel *model, + TrackerOntologyClass *klass, + gboolean link) +{ + g_fprintf (f, "node [shape=\"box\", style=\"rounded\", border=\"0\", fontname=\"sans-serif\""); + + if (link) { + g_autofree gchar *link = NULL; + + link = link_from_shortname (klass->shortname); + g_fprintf (f, ", class=\"link\", href=\"%s\"", link); + } + + g_fprintf (f, "]; \"%s\"\n", klass->shortname); +} + +static void +print_superclasses (FILE *f, + TrackerOntologyModel *model, + TrackerOntologyClass *klass, + GHashTable *visited, + gboolean link) +{ + GList *l; + + if (g_hash_table_contains (visited, klass)) + return; + + describe_class (f, model, klass, link); + + for (l = klass->superclasses; l; l = l->next) { + TrackerOntologyClass *superclass; + + superclass = tracker_ontology_model_get_class (model, l->data); + print_superclasses (f, model, superclass, visited, TRUE); + g_fprintf (f, "\"%s\" -- \"%s\"\n", superclass->shortname, klass->shortname); + } + + g_hash_table_add (visited, klass); +} + +static void +ttl_generate_class_hierarchy_dot (TrackerOntologyDescription *description, + TrackerOntologyModel *model, + TrackerOntologyClass *klass, + GFile *output_location) +{ + gchar *path, *filename; + GFile *file; + g_autoptr(GHashTable) visited = NULL; + FILE *f; + GList *l; + + if (!klass->subclasses && !klass->superclasses) + return; + + filename = g_strdup_printf ("%s-hierarchy.dot", klass->shortname); + file = g_file_get_child (output_location, filename); + g_free (filename); + + path = g_file_get_path (file); + f = fopen (path, "w"); + g_assert (f != NULL); + g_free (path); + + g_fprintf (f, "graph G {\n"); + g_fprintf (f, "bgcolor=\"transparent\";\n"); + g_fprintf (f, "rankdir=TB;\n"); + + visited = g_hash_table_new (NULL, NULL); + + print_superclasses (f, model, klass, visited, FALSE); + + for (l = klass->subclasses; l; l = l->next) { + TrackerOntologyClass *subclass; + + subclass = tracker_ontology_model_get_class (model, l->data); + describe_class (f, model, subclass, TRUE); + g_fprintf (f, "\"%s\" -- \"%s\"\n", klass->shortname, subclass->shortname); + } + + g_fprintf (f, "}"); + + g_object_unref (file); + fclose (f); +} + +void +ttl_generate_dot_files (TrackerOntologyDescription *description, + TrackerOntologyModel *model, + const gchar *prefix, + GFile *output_location) +{ + g_autoptr(GList) classes = NULL; + GList *l; + + classes = tracker_ontology_model_list_classes (model, prefix); + + for (l = classes; l; l = l->next) { + TrackerOntologyClass *klass; + + klass = tracker_ontology_model_get_class (model, l->data); + + ttl_generate_class_hierarchy_dot (description, model, klass, output_location); + } +} |