[redland-dev] processing results
Jagdev Bhogal
Jagdev.Bhogal at uce.ac.uk
Wed May 9 13:28:54 BST 2007
Hello
I have got the following code which reads the news.rdf file and outputs
the results of the query (basically all 84 records) to a queryoutput
file.
However the code only seems to go around the while loop once, when I
expect it go around 84 times.
When I am debugging it I use a counter called qocount to tell me how
many times the code goes around the while loop.
What I need to do is process the variables and bindings in record 1 ,
then record 2 etc until all records in the result have been processed.
I am obviously missing something, I hope you can help me out on this.
Thanks
main()
{
int i, qocount;
rasqal_query *rq;
rasqal_query_results *results;
const unsigned char *value_string;
const char *outcome;
char keyword[]="Content:Abstract";
raptor_iostream *qo;
const char *query_string="select ?label, ?comment from
<file:/export/CISR-D/jagdev/okapi/progs/news.rdf> where (?x rdf:type
rdfs:Class) (?x,rdfs:label, ?label), (?x, rdfs:comment, ?comment) using
rdf for <http://www.w3.org/1999/02/22-rdf-syntax-ns#>, rdfs for
<http://www.w3.org/2000/01/rdf-schema#>";
const char *qfilename="queryoutput";
rasqal_init();
rq=rasqal_new_query("rdql",NULL);
raptor_init();
qo=raptor_new_iostream_to_filename(qfilename);
rasqal_query_prepare(rq,query_string, NULL);
results=rasqal_query_execute(rq);
qocount=0;
while(!rasqal_query_results_finished(results)) {
for(i=0;i<rasqal_query_results_get_bindings_count(results);i++) {
const char
*name=rasqal_query_results_get_binding_name(results,i);
rasqal_literal *value;
value=rasqal_query_results_get_binding_value(results,i);
rasqal_literal_print(value, stderr);
value_string=rasqal_literal_as_string(value);
if (strcmp(value_string,keyword) == 0)
fprintf(stderr,"Match found \n");
fprintf(stderr,"writing line %d in queryoutput file \n",qocount);
qocount++;
rasqal_query_results_write(qo,results,NULL,NULL);
}
fprintf(stderr,"results count is
%d\n",rasqal_query_results_get_count(results));
rasqal_query_results_next(results);
}
raptor_free_iostream(qo);
rasqal_free_query_results(results);
rasqal_free_query(rq);
rasqal_finish();
raptor_finish();
}
Many thanks
Mrs Jagdev Bhogal
Senior Lecturer in Database Systems
Dept. of Computing
University of Central England
Feeney Building
Perry Barr
Birmingham
B42 2SU
Tel: 0121 331 7658
Mrs Jagdev Bhogal
Senior Lecturer in Database Systems
Dept. of Computing
University of Central England
Feeney Building
Perry Barr
Birmingham
B42 2SU
Tel: 0121 331 7658
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.usefulinc.com/pipermail/redland-dev/attachments/20070509/3aef84ec/attachment.htm
More information about the redland-dev
mailing list