diff options
Diffstat (limited to 'docs')
-rw-r--r-- | docs/tools/dsc-ontology.gresource.xml | 5 | ||||
-rw-r--r-- | docs/tools/meson.build | 14 | ||||
-rw-r--r-- | docs/tools/ontology/10-dsc.ontology | 65 | ||||
-rw-r--r-- | docs/tools/tracker-ontology-model.c | 590 | ||||
-rw-r--r-- | docs/tools/tracker-ontology-model.h (renamed from docs/tools/ttl_model.h) | 50 | ||||
-rw-r--r-- | docs/tools/ttl2xml.c | 110 | ||||
-rw-r--r-- | docs/tools/ttl_loader.c | 460 | ||||
-rw-r--r-- | docs/tools/ttl_loader.h | 45 | ||||
-rw-r--r-- | docs/tools/ttl_model.c | 206 | ||||
-rw-r--r-- | docs/tools/ttl_xml.c | 121 | ||||
-rw-r--r-- | docs/tools/ttl_xml.h | 12 | ||||
-rw-r--r-- | docs/tools/ttlresource2xml.c | 181 | ||||
-rw-r--r-- | docs/tools/ttlresource2xml.h | 18 |
13 files changed, 881 insertions, 996 deletions
diff --git a/docs/tools/dsc-ontology.gresource.xml b/docs/tools/dsc-ontology.gresource.xml new file mode 100644 index 000000000..c5f9b176f --- /dev/null +++ b/docs/tools/dsc-ontology.gresource.xml @@ -0,0 +1,5 @@ +<gresources> + <gresource prefix="/org/freedesktop/tracker/doctool"> + <file>ontology/10-dsc.ontology</file> + </gresource> +</gresources> diff --git a/docs/tools/meson.build b/docs/tools/meson.build index e3672fe2c..6e7ad958e 100644 --- a/docs/tools/meson.build +++ b/docs/tools/meson.build @@ -1,11 +1,15 @@ # These tools are used for generating the ontologies documentation. -ttl_loader_files = [ - 'ttl_loader.c', - 'ttl_model.c', +doctool_gresources = gnome.compile_resources('tracker_doctool_gresources', 'dsc-ontology.gresource.xml') + +doctool_files = [ + 'tracker-ontology-model.c', 'ttl_xml.c', + 'ttlresource2xml.c', + 'ttl2xml.c', ] ttl2xml = executable('ttl2xml', - ttl_loader_files, 'ttl2xml.c', 'ttlresource2xml.c', - dependencies: [tracker_data_dep, tracker_sparql_dep]) + doctool_files, + doctool_gresources, + dependencies: [tracker_sparql_dep]) diff --git a/docs/tools/ontology/10-dsc.ontology b/docs/tools/ontology/10-dsc.ontology new file mode 100644 index 000000000..5ff624ad1 --- /dev/null +++ b/docs/tools/ontology/10-dsc.ontology @@ -0,0 +1,65 @@ +# Ontology to load ontology descriptions, coming +# as .description files alongside ontologies. +@prefix dsc: <http://tracker.api.gnome.org/ontology/v3/dsc#> . +@prefix nrl: <http://tracker.api.gnome.org/ontology/v3/nrl#> . +@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . +@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . +@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . + +dsc: a nrl:Namespace, nrl:Ontology ; + nrl:prefix "dsc" ; + nrl:lastModified "2021-05-28T14:00:00Z" . + +dsc:Ontology a rdfs:Class ; + rdfs:subClassOf rdfs:Resource . + +dsc:title a rdf:Property ; + nrl:maxCardinality 1 ; + rdfs:domain dsc:Ontology ; + rdfs:range xsd:string . + +dsc:description a rdf:Property ; + nrl:maxCardinality 1 ; + rdfs:domain dsc:Ontology ; + rdfs:range xsd:string . + +dsc:author a rdf:Property ; + rdfs:domain dsc:Ontology ; + rdfs:range xsd:string . + +dsc:editor a rdf:Property ; + rdfs:domain dsc:Ontology ; + rdfs:range xsd:string . + +dsc:contributor a rdf:Property ; + rdfs:domain dsc:Ontology ; + rdfs:range xsd:string . + +dsc:upstream a rdf:Property ; + nrl:maxCardinality 1 ; + rdfs:domain dsc:Ontology ; + rdfs:range xsd:string . + +dsc:gitlog a rdf:Property ; + nrl:maxCardinality 1 ; + rdfs:domain dsc:Ontology ; + rdfs:range xsd:string . + +dsc:localPrefix a rdf:Property ; + nrl:maxCardinality 1 ; + rdfs:domain dsc:Ontology ; + rdfs:range xsd:string . + +dsc:baseUrl a rdf:Property ; + nrl:maxCardinality 1 ; + rdfs:domain dsc:Ontology ; + rdfs:range xsd:string . + +dsc:relativePath a rdf:Property ; + nrl:maxCardinality 1 ; + rdfs:domain dsc:Ontology ; + rdfs:range xsd:string . + +dsc:copyright a rdf:Property ; + rdfs:domain dsc:Ontology ; + rdfs:range xsd:string . diff --git a/docs/tools/tracker-ontology-model.c b/docs/tools/tracker-ontology-model.c new file mode 100644 index 000000000..c584e47ac --- /dev/null +++ b/docs/tools/tracker-ontology-model.c @@ -0,0 +1,590 @@ +/* + * 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 <libtracker-sparql/tracker-sparql.h> + +#include "tracker-ontology-model.h" + +struct _TrackerOntologyModel +{ + TrackerSparqlConnection *ontology_conn; + TrackerSparqlConnection *desc_conn; + + TrackerSparqlStatement *classes_stmt; + TrackerSparqlStatement *props_stmt; + GHashTable *stmts; + + GHashTable *classes; + GHashTable *properties; + GHashTable *descriptions; +}; + +TrackerOntologyClass * +ttl_model_class_new (const gchar *classname) +{ + TrackerOntologyClass *def = NULL; + + def = g_new0 (TrackerOntologyClass, 1); + def->classname = g_strdup (classname); + + return def; +} + +void +ttl_model_class_free (TrackerOntologyClass *def) +{ + g_free (def->classname); + g_free (def->shortname); + g_free (def->basename); + + g_list_free_full (def->superclasses, (GDestroyNotify) g_free); + g_list_free_full (def->subclasses, (GDestroyNotify) g_free); + g_list_free_full (def->in_domain_of, (GDestroyNotify) g_free); + g_list_free_full (def->in_range_of, (GDestroyNotify) g_free); + + g_free (def->description); + g_free (def->specification); + + g_list_free_full (def->instances, (GDestroyNotify) g_free); + + g_free (def); +} + +TrackerOntologyProperty * +ttl_model_property_new (const gchar *propname) +{ + TrackerOntologyProperty *prop; + + prop = g_new0 (TrackerOntologyProperty, 1); + prop->propertyname = g_strdup (propname); + + return prop; +} + +void +ttl_model_property_free (TrackerOntologyProperty *def) +{ + g_free (def->propertyname); + g_free (def->shortname); + g_free (def->basename); + + g_list_free_full (def->domain, (GDestroyNotify) g_free); + g_list_free_full (def->range, (GDestroyNotify) g_free); + g_list_free_full (def->superproperties, (GDestroyNotify) g_free); + g_list_free_full (def->subproperties, (GDestroyNotify) g_free); + + g_free (def->max_cardinality); + g_free (def->description); + g_free (def->weight); + g_free (def->specification); + g_free (def); +} + +TrackerOntologyDescription * +ttl_model_description_new (void) +{ + TrackerOntologyDescription *desc; + + desc = g_new0 (TrackerOntologyDescription, 1); + + return desc; +} + +void +ttl_model_description_free (TrackerOntologyDescription *desc) +{ + g_free (desc->title); + g_free (desc->description); + + g_list_free_full (desc->authors, (GDestroyNotify) g_free); + g_list_free_full (desc->editors, (GDestroyNotify) g_free); + g_list_free_full (desc->contributors, (GDestroyNotify) g_free); + + 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); +} + +static void +fill_in_list (TrackerSparqlConnection *conn, + TrackerOntologyModel *model, + GList **list, + const gchar *value, + const gchar *query) +{ + TrackerSparqlStatement *stmt; + TrackerSparqlCursor *cursor; + GError *error = NULL; + + stmt = g_hash_table_lookup (model->stmts, query); + if (!stmt) { + stmt = tracker_sparql_connection_query_statement (conn, query, NULL, &error); + g_assert_no_error (error); + g_hash_table_insert (model->stmts, g_strdup (query), stmt); + } + + tracker_sparql_statement_bind_string (stmt, "var", value); + cursor = tracker_sparql_statement_execute (stmt, NULL, &error); + g_assert_no_error (error); + + while (tracker_sparql_cursor_next (cursor, NULL, &error)) { + const gchar *editor = tracker_sparql_cursor_get_string (cursor, 0, NULL); + *list = g_list_prepend (*list, g_strdup (editor)); + } + + g_assert_no_error (error); + g_object_unref (cursor); +} + +static void +tracker_ontology_model_init_classes (TrackerOntologyModel *model) +{ + TrackerOntologyClass *klass; + TrackerSparqlCursor *cursor; + GError *error = NULL; + + cursor = tracker_sparql_connection_query (model->ontology_conn, + "SELECT " + " ?c" + " nrl:classSpecification(?c)" + " rdfs:comment(?c)" + " nrl:notify(?c)" + " nrl:deprecated(?c)" + " (SUBSTR(str(?c), strlen(?o) + 1) AS ?basename)" + " (CONCAT(?prefix, ':', SUBSTR(str(?c), strlen(?o) + 1)) AS ?shortname)" + "{" + " ?c a rdfs:Class ." + " ?o a nrl:Namespace ;" + " nrl:prefix ?prefix ." + " FILTER (STRSTARTS(?c, ?o))" + "}", + NULL, + &error); + g_assert_no_error (error); + + while (tracker_sparql_cursor_next (cursor, NULL, &error)) { + const gchar *class_name; + + class_name = tracker_sparql_cursor_get_string (cursor, 0, NULL); + + klass = ttl_model_class_new (class_name); + klass->specification = g_strdup (tracker_sparql_cursor_get_string (cursor, 1, NULL)); + klass->description = g_strdup (tracker_sparql_cursor_get_string (cursor, 2, NULL)); + klass->notify = tracker_sparql_cursor_get_boolean (cursor, 3); + klass->deprecated = tracker_sparql_cursor_get_boolean (cursor, 4); + klass->basename = g_strdup (tracker_sparql_cursor_get_string (cursor, 5, NULL)); + klass->shortname = g_strdup (tracker_sparql_cursor_get_string (cursor, 6, NULL)); + + fill_in_list (model->ontology_conn, model, &klass->superclasses, class_name, + "SELECT ?super {" + " ~var rdfs:subClassOf ?super" + "} ORDER BY DESC ?super"); + fill_in_list (model->ontology_conn, model, &klass->subclasses, class_name, + "SELECT ?sub {" + " ?sub rdfs:subClassOf ~var" + "} ORDER BY DESC ?sub"); + fill_in_list (model->ontology_conn, model, &klass->in_domain_of, class_name, + "SELECT ?prop {" + " ?prop rdfs:domain ~var" + "} ORDER BY DESC ?prop"); + fill_in_list (model->ontology_conn, model, &klass->in_range_of, class_name, + "SELECT ?prop {" + " ?prop rdfs:range ~var" + "} ORDER BY DESC ?prop"); + fill_in_list (model->ontology_conn, model, &klass->instances, class_name, + "SELECT (CONCAT(?prefix, ':', SUBSTR(str(?c), strlen(?o) + 1)) AS ?shortname) {" + " ?c a ~var ." + " ?o a nrl:Namespace ;" + " nrl:prefix ?prefix ." + " FILTER (STRSTARTS(?c, ?o))" + "} ORDER BY DESC ?shortname"); + + g_hash_table_insert (model->classes, klass->classname, klass); + } + + g_assert_no_error (error); + g_object_unref (cursor); +} + +TrackerOntologyProperty * +tracker_ontology_model_init_properties (TrackerOntologyModel *model) +{ + TrackerOntologyProperty *prop; + TrackerSparqlCursor *cursor; + GError *error = NULL; + + cursor = tracker_sparql_connection_query (model->ontology_conn, + "SELECT " + " ?p" + " nrl:propertySpecification(?p)" + " rdfs:comment(?p)" + " nrl:maxCardinality(?p)" + " nrl:deprecated(?p)" + " nrl:fulltextIndexed(?p)" + " nrl:weight(?p)" + " (SUBSTR(str(?p), strlen(?o) + 1) AS ?basename)" + " (CONCAT(?prefix, ':', SUBSTR(str(?p), strlen(?o) + 1)) AS ?shortname)" + "{" + " ?p a rdf:Property ." + " ?o a nrl:Namespace ;" + " nrl:prefix ?prefix ." + " FILTER (STRSTARTS(?p, ?o))" + "}", + NULL, + &error); + g_assert_no_error (error); + + while (tracker_sparql_cursor_next (cursor, NULL, &error)) { + const gchar *prop_name; + + prop_name = tracker_sparql_cursor_get_string (cursor, 0, NULL); + + prop = ttl_model_property_new (prop_name); + prop->specification = g_strdup (tracker_sparql_cursor_get_string (cursor, 1, NULL)); + prop->description = g_strdup (tracker_sparql_cursor_get_string (cursor, 2, NULL)); + prop->max_cardinality = g_strdup (tracker_sparql_cursor_get_string (cursor, 3, NULL)); + prop->deprecated = tracker_sparql_cursor_get_boolean (cursor, 4); + prop->fulltextIndexed = tracker_sparql_cursor_get_boolean (cursor, 5); + prop->weight = g_strdup (tracker_sparql_cursor_get_string (cursor, 6, NULL)); + prop->basename = g_strdup (tracker_sparql_cursor_get_string (cursor, 7, NULL)); + prop->shortname = g_strdup (tracker_sparql_cursor_get_string (cursor, 8, NULL)); + + fill_in_list (model->ontology_conn, model, &prop->domain, prop_name, + "SELECT ?class {" + " ~var rdfs:domain ?class" + "} ORDER BY DESC ?class"); + fill_in_list (model->ontology_conn, model, &prop->range, prop_name, + "SELECT ?class {" + " ~var rdfs:range ?class" + "} ORDER BY DESC ?class"); + fill_in_list (model->ontology_conn, model, &prop->superproperties, prop_name, + "SELECT ?prop {" + " ~var rdfs:subPropertyOf ?prop" + "} ORDER BY DESC ?prop"); + fill_in_list (model->ontology_conn, model, &prop->subproperties, prop_name, + "SELECT ?prop {" + " ?prop rdfs:subPropertyOf ~var" + "} ORDER BY DESC ?prop"); + + g_hash_table_insert (model->properties, prop->propertyname, prop); + } + + g_assert_no_error (error); + g_object_unref (cursor); + + return prop; +} + +TrackerOntologyModel * +tracker_ontology_model_new (GFile *ontology_location, + GError **error) +{ + TrackerOntologyModel *model; + TrackerSparqlConnection *ontology_conn, *desc_conn; + GFileEnumerator *enumerator; + GFileInfo *info; + GFile *dsc_ontology; + + ontology_conn = tracker_sparql_connection_new (TRACKER_SPARQL_CONNECTION_FLAGS_NONE, + NULL, ontology_location, NULL, + error); + if (!ontology_conn) + goto error; + + dsc_ontology = g_file_new_for_uri ("resource:///org/freedesktop/tracker/doctool/ontology"); + desc_conn = tracker_sparql_connection_new (TRACKER_SPARQL_CONNECTION_FLAGS_NONE, + NULL, + dsc_ontology, + NULL, + error); + g_clear_object (&dsc_ontology); + + if (!desc_conn) + goto error; + + /* Load all .description files into desc_conn */ + enumerator = g_file_enumerate_children (ontology_location, + G_FILE_ATTRIBUTE_STANDARD_NAME, + G_FILE_QUERY_INFO_NONE, + NULL, error); + if (!enumerator) + goto error; + + while (g_file_enumerator_iterate (enumerator, &info, NULL, NULL, error)) { + GError *inner_error = NULL; + gchar *uri, *query; + GFile *child; + + if (!info) + break; + if (!g_str_has_suffix (g_file_info_get_name (info), ".description")) + continue; + + child = g_file_enumerator_get_child (enumerator, info); + uri = g_file_get_uri (child); + query = g_strdup_printf ("LOAD <%s>", uri); + tracker_sparql_connection_update (desc_conn, + query, + NULL, + &inner_error); + g_assert_no_error (inner_error); + g_object_unref (child); + g_free (uri); + g_free (query); + } + + model = g_new0 (TrackerOntologyModel, 1); + model->ontology_conn = ontology_conn; + model->desc_conn = desc_conn; + model->stmts = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, + (GDestroyNotify) g_object_unref); + model->classes = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, + (GDestroyNotify) ttl_model_class_free); + model->properties = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, + (GDestroyNotify) ttl_model_property_free); + model->descriptions = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, + (GDestroyNotify) ttl_model_description_free); + + tracker_ontology_model_init_classes (model); + tracker_ontology_model_init_properties (model); + + return model; + +error: + g_clear_object (&ontology_conn); + g_clear_object (&desc_conn); + g_clear_object (&enumerator); + + return NULL; +} + +void +tracker_ontology_model_free (TrackerOntologyModel *model) +{ + g_object_unref (model->ontology_conn); + g_object_unref (model->desc_conn); + g_object_unref (model->classes_stmt); + g_object_unref (model->props_stmt); + g_hash_table_unref (model->stmts); + g_hash_table_unref (model->classes); + g_hash_table_unref (model->properties); + g_hash_table_unref (model->descriptions); + g_free (model); +} + +GStrv +tracker_ontology_model_get_prefixes (TrackerOntologyModel *model) +{ + TrackerSparqlCursor *cursor; + GError *error = NULL; + GPtrArray *prefixes; + + cursor = tracker_sparql_connection_query (model->ontology_conn, + "SELECT ?p { ?u a nrl:Namespace ; nrl:prefix ?p }", + NULL, + &error); + g_assert_no_error (error); + + prefixes = g_ptr_array_new (); + + while (tracker_sparql_cursor_next (cursor, NULL, &error)) { + const gchar *prefix; + + prefix = tracker_sparql_cursor_get_string (cursor, 0, NULL); + g_ptr_array_add (prefixes, g_strdup (prefix)); + } + + g_object_unref (cursor); + g_ptr_array_add (prefixes, NULL); + g_assert_no_error (error); + + return (GStrv) g_ptr_array_free (prefixes, FALSE); +} + +TrackerOntologyDescription * +tracker_ontology_model_get_description (TrackerOntologyModel *model, + const gchar *prefix) +{ + TrackerSparqlStatement *stmt; + TrackerSparqlCursor *cursor; + TrackerOntologyDescription *desc; + GError *error = NULL; + + desc = g_hash_table_lookup (model->descriptions, prefix); + + if (!desc) { + stmt = tracker_sparql_connection_query_statement (model->desc_conn, + "SELECT " + " dsc:title(?d) " + " dsc:description(?d) " + " dsc:gitlog(?d) " + " dsc:localPrefix(?d) " + " dsc:baseUrl(?d) " + " dsc:relativePath(?d) " + " dsc:copyright(?d) " + " dsc:upstream(?d) " + "{" + " ?d a dsc:Ontology ;" + " dsc:localPrefix ~prefix" + "}", + NULL, + &error); + g_assert_no_error (error); + + tracker_sparql_statement_bind_string (stmt, "prefix", prefix); + cursor = tracker_sparql_statement_execute (stmt, NULL, &error); + g_object_unref (stmt); + g_assert_no_error (error); + + if (!tracker_sparql_cursor_next (cursor, NULL, &error)) + return NULL; + + desc = ttl_model_description_new (); + desc->title = g_strdup (tracker_sparql_cursor_get_string (cursor, 0, NULL)); + desc->description = g_strdup (tracker_sparql_cursor_get_string (cursor, 1, NULL)); + desc->gitlog = g_strdup (tracker_sparql_cursor_get_string (cursor, 2, NULL)); + desc->localPrefix = g_strdup (tracker_sparql_cursor_get_string (cursor, 3, NULL)); + desc->baseUrl = g_strdup (tracker_sparql_cursor_get_string (cursor, 4, NULL)); + desc->relativePath = g_strdup (tracker_sparql_cursor_get_string (cursor, 5, NULL)); + desc->copyright = g_strdup (tracker_sparql_cursor_get_string (cursor, 6, NULL)); + desc->upstream = g_strdup (tracker_sparql_cursor_get_string (cursor, 7, NULL)); + + g_object_unref (cursor); + + fill_in_list (model->desc_conn, model, &desc->authors, prefix, + "SELECT ?author {" + " ?d a dsc:Ontology ;" + " dsc:localPrefix ~var ;" + " dsc:author ?author ." + "}" + "ORDER BY DESC ?author"); + + fill_in_list (model->desc_conn, model, &desc->editors, prefix, + "SELECT ?editor {" + " ?d a dsc:Ontology ;" + " dsc:localPrefix ~var ;" + " dsc:editor ?editor ." + "}" + "ORDER BY DESC ?editor"); + + fill_in_list (model->desc_conn, model, &desc->contributors, prefix, + "SELECT ?contributor {" + " ?d a dsc:Ontology ;" + " dsc:localPrefix ~var ;" + " dsc:contributor ?contributor ." + "}" + "ORDER BY DESC ?contributor"); + + g_hash_table_insert (model->descriptions, desc->localPrefix, desc); + } + + return desc; +} + +GList * +tracker_ontology_model_list_classes (TrackerOntologyModel *model, + const gchar *prefix) +{ + TrackerSparqlCursor *cursor; + GError *error = NULL; + GList *classes = NULL; + + if (!model->classes_stmt) { + model->classes_stmt = + tracker_sparql_connection_query_statement (model->ontology_conn, + "SELECT ?u {" + " ?u a rdfs:Class ." + " ?o a nrl:Namespace ;" + " nrl:prefix ~prefix ." + " FILTER (STRSTARTS(?u, ?o))" + "} ORDER BY DESC ?u", + NULL, + &error); + g_assert_no_error (error); + } + + tracker_sparql_statement_bind_string (model->classes_stmt, "prefix", prefix); + cursor = tracker_sparql_statement_execute (model->classes_stmt, NULL, &error); + g_assert_no_error (error); + + while (tracker_sparql_cursor_next (cursor, NULL, &error)) { + classes = g_list_prepend (classes, g_strdup (tracker_sparql_cursor_get_string (cursor, 0, NULL))); + } + + g_assert_no_error (error); + g_object_unref (cursor); + + return classes; +} + +GList * +tracker_ontology_model_list_properties (TrackerOntologyModel *model, + const gchar *prefix) +{ + TrackerSparqlCursor *cursor; + GError *error = NULL; + GList *props = NULL; + + if (!model->props_stmt) { + model->props_stmt = + tracker_sparql_connection_query_statement (model->ontology_conn, + "SELECT ?u {" + " ?u a rdf:Property ." + " ?o a nrl:Namespace ;" + " nrl:prefix ~prefix ." + " FILTER (STRSTARTS(?u, ?o))" + "} ORDER BY DESC ?u", + NULL, + &error); + g_assert_no_error (error); + } + + tracker_sparql_statement_bind_string (model->props_stmt, "prefix", prefix); + cursor = tracker_sparql_statement_execute (model->props_stmt, NULL, &error); + g_assert_no_error (error); + + while (tracker_sparql_cursor_next (cursor, NULL, &error)) { + props = g_list_prepend (props, g_strdup (tracker_sparql_cursor_get_string (cursor, 0, NULL))); + } + + g_assert_no_error (error); + g_object_unref (cursor); + + return props; +} + +TrackerOntologyClass * +tracker_ontology_model_get_class (TrackerOntologyModel *model, + const gchar *class_name) +{ + return g_hash_table_lookup (model->classes, class_name); +} + +TrackerOntologyProperty * +tracker_ontology_model_get_property (TrackerOntologyModel *model, + const gchar *prop_name) +{ + return g_hash_table_lookup (model->properties, prop_name); +} diff --git a/docs/tools/ttl_model.h b/docs/tools/tracker-ontology-model.h index a3758b0a2..60339fe46 100644 --- a/docs/tools/ttl_model.h +++ b/docs/tools/tracker-ontology-model.h @@ -17,15 +17,19 @@ * 02110-1301, USA. */ -#ifndef __TTL_MODEL_H__ -#define __TTL_MODEL_H__ +#ifndef TRACKER_ONTOLOGY_MODEL_H +#define TRACKER_ONTOLOGY_MODEL_H #include <glib.h> G_BEGIN_DECLS +typedef struct _TrackerOntologyModel TrackerOntologyModel; + typedef struct { gchar *classname; + gchar *shortname; + gchar *basename; gchar *specification; GList *superclasses; GList *subclasses; @@ -35,12 +39,13 @@ typedef struct { GList *instances; gboolean notify; gboolean deprecated; -} OntologyClass; +} TrackerOntologyClass; typedef struct { gchar *propertyname; + gchar *shortname; + gchar *basename; gchar *specification; - GList *type; GList *domain; GList *range; GList *superproperties; @@ -50,7 +55,7 @@ typedef struct { gboolean deprecated; gboolean fulltextIndexed; gchar *weight; -} OntologyProperty; +} TrackerOntologyProperty; typedef struct { gchar *title; @@ -64,30 +69,27 @@ typedef struct { gchar *baseUrl; gchar *localPrefix; gchar *relativePath; -} OntologyDescription; - -typedef struct { - GHashTable *classes; - GHashTable *properties; - GHashTable *prefixes; -} Ontology; +} TrackerOntologyDescription; +TrackerOntologyModel * tracker_ontology_model_new (GFile *ontology_location, + GError **error); +void tracker_ontology_model_free (TrackerOntologyModel *model); -OntologyClass * ttl_model_class_new (const gchar *classname); -void ttl_model_class_free (OntologyClass *klass); +GStrv tracker_ontology_model_get_prefixes (TrackerOntologyModel *model); -OntologyDescription * ttl_model_description_new (void); -void ttl_model_description_free (OntologyDescription *desc); +TrackerOntologyDescription * tracker_ontology_model_get_description (TrackerOntologyModel *model, + const gchar *prefix); -OntologyProperty * ttl_model_property_new (const gchar *propname); -void ttl_model_property_free (OntologyProperty *property); +GList * tracker_ontology_model_list_classes (TrackerOntologyModel *model, + const gchar *prefix); +GList * tracker_ontology_model_list_properties (TrackerOntologyModel *model, + const gchar *prefix); -gchar * ttl_model_name_to_shortname (Ontology *ontology, - const gchar *name, - const gchar *separator); +TrackerOntologyClass * tracker_ontology_model_get_class (TrackerOntologyModel *model, + const gchar *class_name); +TrackerOntologyProperty * tracker_ontology_model_get_property (TrackerOntologyModel *model, + const gchar *prop_name); -gchar * ttl_model_name_to_basename (Ontology *ontology, - const gchar *name); G_END_DECLS -#endif /* __TRACKER_TTL_MODEL_H__ */ +#endif /* TRACKER_ONTOLOGY_MODEL_H */ diff --git a/docs/tools/ttl2xml.c b/docs/tools/ttl2xml.c index 7129c1770..655e1ef10 100644 --- a/docs/tools/ttl2xml.c +++ b/docs/tools/ttl2xml.c @@ -21,10 +21,9 @@ #include <gio/gio.h> #include <string.h> #include <stdio.h> -#include "ttl_loader.h" -#include "ttl_model.h" + +#include "tracker-ontology-model.h" #include "ttl_xml.h" -#include "ttlresource2xml.h" static gchar *ontology_dir = NULL; static gchar *output_dir = NULL; @@ -46,69 +45,16 @@ static GOptionEntry entries[] = { { NULL } }; -static gint -compare_files (gconstpointer a, - gconstpointer b) -{ - const GFile *file_a = a, *file_b = b; - gchar *basename_a, *basename_b; - gint res; - - basename_a = g_file_get_basename ((GFile*) file_a); - basename_b = g_file_get_basename ((GFile*) file_b); - res = strcmp (basename_a, basename_b); - - g_free (basename_a); - g_free (basename_b); - - return res; -} - -static GList * -get_description_files (GFile *dir) -{ - GFileEnumerator *enumerator; - GFileInfo *info; - GFile *desc_file; - GList *files; - const gchar *name; - - enumerator = g_file_enumerate_children (dir, - G_FILE_ATTRIBUTE_STANDARD_NAME, - G_FILE_QUERY_INFO_NONE, - NULL, NULL); - - if (!enumerator) { - return NULL; - } - - files = NULL; - - while ((info = g_file_enumerator_next_file (enumerator, NULL, NULL)) != NULL) { - name = g_file_info_get_name (info); - - if (g_str_has_suffix (name, ".description")) { - desc_file = g_file_enumerator_get_child (enumerator, info); - files = g_list_insert_sorted (files, desc_file, compare_files); - } - - g_object_unref (info); - } - - g_object_unref (enumerator); - - return files; -} - gint main (gint argc, gchar **argv) { GOptionContext *context; - OntologyDescription *description = NULL; - GList *description_files, *l; + TrackerOntologyDescription *description = NULL; + TrackerOntologyModel *model = NULL; g_autoptr(GFile) ontology_file = NULL, output_file = NULL; gchar *path; - gboolean success; + GStrv prefixes = NULL; + gint i; g_autoptr(GError) error = NULL; /* Translators: this messagge will apper immediately after the */ @@ -136,47 +82,31 @@ main (gint argc, gchar **argv) ontology_file = g_file_new_for_commandline_arg (ontology_dir); output_file = g_file_new_for_commandline_arg (output_dir); - description_files = get_description_files (ontology_file); - if (!description_files) { - g_printerr ("Ontology description files not found in dir\n"); + model = tracker_ontology_model_new (ontology_file, &error); + if (error) { + g_printerr ("Error loading ontology: %s\n", error->message); + g_error_free (error); return -1; } + prefixes = tracker_ontology_model_get_prefixes (model); + path = g_file_get_path (output_file); g_mkdir_with_parents (path, 0755); g_free (path); - success = TRUE; - for (l = description_files; l; l = l->next) { - Ontology *ontology = NULL; - g_autoptr(GFile) ttl_file = NULL, ttl_output_file = NULL; - gchar *filename; - - description = ttl_loader_load_description (l->data); - ttl_file = g_file_get_child (ontology_file, description->relativePath); - - filename = g_strdup_printf ("%s-ontology.xml", description->localPrefix); - ttl_output_file = g_file_get_child (output_file, filename); - g_free (filename); - - ontology = ttl_loader_new_ontology (); - - success &= ttl_loader_load_ontology (ontology, ttl_file, &error); - - if (error) { - g_printerr ("%s: Turtle parse error: %s\n", g_file_peek_path (ttl_file), error->message); - g_clear_error (&error); - } - - ttl_xml_print (description, ontology, ttl_output_file, description_dir); + for (i = 0; prefixes[i]; i++) { + description = tracker_ontology_model_get_description (model, prefixes[i]); + if (!description) + continue; - ttl_loader_free_ontology (ontology); - ttl_loader_free_description (description); + ttl_xml_print (description, model, prefixes[i], output_file, description_dir); } - g_list_free_full (description_files, (GDestroyNotify) g_object_unref); + g_strfreev (prefixes); + tracker_ontology_model_free (model); g_option_context_free (context); - return !(success); + return 0; } diff --git a/docs/tools/ttl_loader.c b/docs/tools/ttl_loader.c deleted file mode 100644 index 08b634588..000000000 --- a/docs/tools/ttl_loader.c +++ /dev/null @@ -1,460 +0,0 @@ -/* - * 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_loader.h" -#include <glib/gstdio.h> -#include <gio/gio.h> - -#include <libtracker-data/tracker-turtle-reader.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 RDF_LIST "http://www.w3.org/1999/02/22-rdf-syntax-ns#List" -#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_NS "http://tracker.api.gnome.org/ontology/v3/nrl#" -#define NRL_MAX_CARDINALITY NRL_NS "maxCardinality" - -#define NRL_CLASS_SPECIFICATION NRL_NS "classSpecification" -#define NRL_PROPERTY_SPECIFICATION NRL_NS "propertySpecification" -#define NRL_NOTIFY NRL_NS "notify" -#define NRL_FTS_INDEXED NRL_NS "fulltextIndexed" -#define NRL_FTS_WEIGHT NRL_NS "weight" -#define NRL_DEPRECATED NRL_NS "deprecated" - -/* Ontology description */ -#define DSC_PREFIX "http://tracker.api.gnome.org/ontology/v3/dsc#" - -#define DSC_ONTOLOGY DSC_PREFIX "Ontology" -#define DSC_TITLE DSC_PREFIX "title" -#define DSC_DESCRIPTION DSC_PREFIX "description" -#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_strcmp0 (turtle_object, RDF_LIST)) { - 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, NRL_NOTIFY)) { - /* - * A nrl: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, NRL_FTS_INDEXED)) { - /* - * A nrl:fulltextIndexed TRUE - */ - OntologyProperty *prop; - - prop = g_hash_table_lookup (ontology->properties, turtle_subject); - if (!prop) { - g_error ("Something wrong"); - } - - prop->fulltextIndexed = string_to_boolean (turtle_object); - - } else if (!g_strcmp0 (turtle_predicate, NRL_FTS_WEIGHT)) { - /* - * A nrl:weight X - */ - OntologyProperty *prop; - - prop = g_hash_table_lookup (ontology->properties, turtle_subject); - if (!prop) { - g_error ("Something wrong"); - } - - prop->weight = g_strdup (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 ("Error in comment (%s doesn't exist)", turtle_subject); - } - } - - } else if (!g_strcmp0 (turtle_predicate, NRL_CLASS_SPECIFICATION)) { - OntologyClass *klass; - - klass = g_hash_table_lookup (ontology->classes, turtle_subject); - if (klass) { - klass->specification = g_strdup (turtle_object); - } else { - g_error ("Error in specification (class %s doesn't exist)", turtle_subject); - } - - } else if (!g_strcmp0 (turtle_predicate, NRL_PROPERTY_SPECIFICATION)) { - OntologyProperty *prop; - - prop = g_hash_table_lookup (ontology->properties, turtle_subject); - if (prop) { - prop->specification = g_strdup (turtle_object); - } else { - g_error ("Error in specification (property %s doesn't exist)", 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, NRL_DEPRECATED)) { - /* - * X nrl:deprecated true - * - * This can apply to classes OR properties OR - * namespaces! - * - * NOTE: there is no way to check if we're dealing - * with a namespace or not, so we don't error here if - * we can't verify the property of class. - */ - 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 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_DESCRIPTION)) { - desc->description = 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_new_ontology (void) -{ - 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); - ontology->prefixes = g_hash_table_new_full (g_str_hash, - g_str_equal, - g_free, g_free); - return ontology; -} - -gboolean -ttl_loader_load_ontology (Ontology *ontology, - GFile *ttl_file, - GError **error) -{ - TrackerTurtleReader *reader; - const gchar *subject, *predicate, *object; - const gchar *base_url, *prefix; - GHashTableIter iter; - GError *inner_error = NULL; - - g_return_val_if_fail (G_IS_FILE (ttl_file), 0); - - reader = tracker_turtle_reader_new_for_file (ttl_file, &inner_error); - - while (inner_error == NULL && - tracker_turtle_reader_next (reader, - &subject, &predicate, &object, - NULL, NULL, &inner_error)) { - load_in_memory (ontology, subject, predicate, object); - } - - g_hash_table_iter_init (&iter, tracker_turtle_reader_get_prefixes (reader)); - while (g_hash_table_iter_next (&iter, (gpointer *) &prefix, (gpointer *) &base_url)) { - gchar *prefix_no_colon; - - prefix_no_colon = g_strdup (prefix); - if (strrchr (prefix_no_colon, ':')) - *strrchr (prefix_no_colon, ':') = '\0'; - - g_hash_table_insert (ontology->prefixes, g_strdup (base_url), prefix_no_colon); - } - - g_clear_object (&reader); - - if (inner_error) { - g_propagate_error (error, inner_error); - return FALSE; - } else { - return TRUE; - } -} - -OntologyDescription * -ttl_loader_load_description (GFile *file) -{ - const gchar *subject, *predicate, *object; - OntologyDescription *desc; - TrackerTurtleReader *reader; - GError *error = NULL; - - desc = ttl_model_description_new (); - reader = tracker_turtle_reader_new_for_file (file, &error); - - while (error == NULL && - tracker_turtle_reader_next (reader, - &subject, &predicate, &object, - NULL, NULL, &error)) { - load_description (desc, subject, predicate, object); - } - - g_clear_object (&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_hash_table_destroy (ontology->prefixes); - g_free (ontology); -} - -void -ttl_loader_free_description (OntologyDescription *desc) -{ - ttl_model_description_free (desc); -} diff --git a/docs/tools/ttl_loader.h b/docs/tools/ttl_loader.h deleted file mode 100644 index b70bd33b4..000000000 --- a/docs/tools/ttl_loader.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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. - */ - -#ifndef __TTL_LOADER_H__ -#define __TTL_LOADER_H__ - -#include <glib.h> -#include <gio/gio.h> -#include "ttl_model.h" - -G_BEGIN_DECLS - -Ontology * ttl_loader_new_ontology (void); - -gboolean ttl_loader_load_ontology (Ontology *ontology, - GFile *filename, - GError **error); -OntologyDescription * ttl_loader_load_description (GFile *filename); - -void ttl_loader_load_prefix_from_description (Ontology *ontology, - OntologyDescription *description); - -void ttl_loader_free_ontology (Ontology *ontology); -void ttl_loader_free_description (OntologyDescription *desc); - - -G_END_DECLS - -#endif /* __TTL_LOADER_H__ */ diff --git a/docs/tools/ttl_model.c b/docs/tools/ttl_model.c deleted file mode 100644 index 46801e164..000000000 --- a/docs/tools/ttl_model.c +++ /dev/null @@ -1,206 +0,0 @@ -/* - * 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_model.h" -#include <string.h> - -OntologyClass * -ttl_model_class_new (const gchar *classname) -{ - OntologyClass *def = NULL; - - def = g_new0 (OntologyClass, 1); - - def->classname = g_strdup (classname); - def->specification = NULL; - 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) -{ - g_free (def->classname); - - g_list_free_full (def->superclasses, (GDestroyNotify) g_free); - g_list_free_full (def->subclasses, (GDestroyNotify) g_free); - g_list_free_full (def->in_domain_of, (GDestroyNotify) g_free); - g_list_free_full (def->in_range_of, (GDestroyNotify) g_free); - - g_free (def->description); - g_free (def->specification); - - g_list_free_full (def->instances, (GDestroyNotify) g_free); - - g_free (def); -} - -OntologyProperty * -ttl_model_property_new (const gchar *propname) -{ - OntologyProperty *prop; - - prop = g_new0 (OntologyProperty, 1); - - prop->propertyname = g_strdup (propname); - prop->specification = NULL; - 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; - prop->fulltextIndexed = FALSE ; - prop->weight = NULL; - - return prop; -} - -void -ttl_model_property_free (OntologyProperty *def) -{ - g_free (def->propertyname); - - g_list_free_full (def->type, (GDestroyNotify) g_free); - g_list_free_full (def->domain, (GDestroyNotify) g_free); - g_list_free_full (def->range, (GDestroyNotify) g_free); - g_list_free_full (def->superproperties, (GDestroyNotify) g_free); - g_list_free_full (def->subproperties, (GDestroyNotify) g_free); - - g_free (def->max_cardinality); - g_free (def->description); - g_free (def->weight); - g_free (def->specification); - 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_free (desc->description); - - g_list_free_full (desc->authors, (GDestroyNotify) g_free); - g_list_free_full (desc->editors, (GDestroyNotify) g_free); - g_list_free_full (desc->contributors, (GDestroyNotify) g_free); - - 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); -} - -static gchar * -name_get_prefix (Ontology *ontology, - const gchar *name) -{ - const gchar *delim; - - delim = g_strrstr (name, "#"); - - if (!delim) - delim = g_strrstr (name, "/"); - - if (!delim) - return NULL; - - delim++; - - return g_strndup (name, delim - name); -} - -gchar * -ttl_model_name_to_shortname (Ontology *ontology, - const gchar *name, - const gchar *separator) -{ - gchar *prefix, *short_prefix; - const gchar *suffix; - - if (!separator) - separator = ":"; - - prefix = name_get_prefix (ontology, name); - - if (!prefix) - return g_strdup (name); - - short_prefix = g_hash_table_lookup (ontology->prefixes, prefix); - - if (!short_prefix) { - g_free (prefix); - return g_strdup (name); - } - - suffix = &name[strlen (prefix)]; - g_free (prefix); - - return g_strconcat (short_prefix, separator, suffix, NULL); -} - -gchar * -ttl_model_name_to_basename (Ontology *ontology, - const gchar *name) -{ - g_autofree gchar *prefix = NULL; - const gchar *suffix; - - prefix = name_get_prefix (ontology, name); - - if (!prefix) - return g_strdup (name); - - suffix = &name[strlen (prefix)]; - - return g_strdup (suffix); -} diff --git a/docs/tools/ttl_xml.c b/docs/tools/ttl_xml.c index a5a0af308..375a8f7bb 100644 --- a/docs/tools/ttl_xml.c +++ b/docs/tools/ttl_xml.c @@ -23,8 +23,8 @@ #include "ttlresource2xml.h" typedef struct { - Ontology *ontology; - OntologyDescription *description; + TrackerOntologyModel *model; + TrackerOntologyDescription *description; FILE *output; } CallbackInfo; @@ -88,7 +88,7 @@ print_deprecated_message (FILE *f) #endif static void -print_xml_header (FILE *f, OntologyDescription *desc) +print_xml_header (FILE *f, TrackerOntologyDescription *desc) { g_fprintf (f, "<?xml version='1.0' encoding='UTF-8'?>\n"); g_fprintf (f, "<!DOCTYPE book PUBLIC \"-//OASIS//DTD DocBook XML V4.5//EN\"\n" @@ -107,7 +107,7 @@ print_xml_header (FILE *f, OntologyDescription *desc) } static void -print_xml_footer (FILE *f, OntologyDescription *desc) +print_xml_footer (FILE *f, TrackerOntologyDescription *desc) { g_fprintf (f, "<refsect1>\n"); g_fprintf (f, "<title>Credits and Copyright</title>\n"); @@ -131,12 +131,6 @@ print_xml_footer (FILE *f, OntologyDescription *desc) g_fprintf (f, "</refentry>\n"); } -static gint compare_class (gconstpointer a, - gconstpointer b) -{ - return strcmp (((OntologyClass *)a)->classname, ((OntologyClass *)b)->classname); -} - /* By default we list properties under their respective class. * * Ontologies can contain properties whose class is in a different @@ -146,8 +140,9 @@ static gint compare_class (gconstpointer a, * extra properties provided for that class. */ static GHashTable * -get_extra_properties (GList *classes, - GList *properties) +get_extra_properties (TrackerOntologyModel *model, + GList *classes, + GList *properties) { GList *l, *c; GHashTable *extra_properties; @@ -158,17 +153,27 @@ get_extra_properties (GList *classes, extra_properties = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); for (l = properties; l; l = l->next) { - OntologyProperty *prop = l->data; + TrackerOntologyProperty *prop; gboolean has_domain_in_this_ontology = FALSE; - for (c = classes; c; c = c->next) { - OntologyClass *klass; + prop = tracker_ontology_model_get_property (model, l->data); + + for (c = prop->domain; c; c = c->next) { + TrackerOntologyDescription *desc = NULL; + TrackerOntologyClass *klass; + gchar *prefix; + const gchar *sep; + + klass = tracker_ontology_model_get_class (model, c->data); + sep = strstr (klass->shortname, ":"); - klass = c->data; - if (g_list_find_custom (prop->domain, klass->classname, (GCompareFunc)strcmp)) { - has_domain_in_this_ontology = TRUE; - break; + if (sep) { + prefix = g_strndup (klass->shortname, sep - klass->shortname); + desc = tracker_ontology_model_get_description (model, prefix); + g_free (prefix); } + + has_domain_in_this_ontology = desc != NULL; } if (!has_domain_in_this_ontology) { @@ -194,8 +199,8 @@ get_extra_properties (GList *classes, } static void -print_synopsis (FILE *f, - OntologyDescription *desc) +print_synopsis (FILE *f, + TrackerOntologyDescription *desc) { g_fprintf (f, "<refsynopsisdiv>\n"); g_fprintf (f, "<synopsis>\n"); @@ -205,10 +210,10 @@ print_synopsis (FILE *f, } static void -print_toc_classes (FILE *f, - Ontology *ontology, - const char *id, - GList *classes) +print_toc_classes (FILE *f, + TrackerOntologyModel *model, + const char *id, + GList *classes) { GList *l; @@ -219,12 +224,12 @@ print_toc_classes (FILE *f, g_fprintf (f, "<title>Classes</title>"); for (l = classes; l; l = l->next) { - OntologyClass *klass; - g_autofree char *basename = NULL, *id = NULL; + TrackerOntologyClass *klass; + const char *basename = NULL, *id = NULL; - klass = l->data; - basename = ttl_model_name_to_basename (ontology, klass->classname); - id = ttl_model_name_to_shortname (ontology, klass->classname, "-"); + klass = tracker_ontology_model_get_class (model, l->data); + basename = klass->basename; + id = klass->shortname; if (l != classes) { g_fprintf (f, ", "); @@ -236,10 +241,10 @@ print_toc_classes (FILE *f, } static void -print_toc_extra_properties (FILE *f, - Ontology *ontology, - const char *id, - GHashTable *extra_properties) +print_toc_extra_properties (FILE *f, + TrackerOntologyModel *model, + const char *id, + GHashTable *extra_properties) { GList *props_for_class, *c, *l; g_autoptr(GList) classes = NULL; @@ -259,13 +264,12 @@ print_toc_extra_properties (FILE *f, classname = c->data; props_for_class = g_hash_table_lookup (extra_properties, classname); for (l = props_for_class; l; l = l->next) { - OntologyProperty *prop; - g_autofree char *basename = NULL, *prop_id = NULL; - - prop = g_hash_table_lookup (ontology->properties, l->data); + TrackerOntologyProperty *prop; + const char *basename = NULL, *prop_id = NULL; - basename = ttl_model_name_to_basename (ontology, prop->propertyname); - prop_id = ttl_model_name_to_shortname (ontology, prop->propertyname, "-"); + prop = tracker_ontology_model_get_property (model, l->data); + basename = prop->basename; + prop_id = prop->shortname; if (print_comma) { g_fprintf (f, ", "); @@ -282,33 +286,38 @@ print_toc_extra_properties (FILE *f, /* Generate docbook XML document for one ontology. */ void -ttl_xml_print (OntologyDescription *description, - Ontology *ontology, - GFile *file, - const gchar *description_dir) +ttl_xml_print (TrackerOntologyDescription *description, + TrackerOntologyModel *model, + const gchar *prefix, + GFile *output_location, + const gchar *description_dir) { - gchar *upper_name, *path, *introduction, *basename; + gchar *upper_name, *path, *introduction, *basename, *filename; g_autoptr(GList) classes = NULL, properties = NULL, extra_classes = NULL; g_autoptr(GHashTable) extra_properties = NULL; + GFile *file; GList *l; FILE *f; + filename = g_strdup_printf ("%s-ontology.xml", description->localPrefix); + 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); upper_name = g_ascii_strup (description->localPrefix, -1); - classes = g_list_sort (g_hash_table_get_values (ontology->classes), compare_class); - properties = g_hash_table_get_values (ontology->properties); - - extra_properties = get_extra_properties (classes, properties); + classes = tracker_ontology_model_list_classes (model, prefix); + properties = tracker_ontology_model_list_properties (model, prefix); + extra_properties = get_extra_properties (model, classes, properties); print_xml_header (f, description); print_synopsis (f, description); - print_toc_classes (f, ontology, description->localPrefix, classes); - print_toc_extra_properties (f, ontology, description->localPrefix, extra_properties); + print_toc_classes (f, model, description->localPrefix, classes); + print_toc_extra_properties (f, model, description->localPrefix, extra_properties); basename = g_strdup_printf ("%s-introduction.xml", description->localPrefix); introduction = g_build_filename (description_dir, basename, NULL); @@ -320,11 +329,14 @@ ttl_xml_print (OntologyDescription *description, } if (classes != NULL) { - g_fprintf (f, "<refsect1 id='%s-classes'>\n", description->localPrefix); + g_fprintf (f, "<refsect1 id='%s-classes'>\n", description->localPrefix); g_fprintf (f, "<title>Class Details</title>\n"); for (l = classes; l; l = l->next) { - print_ontology_class (ontology, l->data, f); + TrackerOntologyClass *klass; + + klass = tracker_ontology_model_get_class (model, l->data); + print_ontology_class (model, klass, f); } g_fprintf (f, "</refsect1>\n"); @@ -344,7 +356,7 @@ ttl_xml_print (OntologyDescription *description, properties_for_class = g_hash_table_lookup (extra_properties, classname); if (properties_for_class) { - print_ontology_extra_properties (ontology, description->localPrefix, classname, properties_for_class, f); + print_ontology_extra_properties (model, description->localPrefix, classname, properties_for_class, f); } } @@ -355,5 +367,6 @@ ttl_xml_print (OntologyDescription *description, g_free (upper_name); g_free (introduction); + g_object_unref (file); fclose (f); } diff --git a/docs/tools/ttl_xml.h b/docs/tools/ttl_xml.h index f22745621..840182bb8 100644 --- a/docs/tools/ttl_xml.h +++ b/docs/tools/ttl_xml.h @@ -21,15 +21,15 @@ #define __TTL_XML_H__ #include <gio/gio.h> -#include "ttl_model.h" -#include <stdio.h> +#include "tracker-ontology-model.h" G_BEGIN_DECLS -void ttl_xml_print (OntologyDescription *description, - Ontology *ontology, - GFile *file, - const gchar *description_dir); +void ttl_xml_print (TrackerOntologyDescription *description, + TrackerOntologyModel *model, + const gchar *prefix, + GFile *output_location, + const gchar *description_dir); G_END_DECLS diff --git a/docs/tools/ttlresource2xml.c b/docs/tools/ttlresource2xml.c index 784680446..446a8f8b2 100644 --- a/docs/tools/ttlresource2xml.c +++ b/docs/tools/ttlresource2xml.c @@ -23,39 +23,34 @@ #include <glib/gprintf.h> #include <gio/gio.h> #include <stdlib.h> -#include "ttl_loader.h" -#include "ttl_model.h" +#include "tracker-ontology-model.h" #include "ttl_xml.h" #include "ttlresource2xml.h" static void -class_get_parent_hierarchy (Ontology *ontology, - const gchar *class_name, - GList **list) +class_get_parent_hierarchy (TrackerOntologyModel *model, + const gchar *class_name, + GList **list) { - OntologyClass *klass; + TrackerOntologyClass *klass; GList *l; /* Ensure we only got the same class there once */ *list = g_list_remove (*list, (gpointer) class_name); *list = g_list_prepend (*list, (gpointer) class_name); - klass = g_hash_table_lookup (ontology->classes, class_name); - - if (!klass) { - klass = ttl_model_class_new (class_name); - g_hash_table_insert (ontology->classes, g_strdup (klass->classname), klass); + klass = tracker_ontology_model_get_class (model, class_name); + if (!klass) return; - } for (l = klass->superclasses; l; l = l->next) { - class_get_parent_hierarchy (ontology, l->data, list); + class_get_parent_hierarchy (model, l->data, list); } } static GList * -class_get_hierarchy (Ontology *ontology, - OntologyClass *klass) +class_get_hierarchy (TrackerOntologyModel *model, + TrackerOntologyClass *klass) { GList *hierarchy = NULL, *l; @@ -68,40 +63,33 @@ class_get_hierarchy (Ontology *ontology, hierarchy = g_list_prepend (hierarchy, l->data); } - class_get_parent_hierarchy (ontology, klass->classname, &hierarchy); + class_get_parent_hierarchy (model, klass->classname, &hierarchy); return hierarchy; } static void -print_predefined_instances (FILE *f, - OntologyClass *klass, - Ontology *ontology) +print_predefined_instances (FILE *f, + TrackerOntologyClass *klass, + TrackerOntologyModel *model) { - gchar *shortname, *id; + const gchar *id; GList *l; if (!klass->instances) return; - shortname = ttl_model_name_to_shortname (ontology, klass->classname, NULL); - id = ttl_model_name_to_shortname (ontology, klass->classname, "-"); + id = klass->shortname; g_fprintf (f, "<refsect3 id='%s.predefined-instances'>", id); g_fprintf (f, "<title>Predefined instances</title><para>"); - g_fprintf (f, "%s has the following predefined instances: ", shortname); + g_fprintf (f, "%s has the following predefined instances: ", klass->shortname); g_fprintf (f, "<itemizedlist>\n"); - g_free (shortname); - g_free (id); - for (l = klass->instances; l; l = l->next) { - shortname = ttl_model_name_to_shortname (ontology, l->data, NULL); - g_fprintf (f, "<listitem><para>"); - g_fprintf (f, "<literal>%s</literal>", shortname); + g_fprintf (f, "<literal>%s</literal>", (gchar*) l->data); g_fprintf (f, "</para></listitem>\n"); - g_free (shortname); } g_fprintf (f, "</itemizedlist></para></refsect3>\n"); @@ -113,7 +101,7 @@ typedef struct { } HierarchyString; typedef struct { - OntologyClass *class; + TrackerOntologyClass *class; GList *hierarchy; GHashTable *resolved_children; GHashTable *resolved_parents; @@ -180,15 +168,15 @@ list_filter (GList *original, } static HierarchyContext * -hierarchy_context_new (OntologyClass *klass, - Ontology *ontology) +hierarchy_context_new (TrackerOntologyClass *klass, + TrackerOntologyModel *model) { HierarchyContext *context; GList *l; context = g_new0 (HierarchyContext, 1); context->class = klass; - context->hierarchy = class_get_hierarchy (ontology, klass); + context->hierarchy = class_get_hierarchy (model, klass); context->placed = g_hash_table_new (g_str_hash, g_str_equal); context->resolved_parents = g_hash_table_new_full (g_str_hash, g_str_equal, @@ -201,7 +189,7 @@ hierarchy_context_new (OntologyClass *klass, context->strings = g_ptr_array_new_with_free_func ((GDestroyNotify) hierarchy_string_free); for (l = context->hierarchy; l; l = l->next) { - OntologyClass *cl = g_hash_table_lookup (ontology->classes, l->data); + TrackerOntologyClass *cl = tracker_ontology_model_get_class (model, l->data); g_hash_table_insert (context->resolved_parents, cl->classname, @@ -230,9 +218,9 @@ hierarchy_context_free (HierarchyContext *context) } static GList * -hierarchy_context_get_single_parented_children (HierarchyContext *context, - OntologyClass *klass, - Ontology *ontology) +hierarchy_context_get_single_parented_children (HierarchyContext *context, + TrackerOntologyClass *klass, + TrackerOntologyModel *model) { GList *filtered = NULL, *children, *l; @@ -282,23 +270,22 @@ check_parents_placed (GList *parents, } static void -hierarchy_context_resolve_class (HierarchyContext *context, - OntologyClass *klass, - Ontology *ontology) +hierarchy_context_resolve_class (HierarchyContext *context, + TrackerOntologyClass *klass, + TrackerOntologyModel *model) { GList *l = g_list_find_custom (context->hierarchy, klass->classname, (GCompareFunc) g_strcmp0); gint pos = g_list_position (context->hierarchy, l); GList *children, *parents; - gchar *shortname, *link; + const gchar *shortname, *link; HierarchyString *str; gboolean is_child; if (pos < 0) return; - shortname = ttl_model_name_to_shortname (ontology, klass->classname, NULL); - link = ttl_model_name_to_shortname (ontology, klass->classname, "-"); + shortname = link = klass->shortname; parents = g_hash_table_lookup (context->resolved_parents, klass->classname); @@ -367,7 +354,7 @@ hierarchy_context_resolve_class (HierarchyContext *context, /* Step 2: Modify all strings downwards, adding the lineart * necessary for all children of this class. */ - children = hierarchy_context_get_single_parented_children (context, klass, ontology); + children = hierarchy_context_get_single_parented_children (context, klass, model); l = l->next; pos++; @@ -406,27 +393,24 @@ hierarchy_context_resolve_class (HierarchyContext *context, } } } - - g_free (shortname); - g_free (link); } static GPtrArray * -class_get_parent_hierarchy_strings (OntologyClass *klass, - Ontology *ontology) +class_get_parent_hierarchy_strings (TrackerOntologyClass *klass, + TrackerOntologyModel *model) { HierarchyContext *context; GList *c; GPtrArray *strings = NULL; - context = hierarchy_context_new (klass, ontology); + context = hierarchy_context_new (klass, model); /* Proceed from parent to child classes, populating the * context->strings array. */ for (c = context->hierarchy; c; c = c->next) { - OntologyClass *cl = g_hash_table_lookup (ontology->classes, c->data); - hierarchy_context_resolve_class (context, cl, ontology); + TrackerOntologyClass *cl = tracker_ontology_model_get_class (model, c->data); + hierarchy_context_resolve_class (context, cl, model); } strings = g_ptr_array_ref (context->strings); @@ -436,27 +420,25 @@ class_get_parent_hierarchy_strings (OntologyClass *klass, } static void -print_class_hierarchy (FILE *f, - OntologyClass *klass, - Ontology *ontology) +print_class_hierarchy (FILE *f, + TrackerOntologyClass *klass, + TrackerOntologyModel *model) { GPtrArray *strings; - gchar *id; + const gchar *id; gsize i; - strings = class_get_parent_hierarchy_strings (klass, ontology); + strings = class_get_parent_hierarchy_strings (klass, model); if (!strings) return; - id = ttl_model_name_to_shortname (ontology, klass->classname, "-"); + id = klass->shortname; g_fprintf (f, "<refsect3 id='%s.hierarchy'>", id); g_fprintf (f, "<title>Class hierarchy</title>"); g_fprintf (f, "<screen>"); - g_free (id); - for (i = 0; i < strings->len; i++) { HierarchyString *str = g_ptr_array_index (strings, i); g_fprintf (f, " %s\n", str->str->str); @@ -467,7 +449,7 @@ print_class_hierarchy (FILE *f, } static void -print_flag (FILE *f, +print_flag (FILE *f, const gchar *flag_property_link, const gchar *icon_name, const gchar *flag_description) @@ -484,10 +466,10 @@ print_flag (FILE *f, } static void -print_property_table (FILE *f, - Ontology *ontology, - const char *id, - GList *properties) +print_property_table (FILE *f, + TrackerOntologyModel *model, + const char *id, + GList *properties) { GList *l, *m; g_autoptr(GList) properties_sorted = NULL; @@ -509,16 +491,17 @@ print_property_table (FILE *f, g_fprintf (f, "<tbody>"); for (l = properties_sorted; l; l = l->next) { - OntologyProperty *prop; - g_autofree gchar *shortname = NULL, *basename = NULL, *type_name = NULL, *type_class_id = NULL, *prop_id = NULL; + TrackerOntologyProperty *prop; + TrackerOntologyClass *range; + const gchar *shortname = NULL, *basename = NULL, *type_name = NULL, *type_class_id = NULL, *prop_id = NULL; - prop = g_hash_table_lookup (ontology->properties, l->data); + prop = tracker_ontology_model_get_property (model, l->data); + range = tracker_ontology_model_get_class (model, prop->range->data); - prop_id = ttl_model_name_to_shortname (ontology, prop->propertyname, "-"); - shortname = ttl_model_name_to_shortname (ontology, prop->propertyname, NULL); - basename = ttl_model_name_to_basename (ontology, prop->propertyname); - type_name = ttl_model_name_to_basename (ontology, prop->range->data); - type_class_id = ttl_model_name_to_shortname (ontology, prop->range->data, "-"); + prop_id = shortname = prop->shortname; + basename = prop->basename; + type_name = range->basename; + type_class_id = range->shortname; g_fprintf (f, "<row role=\"member\">"); @@ -548,11 +531,12 @@ print_property_table (FILE *f, if (prop->superproperties) { for (m = prop->superproperties; m; m = m->next) { - g_autofree gchar *shortname = NULL, *superprop_id = NULL; + const gchar *shortname = NULL, *superprop_id = NULL; g_autofree gchar *message = NULL; + TrackerOntologyProperty *superprop; - shortname = ttl_model_name_to_shortname (ontology, m->data, NULL); - superprop_id = ttl_model_name_to_shortname (ontology, m->data, "-"); + superprop = tracker_ontology_model_get_property (model, m->data); + shortname = superprop_id = superprop->shortname; message = g_strdup_printf ("This property extends %s", shortname); @@ -596,16 +580,16 @@ print_property_table (FILE *f, } void -print_ontology_class (Ontology *ontology, - OntologyClass *klass, - FILE *f) +print_ontology_class (TrackerOntologyModel *model, + TrackerOntologyClass *klass, + FILE *f) { - g_autofree gchar *name = NULL, *id = NULL; + const gchar *name = NULL, *id = NULL; g_return_if_fail (f != NULL); - name = ttl_model_name_to_basename (ontology, klass->classname); - id = ttl_model_name_to_shortname (ontology, klass->classname, "-"); + name = klass->basename; + id = klass->shortname; /* Anchor for external links. */ g_fprintf (f, "<anchor id='%s' />\n", name); @@ -645,29 +629,29 @@ print_ontology_class (Ontology *ontology, g_fprintf (f, "</refsect3>\n"); } - print_class_hierarchy (f, klass, ontology); - print_predefined_instances (f, klass, ontology); + print_class_hierarchy (f, klass, model); + print_predefined_instances (f, klass, model); - print_property_table (f, ontology, id, klass->in_domain_of); + print_property_table (f, model, id, klass->in_domain_of); g_fprintf (f, "</refsect2>\n"); } void -print_ontology_extra_properties (Ontology *ontology, - const char *ontology_prefix, - const char *classname, - GList *properties_for_class, - FILE *f) +print_ontology_extra_properties (TrackerOntologyModel *model, + const char *ontology_prefix, + const char *classname, + GList *properties_for_class, + FILE *f) { - g_autofree gchar *short_classname = NULL; - g_autofree gchar *section_id = NULL, *class_id = NULL; + TrackerOntologyClass *klass; + const gchar *short_classname = NULL, *class_id = NULL; + gchar *section_id = NULL; g_return_if_fail (f != NULL); - short_classname = ttl_model_name_to_shortname (ontology, classname, ":"); - - class_id = ttl_model_name_to_shortname (ontology, classname, "-"); + klass = tracker_ontology_model_get_class (model, classname); + short_classname = class_id = klass->shortname; section_id = g_strconcat (ontology_prefix, ".", class_id, NULL); g_fprintf (f, "<refsect2 role='rdf-property-list' id='%s'>\n", section_id); @@ -679,6 +663,9 @@ print_ontology_extra_properties (Ontology *ontology, short_classname); g_fprintf (f, "</refsect3>\n"); - print_property_table (f, ontology, section_id, properties_for_class); + print_property_table (f, model, section_id, properties_for_class); g_fprintf (f, "</refsect2>\n"); + + g_free (section_id); } + diff --git a/docs/tools/ttlresource2xml.h b/docs/tools/ttlresource2xml.h index 748e5bff0..80ba0bb4b 100644 --- a/docs/tools/ttlresource2xml.h +++ b/docs/tools/ttlresource2xml.h @@ -23,18 +23,18 @@ #define __TTLRESOURCE2XML_H__ #include <glib.h> -#include "ttl_model.h" +#include "tracker-ontology-model.h" G_BEGIN_DECLS -void print_ontology_class (Ontology *ontology, - OntologyClass *klass, - FILE *f); -void print_ontology_extra_properties (Ontology *ontology, - const char *ontology_prefix, - const char *classname, - GList *properties_for_class, - FILE *f); +void print_ontology_class (TrackerOntologyModel *model, + TrackerOntologyClass *klass, + FILE *f); +void print_ontology_extra_properties (TrackerOntologyModel *model, + const char *ontology_prefix, + const char *classname, + GList *properties_for_class, + FILE *f); G_END_DECLS |