Mercurial > hg > audiodb
comparison examples/runner-rdf/populate.c @ 644:404222029e27
Grab bag of populate.c improvements
no need for fileUri (and in fact it was wrong for files with %s in them); use
librdf_new_uri_from_filename.
Use the basename of the audio filename as the key, just for my own sanity.
People who want file://///// everywhere can write their own populate.c.
author | mas01cr |
---|---|
date | Tue, 13 Oct 2009 14:26:26 +0000 |
parents | 46673db7c6a4 |
children |
comparison
equal
deleted
inserted
replaced
643:09af91f8803f | 644:404222029e27 |
---|---|
1 #include <sys/types.h> | 1 #include <sys/types.h> |
2 #include <sys/stat.h> | 2 #include <sys/stat.h> |
3 #include <libgen.h> | |
3 #include <unistd.h> | 4 #include <unistd.h> |
4 #include <librdf.h> | 5 #include <librdf.h> |
5 #include <fcntl.h> | 6 #include <fcntl.h> |
6 #include <string.h> | 7 #include <string.h> |
7 #include <stdlib.h> | 8 #include <stdlib.h> |
12 " PREFIX af: <http://purl.org/ontology/af/>" | 13 " PREFIX af: <http://purl.org/ontology/af/>" |
13 " PREFIX dc: <http://purl.org/dc/elements/1.1/>" | 14 " PREFIX dc: <http://purl.org/dc/elements/1.1/>" |
14 " PREFIX mo: <http://purl.org/ontology/mo/>" | 15 " PREFIX mo: <http://purl.org/ontology/mo/>" |
15 " PREFIX tl: <http://purl.org/NET/c4dm/timeline.owl#>" | 16 " PREFIX tl: <http://purl.org/NET/c4dm/timeline.owl#>" |
16 | 17 |
17 " SELECT ?key ?value ?sample_rate ?window_length ?hop_size ?dimensions ?typetitle" | 18 " SELECT ?key ?value ?sample_rate ?window_length ?hop_size ?dimensions" |
18 " FROM <file:///home/csr21/tmp/rdf/test2.n3> " | |
19 | 19 |
20 " WHERE { " | 20 " WHERE { " |
21 " ?key a mo:AudioFile . " | 21 " ?key a mo:AudioFile . " |
22 " ?signal a mo:Signal . " | 22 " ?signal a mo:Signal . " |
23 " ?key mo:encodes ?signal ." | 23 " ?key mo:encodes ?signal ." |
34 | 34 |
35 " ?feature a ?feature_signal_type ; " | 35 " ?feature a ?feature_signal_type ; " |
36 " mo:time [ tl:onTimeLine ?feature_timeline ] ; " | 36 " mo:time [ tl:onTimeLine ?feature_timeline ] ; " |
37 " af:value ?value . " | 37 " af:value ?value . " |
38 " ?feature af:dimensions ?dimensions ." | 38 " ?feature af:dimensions ?dimensions ." |
39 | |
40 " ?feature_signal_type dc:title ?typetitle " | |
41 | 39 |
42 " } " | 40 " } " |
43 ; | 41 ; |
44 | 42 |
45 double *parse_value_string(const char *value_string, size_t *nelements) { | 43 double *parse_value_string(const char *value_string, size_t *nelements) { |
87 | 85 |
88 librdf_model *model; | 86 librdf_model *model; |
89 if (!(model = librdf_new_model(world, storage, NULL))) | 87 if (!(model = librdf_new_model(world, storage, NULL))) |
90 goto librdf_error; | 88 goto librdf_error; |
91 | 89 |
92 | |
93 char *fileUri = malloc(sizeof(char)*(strlen(n3file)+6)); | |
94 sprintf(fileUri, "file:%s\0", n3file); | |
95 | |
96 librdf_uri *uri; | 90 librdf_uri *uri; |
97 if (!(uri = librdf_new_uri(world, fileUri))) | 91 if (!(uri = librdf_new_uri_from_filename(world, n3file))) |
98 goto librdf_error; | 92 goto librdf_error; |
99 | |
100 free(fileUri); | |
101 | 93 |
102 librdf_parser *parser; | 94 librdf_parser *parser; |
103 if (!(parser = librdf_new_parser(world, "guess", NULL, NULL))) | 95 if (!(parser = librdf_new_parser(world, "guess", NULL, NULL))) |
104 goto librdf_error; | 96 goto librdf_error; |
105 | 97 |
167 char* dimensions = librdf_node_get_literal_value(node); | 159 char* dimensions = librdf_node_get_literal_value(node); |
168 | 160 |
169 int dimension = 0; | 161 int dimension = 0; |
170 sscanf(dimensions, "%d", &dimension); | 162 sscanf(dimensions, "%d", &dimension); |
171 datum.dim = dimension; | 163 datum.dim = dimension; |
172 | 164 |
173 node = librdf_query_results_get_binding_value_by_name(results, "typetitle"); | |
174 printf("Insert feature of type %s\n", librdf_node_get_literal_value(node)); | |
175 | |
176 // Grab key and value | 165 // Grab key and value |
177 | 166 |
178 node = librdf_query_results_get_binding_value_by_name(results, "key"); | 167 node = librdf_query_results_get_binding_value_by_name(results, "key"); |
179 datum.key = librdf_uri_as_string(librdf_node_get_uri(node)); | 168 char *key = strdup(librdf_uri_to_filename(librdf_node_get_uri(node))); |
169 datum.key = basename(key); | |
180 | 170 |
181 size_t nelements = 0; | 171 size_t nelements = 0; |
182 node = librdf_query_results_get_binding_value_by_name(results, "value"); | 172 node = librdf_query_results_get_binding_value_by_name(results, "value"); |
183 datum.data = parse_value_string(librdf_node_get_literal_value(node), &nelements); | 173 datum.data = parse_value_string(librdf_node_get_literal_value(node), &nelements); |
184 | 174 |