changeset 583:46673db7c6a4

No changes... oddly
author mas01mj
date Tue, 28 Jul 2009 13:49:49 +0000
parents 29f3289bb183
children e3790284fd4a
files examples/runner-rdf/populate.c
diffstat 1 files changed, 73 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/examples/runner-rdf/populate.c	Tue Jul 28 13:49:48 2009 +0000
+++ b/examples/runner-rdf/populate.c	Tue Jul 28 13:49:49 2009 +0000
@@ -14,13 +14,13 @@
 " PREFIX mo: <http://purl.org/ontology/mo/>"
 " PREFIX tl: <http://purl.org/NET/c4dm/timeline.owl#>"
 
-" SELECT ?key ?value ?sample_rate ?window_length ?hop_size"
-" FROM <file:///home/csr21/tmp/rdf/test.n3> "
+" SELECT ?key ?value ?sample_rate ?window_length ?hop_size ?dimensions ?typetitle"
+" FROM <file:///home/csr21/tmp/rdf/test2.n3> "
 
 " WHERE { "
-
-"   ?signal mo:available_as ?key ."
-
+"   ?key a mo:AudioFile . "
+"   ?signal a mo:Signal . "
+"   ?key mo:encodes ?signal ."
 "   ?signal mo:time [ tl:onTimeLine ?signal_timeline ] . "
 
 "   ?timeline_map a tl:UniformSamplingWindowingMap ; "
@@ -35,8 +35,9 @@
 "   ?feature a ?feature_signal_type ; "
 "     mo:time [ tl:onTimeLine ?feature_timeline ] ; "
 "     af:value ?value . "
+"   ?feature af:dimensions ?dimensions ."
 
-"   ?feature_signal_type dc:title \"Key Strength Plot\""
+"   ?feature_signal_type dc:title ?typetitle "
 
 " } "
 ;
@@ -44,6 +45,7 @@
 double *parse_value_string(const char *value_string, size_t *nelements) {
   /* What error checking? */
 
+
   *nelements = 0;
 
   const char *current = value_string;
@@ -53,7 +55,6 @@
   double *buf = (double *) malloc(size * sizeof(double));
   double value = strtod(current, &next);
   while(next != current) {
-    printf("Value: %f\n", value);
     buf[(*nelements)++] = value;
     if((*nelements) == size) {
       size *= 2;
@@ -65,7 +66,17 @@
   return buf;
 }
 
-int main() {
+int main(int argc, char* argv[]) {
+  
+  if(argc != 3)
+  {
+    fprintf(stderr, "Usage: %s <n3file> <dbfile>\n", argv[0]);
+    return 2;
+  }
+  
+  char* n3file = argv[1];
+  char* dbfile = argv[2];
+  
   librdf_world *world;
   if (!(world = librdf_new_world())) 
     goto librdf_error;
@@ -77,11 +88,17 @@
   librdf_model *model;
   if (!(model = librdf_new_model(world, storage, NULL)))
     goto librdf_error;
+  
+  
+  char *fileUri = malloc(sizeof(char)*(strlen(n3file)+6));
+  sprintf(fileUri, "file:%s\0", n3file);
 
   librdf_uri *uri;
-  if (!(uri = librdf_new_uri(world, "file:data/test.n3")))
+  if (!(uri = librdf_new_uri(world, fileUri)))
     goto librdf_error;
 
+  free(fileUri);
+
   librdf_parser *parser;
   if (!(parser = librdf_new_parser(world, "guess", NULL, NULL)))
     goto librdf_error;
@@ -101,10 +118,11 @@
     goto librdf_error;
 
   adb_t *adb; 
-  if(!(adb = audiodb_open("keyplot.adb", O_RDWR))) {
+  if(!(adb = audiodb_open(dbfile, O_RDWR))) {
+    
     struct stat st;
-    if(!(stat("keyplot.adb", &st))) {
-      fprintf(stderr, "keyplot.adb not opened.\n");
+    if(!(stat(dbfile, &st))) {
+      fprintf(stderr, "%s not opened.\n", dbfile);
       return 1;
     } else {
       /* FIXME: if we are doing a proper SPARQL query over a
@@ -125,35 +143,56 @@
 
        * (also NOTE: this audiodb_create() interface is scheduled for
        * being made less inelegant.) */
-      if(!(adb = audiodb_create("keyplot.adb", 0, 0, 0))) {
-        fprintf(stderr, "failed to create keyplot.adb.\n");
+      if(!(adb = audiodb_create(dbfile, 0, 0, 0))) {
+        fprintf(stderr, "failed to create %s.\n", dbfile);
         return 1;
       }
     }
   }
 
+  if(librdf_query_results_finished(results))
+  {
+    fprintf(stderr, "No features found!\n");
+    return 3;
+  }
+  
+
   while(!librdf_query_results_finished(results)) {
-    int count = librdf_query_results_get_bindings_count(results);
+    
     adb_datum_t datum = {0};
-    datum.dim = 25;
-    for (int i = 0; i < count; i++) {
-      const char *name = librdf_query_results_get_binding_name(results, i);
-      librdf_node *node = librdf_query_results_get_binding_value(results, i);
-      if(!node) return 2;
-
-      if(!strcmp(name, "key")) {
-        datum.key = librdf_uri_as_string(librdf_node_get_uri(node));
-      } else if(!strcmp(name, "value")) {
-        size_t nelements = 0;
-        datum.data = parse_value_string(librdf_node_get_literal_value(node), &nelements);
-        if(nelements % 25) return 4;
-        datum.nvectors = nelements / 25;
-      } else {
-        /* do something with the timeline (and other) information */
-        printf("%s: %s\n", name, librdf_node_get_literal_value(node));
-      }
-      librdf_free_node(node);
-    }
+    
+    // Pull out the dimension
+    
+    librdf_node *node = librdf_query_results_get_binding_value_by_name(results, "dimensions");
+    char* dimensions = librdf_node_get_literal_value(node);
+   
+    int dimension = 0;
+    sscanf(dimensions, "%d", &dimension);
+    datum.dim = dimension;
+    
+    node = librdf_query_results_get_binding_value_by_name(results, "typetitle");
+    printf("Insert feature of type %s\n", librdf_node_get_literal_value(node));
+    
+    // Grab key and value
+    
+    node = librdf_query_results_get_binding_value_by_name(results, "key");
+    datum.key = librdf_uri_as_string(librdf_node_get_uri(node));
+    
+    size_t nelements = 0;
+    node = librdf_query_results_get_binding_value_by_name(results, "value");
+    datum.data = parse_value_string(librdf_node_get_literal_value(node), &nelements);
+    
+    // Validate that we have the correct number of elements
+    
+    if(nelements % dimension) return 4;
+    datum.nvectors = nelements / dimension;
+    
+    printf("Dimension: %d\n", dimension);
+    printf("Key: %s\n", datum.key);
+    printf("Vectors: %d\n", datum.nvectors);
+    
+    librdf_free_node(node);
+    
     if(audiodb_insert_datum(adb, &datum)) {
       fprintf(stderr, "failed to insert datum with key %s.\n", datum.key);
       return 1;