[tracker] Ontology doc: Add table with all fts-indexed properties



commit 2877880ed83c9c2fa56d058f30d57ba4771d834e
Author: Ivan Frade <ivan frade nokia com>
Date:   Thu Mar 4 15:06:22 2010 +0200

    Ontology doc: Add table with all fts-indexed properties

 docs/reference/ontology/ontology-docs.sgml |    3 ++
 docs/tools/gen-doc.sh                      |   32 ++++++++++++++-----------
 docs/tools/ttl2sgml.c                      |   14 ++++++++---
 docs/tools/ttl_loader.c                    |   14 +++++++++++
 docs/tools/ttl_model.c                     |    6 ++++-
 docs/tools/ttl_model.h                     |    1 +
 docs/tools/ttl_sgml.c                      |   34 ++++++++++++++++++++++++++-
 docs/tools/ttl_sgml.h                      |    2 +-
 8 files changed, 84 insertions(+), 22 deletions(-)
---
diff --git a/docs/reference/ontology/ontology-docs.sgml b/docs/reference/ontology/ontology-docs.sgml
index 76ebe94..20d8411 100644
--- a/docs/reference/ontology/ontology-docs.sgml
+++ b/docs/reference/ontology/ontology-docs.sgml
@@ -17,6 +17,7 @@
 <!ENTITY maemo-ontology SYSTEM "maemo-ontology.xml">
 <!ENTITY ncal-ontology SYSTEM "ncal-ontology.xml">
 <!ENTITY scal-ontology SYSTEM "scal-ontology.xml">
+<!ENTITY fts-properties SYSTEM "fts-properties.xml">
 ]>
 <book id="index">
   <bookinfo>
@@ -58,6 +59,8 @@
     &maemo-ontology;
     &ncal-ontology;
     &scal-ontology;
+
+    &fts-properties;
   </part>
 
   <part id="ontology-notation-description">
diff --git a/docs/tools/gen-doc.sh b/docs/tools/gen-doc.sh
index 7b484fe..0be4134 100755
--- a/docs/tools/gen-doc.sh
+++ b/docs/tools/gen-doc.sh
@@ -6,21 +6,23 @@
 #
 BUILD_DIR="../reference/ontology/"
 
-echo "Generating list of classes-properties and files (file-class.cache)"
-if [ -e file-class.cache ]; then
-   rm -f file-class.cache ;
-fi
+echo "Preparing file full text index properties (fts-properties.xml)"
 
-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 "<?xml version='1.0' encoding='UTF-8'?>
+<chapter id='fts-properties'>
+<title>Full-text indexed properties in the ontology</title>
+<table frame='all'>
+  <colspec colname='Property'/>
+  <colspec colname='Weigth'/>
 
-#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
+  <thead>
+   <tr>
+     <td>Property</td>
+     <td>Weigth</td>
+   </tr>
+  </thead>
+
+<tbody>" > $BUILD_DIR/fts-properties.xml
 
 for f in `find ../../data/ontologies -name "*.description"` ; do
     # ../../data/ontologies/XX-aaa.description -> PREFIX=aaa
@@ -28,6 +30,8 @@ for f in `find ../../data/ontologies -name "*.description"` ; do
     PREFIX=${TMPNAME#*-}
     echo "Generating $PREFIX documentation"
 
-    ./ttl2sgml -d $f -o $BUILD_DIR/$PREFIX-ontology.xml -l file-class.cache \
+    ./ttl2sgml -d $f -o $BUILD_DIR/$PREFIX-ontology.xml -f $BUILD_DIR/fts-properties.xml \
 	-e ../../docs/ontologies/$PREFIX/explanation.xml
 done
+
+echo "</tbody></table></chapter>" >> $BUILD_DIR/fts-properties.xml
diff --git a/docs/tools/ttl2sgml.c b/docs/tools/ttl2sgml.c
index ec9982d..18cb455 100644
--- a/docs/tools/ttl2sgml.c
+++ b/docs/tools/ttl2sgml.c
@@ -8,7 +8,7 @@
 
 static gchar *desc_file = NULL;
 static gchar *output_file = NULL;
-static gchar *class_location_file = NULL;
+static gchar *fts_properties_file = NULL;
 static gchar *explanation_file = NULL;
 
 static GOptionEntry   entries[] = {
@@ -20,8 +20,8 @@ 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)",
+	{ "fts", 'f', 0, G_OPTION_ARG_FILENAME, &fts_properties_file,
+	  "Output file listing the full text indexed properties",
 	  NULL
 	},
 	{ "explanation", 'e', 0, G_OPTION_ARG_FILENAME, &explanation_file,
@@ -40,6 +40,7 @@ main (gint argc, gchar **argv)
 	gchar *ttl_file = NULL;
 	gchar *dirname = NULL;
 	FILE *f = NULL;
+        FILE *fts = NULL;
 
 	g_type_init ();
 
@@ -73,6 +74,10 @@ main (gint argc, gchar **argv)
 	}
 	g_assert (f != NULL);
 
+        if (fts_properties_file) {
+		fts = fopen (fts_properties_file, "a");
+        } 
+
 	description = ttl_loader_load_description (desc_file);
 
 	dirname = g_path_get_dirname (desc_file);
@@ -84,7 +89,7 @@ main (gint argc, gchar **argv)
 	g_free (ttl_file);
 	g_free (dirname);
 
-	ttl_sgml_print (description, ontology, f, class_location_file, explanation_file);
+	ttl_sgml_print (description, ontology, f, fts, explanation_file);
 
 	ttl_loader_free_ontology (ontology);
 	ttl_loader_free_description (description);
@@ -92,6 +97,7 @@ main (gint argc, gchar **argv)
 	g_option_context_free (context);
 
 	fclose (f);
+        fclose (fts);
 
 	return 0;
 }
diff --git a/docs/tools/ttl_loader.c b/docs/tools/ttl_loader.c
index 59d178d..6cefe30 100644
--- a/docs/tools/ttl_loader.c
+++ b/docs/tools/ttl_loader.c
@@ -20,6 +20,7 @@
 #define TRACKER_NS "http://www.tracker-project.org/ontologies/tracker#";
 #define TRACKER_NOTIFY TRACKER_NS "notify"
 #define TRACKER_FTS_INDEXED TRACKER_NS "fulltextIndexed"
+#define TRACKER_FTS_WEIGHT TRACKER_NS "weight"
 
 #define NAO_DEPRECATED "http://www.semanticdesktop.org/ontologies/2007/08/15/nao#deprecated";
 
@@ -131,6 +132,19 @@ load_in_memory (Ontology    *ontology,
 
 		prop->fulltextIndexed = string_to_boolean (turtle_object);
 
+	} else if (!g_strcmp0 (turtle_predicate, TRACKER_FTS_WEIGHT)) {
+		/*
+		 * A tracker: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;
diff --git a/docs/tools/ttl_model.c b/docs/tools/ttl_model.c
index 10edc5c..975b3dd 100644
--- a/docs/tools/ttl_model.c
+++ b/docs/tools/ttl_model.c
@@ -56,7 +56,7 @@ ttl_model_property_new (const gchar *propname)
 	prop->description = NULL;
 	prop->deprecated = FALSE;
         prop->fulltextIndexed = FALSE ;
-
+        prop->weight = NULL;
 	return prop;
 }
 
@@ -81,6 +81,10 @@ ttl_model_property_free (OntologyProperty *def)
 		g_free (def->description);
 	}
 
+        if (def->weight) {
+                g_free (def->weight);
+        }
+
 	g_free (def);
 }
 
diff --git a/docs/tools/ttl_model.h b/docs/tools/ttl_model.h
index 9ab609e..3c37255 100644
--- a/docs/tools/ttl_model.h
+++ b/docs/tools/ttl_model.h
@@ -28,6 +28,7 @@ typedef struct {
 	gchar *description;
 	gboolean deprecated;
         gboolean fulltextIndexed;
+        gchar *weight;
 } OntologyProperty;
 
 typedef struct {
diff --git a/docs/tools/ttl_sgml.c b/docs/tools/ttl_sgml.c
index cee666f..84ac38e 100644
--- a/docs/tools/ttl_sgml.c
+++ b/docs/tools/ttl_sgml.c
@@ -283,18 +283,44 @@ print_ontology_property (gpointer key, gpointer value, gpointer user_data)
         g_fprintf (f, "</refsect2>\n\n");
 }
 
+static void
+print_fts_properties (gpointer key, gpointer value, gpointer user_data)
+{
+	OntologyProperty *def = (OntologyProperty *) value;
+	gchar *name, *id;
+	FILE *fts = (FILE *) user_data;
+
+	g_return_if_fail (fts != NULL);
+        if (!def->fulltextIndexed) {
+                return;
+        }
+
+	name = qname_to_shortname (def->propertyname);
+        id = shortname_to_id (name);
+
+        g_fprintf (fts, "<tr>\n");
+        g_fprintf (fts, "  <td>\n");
+        print_reference (def->propertyname, fts);
+        g_fprintf (fts, "  </td>\n");
+        g_fprintf (fts, "  <td>%s</td>\n", (def->weight ? def->weight : "0"));
+        g_fprintf (fts, "</tr>\n");
+
+        g_free (id);
+
+}
+
 void
 ttl_sgml_print (OntologyDescription *description,
                 Ontology *ontology,
                 FILE *f,
-                const gchar *class_location_file,
+                FILE *fts,
                 const gchar *explanation_file)
 {
         gchar *upper_name;
 
         upper_name = g_ascii_strup (description->localPrefix, -1);
 
-        qname_init (description->baseUrl, description->localPrefix, class_location_file);
+        qname_init (description->baseUrl, description->localPrefix, NULL);
 	print_sgml_header (f, description);
 
         /* FIXME: make desc files sgml */
@@ -313,4 +339,8 @@ ttl_sgml_print (OntologyDescription *description,
 	print_sgml_footer (f);
 
         g_free (upper_name);
+
+        if (fts) {
+                g_hash_table_foreach (ontology->properties, print_fts_properties, fts);
+        }
 }
diff --git a/docs/tools/ttl_sgml.h b/docs/tools/ttl_sgml.h
index e016c19..b0bbbff 100644
--- a/docs/tools/ttl_sgml.h
+++ b/docs/tools/ttl_sgml.h
@@ -10,7 +10,7 @@ G_BEGIN_DECLS
 void ttl_sgml_print (OntologyDescription *description,
                      Ontology *ontology,
                      FILE *output,
-                     const gchar *class_location,
+                     FILE *class_location,
                      const gchar *explanation_file);
 
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]