示例#1
0
文件: utilities.c 项目: h0st/m3sec
ssStatus_t parseM3_sparql_bindings(GSList** template_query_, unsigned char * query_str, sib_data_structure* p)
{
	GSList* template_query =NULL;
	librdf_world * world;
	rasqal_query* rq;
	rasqal_graph_pattern* gp;

    gchar*		prefix_query_str;
    gchar*		prefix_str;

    //printf("RECEIVED SPARQL IN\n");
    //printf("q: %s\n",op->req->query_str);


    prefix_str= g_strdup_printf("PREFIX %s <%s> PREFIX %s <%s> PREFIX %s <%s> PREFIX %s <%s>  ",rdf_c ,rdf_ex ,fn_c_2,fn_ex,rdfs_c,rdfs_ex,xsd_c , xsd_ex);
    prefix_query_str=g_strdup_printf("%s %s", prefix_str, query_str);

	rq = rasqal_new_query(p->sparql_preprocessing_world, "sparql",NULL);
	//printf ("pre parsing\n");

	if(rasqal_query_prepare(rq, prefix_query_str, NULL)) {

		rasqal_free_query(rq);
		rq = NULL;
		*template_query_ =template_query;

		g_free( prefix_str);
		g_free( prefix_query_str);

		rasqal_free_world(world);
		return ss_GeneralError;
	}

	//printf ("query prepared\n");
	gp = rasqal_query_get_query_graph_pattern(rq);

	navigator_graph_pattern_load(gp, -1,  0, &template_query);

	*template_query_ =template_query;

	g_free( prefix_str);
	g_free( prefix_query_str);

	rasqal_free_query(rq);

	return ss_StatusOK;
}
示例#2
0
文件: roqet.c 项目: sengels/rasqal
static void
roqet_query_walk(rasqal_query *rq, FILE *fh, int indent) {
    rasqal_query_verb verb;
    int i;
    rasqal_graph_pattern* gp;
    raptor_sequence *seq;

    verb = rasqal_query_get_verb(rq);
    roqet_write_indent(fh, indent);
    fprintf(fh, "query verb: %s\n", rasqal_query_verb_as_string(verb));

    i = rasqal_query_get_distinct(rq);
    if(i != 0) {
        roqet_write_indent(fh, indent);
        fprintf(fh, "query asks for distinct results\n");
    }

    i = rasqal_query_get_limit(rq);
    if(i >= 0) {
        roqet_write_indent(fh, indent);
        fprintf(fh, "query asks for result limits %d\n", i);
    }

    i = rasqal_query_get_offset(rq);
    if(i >= 0) {
        roqet_write_indent(fh, indent);
        fprintf(fh, "query asks for result offset %d\n", i);
    }

    seq = rasqal_query_get_bound_variable_sequence(rq);
    if(seq && raptor_sequence_size(seq) > 0) {
        fprintf(fh, "query bound variables (%d): ",
                raptor_sequence_size(seq));
        i = 0;
        while(1) {
            rasqal_variable* v = (rasqal_variable*)raptor_sequence_get_at(seq, i);
            if(!v)
                break;

            if(i > 0)
                fputs(", ", fh);

            roqet_query_write_variable(fh, v);
            i++;
        }
        fputc('\n', fh);
    }

    gp = rasqal_query_get_query_graph_pattern(rq);
    if(!gp)
        return;


    seq = rasqal_query_get_construct_triples_sequence(rq);
    if(seq && raptor_sequence_size(seq) > 0) {
        roqet_write_indent(fh, indent);
        fprintf(fh, "query construct triples (%d) {\n",
                raptor_sequence_size(seq));
        i = 0;
        while(1) {
            rasqal_triple* t = rasqal_query_get_construct_triple(rq, i);
            if(!t)
                break;

            roqet_write_indent(fh, indent + 2);
            fprintf(fh, "triple #%d { ", i);
            rasqal_triple_print(t, fh);
            fputs(" }\n", fh);

            i++;
        }
        roqet_write_indent(fh, indent);
        fputs("}\n", fh);
    }

    /* look for binding rows */
    seq = rasqal_query_get_bindings_variables_sequence(rq);
    if(seq) {
        roqet_write_indent(fh, indent);
        fprintf(fh, "bindings variables (%d): ",  raptor_sequence_size(seq));

        i = 0;
        while(1) {
            rasqal_variable* v = rasqal_query_get_bindings_variable(rq, i);
            if(!v)
                break;

            if(i > 0)
                fputs(", ", fh);

            roqet_query_write_variable(fh, v);
            i++;
        }
        fputc('\n', fh);

        seq = rasqal_query_get_bindings_rows_sequence(rq);

        fprintf(fh, "bindings rows (%d) {\n", raptor_sequence_size(seq));
        i = 0;
        while(1) {
            rasqal_row* row;

            row = rasqal_query_get_bindings_row(rq, i);
            if(!row)
                break;

            roqet_write_indent(fh, indent + 2);
            fprintf(fh, "row #%d { ", i);
            rasqal_row_print(row, fh);
            fputs("}\n", fh);

            i++;
        }
    }


    fputs("query ", fh);
    roqet_graph_pattern_walk(gp, -1, fh, indent);
}