[tracker] Define local prefix in the ontology description
- From: Ivan Frade <ifrade src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [tracker] Define local prefix in the ontology description
- Date: Mon, 28 Sep 2009 16:40:37 +0000 (UTC)
commit 2bcbcfb79fbae2f160d0cb52d06f11af45339ad5
Author: Ivan Frade <ivan frade nokia com>
Date: Fri Sep 25 17:20:54 2009 +0300
Define local prefix in the ontology description
utils/services/gen-doc.sh | 10 ++++++++++
utils/services/qname.c | 34 +++++++++++++++++++++++-----------
utils/services/qname.h | 4 +++-
utils/services/ttl2html.c | 8 +++++++-
utils/services/ttl_graphviz.c | 2 +-
utils/services/ttl_html.c | 5 +++--
utils/services/ttl_html.h | 3 ++-
utils/services/ttl_loader.c | 3 +++
utils/services/ttl_model.c | 15 +++++----------
utils/services/ttl_model.h | 1 +
10 files changed, 58 insertions(+), 27 deletions(-)
---
diff --git a/utils/services/gen-doc.sh b/utils/services/gen-doc.sh
index f4c4f69..c52c429 100755
--- a/utils/services/gen-doc.sh
+++ b/utils/services/gen-doc.sh
@@ -17,6 +17,16 @@ mkdir -p $BUILD_DIR
echo "Compiling the tools"
make
+echo "Generating list of classes-properties and files"
+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
for f in `find ../../data/ontologies -name "*.description"` ; do
# ../../data/ontologies/XX-aaa.description -> PREFIX=aaa
diff --git a/utils/services/qname.c b/utils/services/qname.c
index b4e6bdb..ac3d1a6 100644
--- a/utils/services/qname.c
+++ b/utils/services/qname.c
@@ -1,13 +1,15 @@
#include "qname.h"
-static gchar *local_uri = NULL;
+//static gchar *local_uri = NULL;
+//static gchar *local_prefix = NULL;
typedef struct {
- const gchar *namespace;
- const gchar *uri;
+ gchar *namespace;
+ gchar *uri;
} Namespace;
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#"},
@@ -30,19 +32,29 @@ Namespace NAMESPACES [] = {
void
-qname_init (const gchar *luri)
+qname_init (const gchar *luri, const gchar *lprefix, const gchar *class_location)
{
- if (local_uri) {
+ g_return_if_fail (luri != NULL);
+
+ if (NAMESPACES[0].namespace || NAMESPACES[0].uri) {
g_warning ("Reinitializing qname_module");
- g_free (local_uri);
+ g_free (NAMESPACES[0].namespace);
+ g_free (NAMESPACES[0].uri);
+ }
+ NAMESPACES[0].uri = g_strdup (luri);
+ NAMESPACES[0].namespace = (lprefix != NULL ? g_strdup (lprefix) : g_strdup (""));
+
+ if (class_location) {
+ /* TODO */
}
- local_uri = g_strdup (luri);
+
}
void
qname_shutdown (void)
{
- g_free (local_uri);
+ g_free (NAMESPACES[0].namespace);
+ g_free (NAMESPACES[0].uri);
}
gchar *
@@ -51,9 +63,9 @@ qname_to_link (const gchar *qname)
gchar **pieces;
gchar *name;
- if (local_uri) {
+ if (NAMESPACES[0].uri) {
/* There is a local URI! */
- if (g_str_has_prefix (qname, local_uri)) {
+ if (g_str_has_prefix (qname, NAMESPACES[0].uri)) {
pieces = g_strsplit (qname, "#", 2);
g_assert (g_strv_length (pieces) == 2);
name = g_strdup_printf ("#%s", pieces[1]);
@@ -100,7 +112,7 @@ qname_is_basic_type (const gchar *qname)
{
gint i;
/* dc: or xsd: are basic types */
- for (i = 0; NAMESPACES[i].namespace != NULL && i < 3; i++) {
+ for (i = 1; NAMESPACES[i].namespace != NULL && i < 3; i++) {
if (g_str_has_prefix (qname, NAMESPACES[i].uri)) {
return TRUE;
}
diff --git a/utils/services/qname.h b/utils/services/qname.h
index 1518402..31660a9 100644
--- a/utils/services/qname.h
+++ b/utils/services/qname.h
@@ -5,7 +5,9 @@
G_BEGIN_DECLS
-void qname_init (const gchar *local_uri);
+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);
diff --git a/utils/services/ttl2html.c b/utils/services/ttl2html.c
index 4f1c342..906e07d 100644
--- a/utils/services/ttl2html.c
+++ b/utils/services/ttl2html.c
@@ -8,6 +8,7 @@
static gchar *desc_file = NULL;
static gchar *output_file = NULL;
+static gchar *class_location_file = NULL;
static GOptionEntry entries[] = {
{ "desc", 'd', 0, G_OPTION_ARG_FILENAME, &desc_file,
@@ -18,6 +19,10 @@ static GOptionEntry entries[] = {
"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
+ },
{ NULL }
};
@@ -30,6 +35,7 @@ main (gint argc, gchar **argv)
gchar *ttl_file = NULL;
gchar *dirname = NULL;
FILE *f = NULL;
+ gchar *class_location = NULL;
g_type_init ();
@@ -74,7 +80,7 @@ main (gint argc, gchar **argv)
g_free (ttl_file);
g_free (dirname);
- ttl_html_print (description, ontology, f);
+ ttl_html_print (description, ontology, f, class_location);
ttl_loader_free_ontology (ontology);
ttl_loader_free_description (description);
diff --git a/utils/services/ttl_graphviz.c b/utils/services/ttl_graphviz.c
index c0dd182..10658f6 100644
--- a/utils/services/ttl_graphviz.c
+++ b/utils/services/ttl_graphviz.c
@@ -63,7 +63,7 @@ ttl_graphviz_print (OntologyDescription *description,
Ontology *ontology,
FILE *output)
{
-
+ qname_init (description->baseUrl, description->localPrefix, NULL);
g_fprintf (output, "digraph \"%s\" {\n", description->title);
g_fprintf (output, " label=\"%s\";\n", description->title);
g_fprintf (output, " rankdir=BT;\n");
diff --git a/utils/services/ttl_html.c b/utils/services/ttl_html.c
index 1d8d604..23cc653 100644
--- a/utils/services/ttl_html.c
+++ b/utils/services/ttl_html.c
@@ -207,10 +207,11 @@ print_ontology_property (gpointer key, gpointer value, gpointer user_data)
void
ttl_html_print (OntologyDescription *description,
Ontology *ontology,
- FILE *f)
+ FILE *f,
+ const gchar *class_location_file)
{
- qname_init (description->baseUrl);
+ qname_init (description->baseUrl, description->localPrefix, class_location_file);
print_html_header (f, description);
g_fprintf (f,"<h2>Ontology Classes Descriptions</h2>");
g_hash_table_foreach (ontology->classes, print_ontology_class, f);
diff --git a/utils/services/ttl_html.h b/utils/services/ttl_html.h
index 019b001..6c47f8b 100644
--- a/utils/services/ttl_html.h
+++ b/utils/services/ttl_html.h
@@ -9,7 +9,8 @@ G_BEGIN_DECLS
void ttl_html_print (OntologyDescription *description,
Ontology *ontology,
- FILE *output);
+ FILE *output,
+ const gchar *class_location);
diff --git a/utils/services/ttl_loader.c b/utils/services/ttl_loader.c
index 250090b..a82976c 100644
--- a/utils/services/ttl_loader.c
+++ b/utils/services/ttl_loader.c
@@ -28,6 +28,7 @@
#define DSC_CONTRIBUTOR DSC_PREFIX "contributor"
#define DSC_BASEURI DSC_PREFIX "baseUrl"
#define DSC_RELPATH DSC_PREFIX "relativePath"
+#define DSC_LOCALPREFIX DSC_PREFIX "localPrefix"
static void
load_in_memory (Ontology *ontology,
@@ -202,6 +203,8 @@ load_description (OntologyDescription *desc,
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 {
g_critical ("Unhandled element %s", turtle_predicate);
}
diff --git a/utils/services/ttl_model.c b/utils/services/ttl_model.c
index f8a6209..fc0fce6 100644
--- a/utils/services/ttl_model.c
+++ b/utils/services/ttl_model.c
@@ -91,6 +91,7 @@ ttl_model_description_new (void)
desc->contributors = NULL;
desc->baseUrl = NULL;
desc->relativePath = NULL;
+ desc->localPrefix = NULL;
return desc;
}
@@ -98,21 +99,15 @@ ttl_model_description_new (void)
void
ttl_model_description_free (OntologyDescription *desc)
{
- if (desc->title) {
- g_free (desc->title);
- }
+ 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);
- if (desc->baseUrl) {
- g_free (desc->baseUrl);
- }
-
- if (desc->relativePath) {
- g_free (desc->relativePath);
- }
+ 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
index 2a836ab..5900fa3 100644
--- a/utils/services/ttl_model.h
+++ b/utils/services/ttl_model.h
@@ -31,6 +31,7 @@ typedef struct {
GList *editors;
GList *contributors;
gchar *baseUrl;
+ gchar *localPrefix;
gchar *relativePath;
} OntologyDescription;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]