static int raptor_rss_parse_init(raptor_parser* rdf_parser, const char *name) { raptor_rss_parser_context *rss_parser=(raptor_rss_parser_context*)rdf_parser->context; int i; RAPTOR_RDF_type_URI(rss_parser)=raptor_new_uri_for_rdf_concept("type"); RAPTOR_RDF_Seq_URI(rss_parser)=raptor_new_uri_for_rdf_concept("Seq"); for(i=0; i<RSS_NAMESPACES_SIZE;i++) { const char *uri_string=rss_namespace_uri_strings[i]; if(uri_string) rss_parser->namespace_uris[i]=raptor_new_uri((const unsigned char*)uri_string); } for(i=0; i< RAPTOR_RSS_COMMON_SIZE; i++) { raptor_uri *namespace_uri=rss_parser->namespace_uris[raptor_rss_types_info[i].nspace]; if(namespace_uri) raptor_rss_types_info[i].uri=raptor_new_uri_from_uri_local_name(namespace_uri, (const unsigned char*)raptor_rss_types_info[i].name); } for(i=0; i< RAPTOR_RSS_FIELDS_SIZE; i++) { raptor_uri *namespace_uri=rss_parser->namespace_uris[raptor_rss_fields_info[i].nspace]; if(namespace_uri) raptor_rss_fields_info[i].uri=raptor_new_uri_from_uri_local_name(namespace_uri, (const unsigned char*)raptor_rss_fields_info[i].name); } xmlSubstituteEntitiesDefault(1); return 0; }
manifest_world* manifest_new_world(rasqal_world* world) { manifest_world* mw; raptor_world* raptor_world_ptr = rasqal_world_get_raptor(world); mw = (manifest_world*)calloc(sizeof(*mw), 1); if(!mw) return NULL; mw->world = world; mw->raptor_world_ptr = raptor_world_ptr; /* Create Namespace URIs, concept URIs and rasqal literal concepts */ mw->rdfs_namespace_uri = raptor_new_uri(raptor_world_ptr, raptor_rdf_schema_namespace_uri); mw->mf_namespace_uri = raptor_new_uri(raptor_world_ptr, (const unsigned char*)"http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#"); mw->t_namespace_uri = raptor_new_uri(raptor_world_ptr, (const unsigned char*)"http://ns.librdf.org/2009/test-manifest#"); mw->qt_namespace_uri = raptor_new_uri(raptor_world_ptr, (const unsigned char*)"http://www.w3.org/2001/sw/DataAccess/tests/test-query#"); mw->dawgt_namespace_uri = raptor_new_uri(raptor_world_ptr, (const unsigned char*)"http://www.w3.org/2001/sw/DataAccess/tests/test-dawg#"); mw->sd_namespace_uri = raptor_new_uri(raptor_world_ptr, (const unsigned char*)"http://www.w3.org/ns/sparql-service-description#"); mw->mf_Manifest_uri = raptor_new_uri_from_uri_local_name(raptor_world_ptr, mw->mf_namespace_uri, (const unsigned char*)"Manifest"); mw->mf_entries_uri = raptor_new_uri_from_uri_local_name(raptor_world_ptr, mw->mf_namespace_uri, (const unsigned char*)"entries"); mw->mf_name_uri = raptor_new_uri_from_uri_local_name(raptor_world_ptr, mw->mf_namespace_uri, (const unsigned char*)"name"); mw->mf_action_uri = raptor_new_uri_from_uri_local_name(raptor_world_ptr, mw->mf_namespace_uri, (const unsigned char*)"action"); mw->mf_result_uri = raptor_new_uri_from_uri_local_name(raptor_world_ptr, mw->mf_namespace_uri, (const unsigned char*)"result"); mw->mf_resultCardinality_uri = raptor_new_uri_from_uri_local_name(raptor_world_ptr, mw->mf_namespace_uri, (const unsigned char*)"resultCardinality"); mw->rdf_type_uri = raptor_new_uri_for_rdf_concept(raptor_world_ptr, (const unsigned char*)"type"); mw->rdf_first_uri = raptor_new_uri_for_rdf_concept(raptor_world_ptr, (const unsigned char*)"first"); mw->rdf_rest_uri = raptor_new_uri_for_rdf_concept(raptor_world_ptr, (const unsigned char*)"rest"); mw->rdf_nil_uri = raptor_new_uri_for_rdf_concept(raptor_world_ptr, (const unsigned char*)"nil"); mw->rdfs_comment_uri = raptor_new_uri_from_uri_local_name(raptor_world_ptr, mw->rdfs_namespace_uri, (const unsigned char*)"comment"); mw->t_path_uri = raptor_new_uri_from_uri_local_name(raptor_world_ptr, mw->t_namespace_uri, (const unsigned char*)"path"); mw->qt_data_uri = raptor_new_uri_from_uri_local_name(raptor_world_ptr, mw->qt_namespace_uri, (const unsigned char*)"data"); mw->qt_graphData_uri = raptor_new_uri_from_uri_local_name(raptor_world_ptr, mw->qt_namespace_uri, (const unsigned char*)"graphData"); mw->qt_query_uri = raptor_new_uri_from_uri_local_name(raptor_world_ptr, mw->qt_namespace_uri, (const unsigned char*)"query"); mw->dawgt_approval_uri = raptor_new_uri_from_uri_local_name(raptor_world_ptr, mw->dawgt_namespace_uri, (const unsigned char*)"approval"); mw->sd_entailmentRegime_uri = raptor_new_uri_from_uri_local_name(raptor_world_ptr, mw->sd_namespace_uri, (const unsigned char*)"entailmentRegime"); mw->mf_Manifest_literal = rasqal_new_uri_literal(world, raptor_uri_copy(mw->mf_Manifest_uri)); mw->mf_entries_literal = rasqal_new_uri_literal(world, raptor_uri_copy(mw->mf_entries_uri)); mw->mf_name_literal = rasqal_new_uri_literal(world, raptor_uri_copy(mw->mf_name_uri)); mw->mf_action_literal = rasqal_new_uri_literal(world, raptor_uri_copy(mw->mf_action_uri)); mw->mf_result_literal = rasqal_new_uri_literal(world, raptor_uri_copy(mw->mf_result_uri)); mw->mf_resultCardinality_literal = rasqal_new_uri_literal(world, raptor_uri_copy(mw->mf_resultCardinality_uri)); mw->rdf_type_literal = rasqal_new_uri_literal(world, raptor_uri_copy(mw->rdf_type_uri)); mw->rdf_first_literal = rasqal_new_uri_literal(world, raptor_uri_copy(mw->rdf_first_uri)); mw->rdf_rest_literal = rasqal_new_uri_literal(world, raptor_uri_copy(mw->rdf_rest_uri)); mw->rdfs_comment_literal = rasqal_new_uri_literal(world, raptor_uri_copy(mw->rdfs_comment_uri)); mw->t_path_literal = rasqal_new_uri_literal(world, raptor_uri_copy(mw->t_path_uri)); mw->qt_data_literal = rasqal_new_uri_literal(world, raptor_uri_copy(mw->qt_data_uri)); mw->qt_graphData_literal = rasqal_new_uri_literal(world, raptor_uri_copy(mw->qt_graphData_uri)); mw->qt_query_literal = rasqal_new_uri_literal(world, raptor_uri_copy(mw->qt_query_uri)); mw->dawgt_approval_literal = rasqal_new_uri_literal(world, raptor_uri_copy(mw->dawgt_approval_uri)); mw->sd_entailmentRegime_literal = rasqal_new_uri_literal(world, raptor_uri_copy(mw->sd_entailmentRegime_uri)); return mw; }
int raptor_concepts_init(raptor_world* world) { int i; for(i = 0; i < RDF_NS_LAST + 1; i++) { unsigned char* name = (unsigned char*)raptor_rdf_ns_terms_info[i].name; world->concepts[i] = raptor_new_uri_for_rdf_concept(world, name); if(!world->concepts[i]) return 1; /* only make a term for things that are not syntax-only */ /* OR use: raptor_rdf_ns_terms_info[i].allowed_as_nodeElement || raptor_rdf_ns_terms_info[i].allowed_as_propertyElement || raptor_rdf_ns_terms_info[i].allowed_as_propertyAttribute) */ if(i > RDF_NS_LAST_SYNTAX_TERM) { world->terms[i] = raptor_new_term_from_uri(world, world->concepts[i]); if(!world->terms[i]) return 1; } } return 0; }
/** * librdf_node_get_literal_value_is_wf_xml: * @node: the node object * * Get the XML well-formness property of the node. * * Return value: 0 if the XML literal is NOT well formed XML content, or the node is not a literal **/ int librdf_node_get_literal_value_is_wf_xml(librdf_node *node) { raptor_uri* rdf_xml_literal_uri; int rc; LIBRDF_ASSERT_OBJECT_POINTER_RETURN_VALUE(node, librdf_node, 0); if(node->type != RAPTOR_TERM_TYPE_LITERAL) return 0; if(!node->value.literal.datatype) return 0; rdf_xml_literal_uri = raptor_new_uri_for_rdf_concept(node->world, (const unsigned char *)"XMLLiteral"); rc = librdf_uri_equals(node->value.literal.datatype, rdf_xml_literal_uri); raptor_free_uri(rdf_xml_literal_uri); return rc; }
int rasqal_query_write_sparql_20060406(raptor_iostream *iostr, rasqal_query* query, raptor_uri *base_uri) { int i; sparql_writer_context wc; int limit, offset; rasqal_query_verb verb; wc.world = query->world; wc.base_uri = NULL; wc.type_uri = raptor_new_uri_for_rdf_concept(query->world->raptor_world_ptr, (const unsigned char*)"type"); wc.nstack = raptor_new_namespaces(query->world->raptor_world_ptr, 1); if(base_uri) { raptor_iostream_counted_string_write("BASE ", 5, iostr); rasqal_query_write_sparql_uri(&wc, iostr, base_uri); raptor_iostream_write_byte('\n', iostr); /* from now on all URIs are relative to this */ wc.base_uri = raptor_uri_copy(base_uri); } for(i = 0; 1 ; i++) { raptor_namespace *nspace; rasqal_prefix* p = rasqal_query_get_prefix(query, i); if(!p) break; raptor_iostream_counted_string_write("PREFIX ", 7, iostr); if(p->prefix) raptor_iostream_string_write(p->prefix, iostr); raptor_iostream_counted_string_write(": ", 2, iostr); rasqal_query_write_sparql_uri(&wc, iostr, p->uri); raptor_iostream_write_byte('\n', iostr); /* Use this constructor so we copy a URI directly */ nspace = raptor_new_namespace_from_uri(wc.nstack, p->prefix, p->uri, i); raptor_namespaces_start_namespace(wc.nstack, nspace); } if(query->explain) raptor_iostream_counted_string_write("EXPLAIN ", 8, iostr); verb = query->verb; /* These terms are deprecated */ if(query->verb == RASQAL_QUERY_VERB_INSERT || query->verb == RASQAL_QUERY_VERB_DELETE) { verb = RASQAL_QUERY_VERB_UPDATE; } /* Write SPARQL 1.1 (Draft) Update forms */ if(verb == RASQAL_QUERY_VERB_UPDATE) { rasqal_update_operation* update; /* Write SPARQL Update */ for(i = 0; (update = rasqal_query_get_update_operation(query, i)); i++) { int is_always_2_args = (update->type >= RASQAL_UPDATE_TYPE_ADD && update->type <= RASQAL_UPDATE_TYPE_COPY); if(update->type == RASQAL_UPDATE_TYPE_UPDATE) { /* update operations: * WITH ... INSERT { template } DELETE { template } WHERE { template } * INSERT/DELETE { template } WHERE { template } * INSERT/DELETE DATA { triples } */ if(update->graph_uri) { raptor_iostream_counted_string_write("WITH ", 5, iostr); rasqal_query_write_sparql_uri(&wc, iostr, update->graph_uri); raptor_iostream_write_byte('\n', iostr); } if(update->delete_templates) { raptor_iostream_counted_string_write("DELETE ", 7, iostr); if(update->flags & RASQAL_UPDATE_FLAGS_DATA) raptor_iostream_counted_string_write("DATA ", 5, iostr); rasqal_query_write_sparql_triple_data(&wc, iostr, update->delete_templates, 0); raptor_iostream_write_byte('\n', iostr); } if(update->insert_templates) { raptor_iostream_counted_string_write("INSERT ", 7, iostr); if(update->flags & RASQAL_UPDATE_FLAGS_DATA) raptor_iostream_counted_string_write("DATA ", 5, iostr); rasqal_query_write_sparql_triple_data(&wc, iostr, update->insert_templates, 0); raptor_iostream_write_byte('\n', iostr); } if(update->where) { raptor_iostream_counted_string_write("WHERE ", 6, iostr); rasqal_query_write_sparql_graph_pattern(&wc, iostr, update->where, -1, 0); raptor_iostream_write_byte('\n', iostr); } } else { /* admin operations: * CLEAR GRAPH graph-uri | DEFAULT | NAMED | ALL * CREATE (SILENT) GRAPH graph-uri | DEFAULT | NAMED | ALL * DROP (SILENT) GRAPH graph-uri * LOAD (SILENT) doc-uri / LOAD (SILENT) doc-uri INTO GRAPH graph-uri * ADD (SILENT) GraphOrDefault TO GraphOrDefault * MOVE (SILENT) GraphOrDefault TO GraphOrDefault * COPY (SILENT) GraphOrDefault TO GraphOrDefault */ raptor_iostream_string_write(rasqal_update_type_label(update->type), iostr); if(update->flags & RASQAL_UPDATE_FLAGS_SILENT) raptor_iostream_counted_string_write(" SILENT", 7, iostr); if(is_always_2_args) { /* ADD, MOVE, COPY are always 2-arg admin operations */ rasqal_query_write_graphref(&wc, iostr, update->graph_uri, RASQAL_UPDATE_GRAPH_ONE); raptor_iostream_counted_string_write(" TO", 3, iostr); rasqal_query_write_graphref(&wc, iostr, update->document_uri, RASQAL_UPDATE_GRAPH_ONE); } else if(update->type == RASQAL_UPDATE_TYPE_LOAD) { /* LOAD is 1 or 2 URIs and first one never has a GRAPH prefix */ raptor_iostream_write_byte(' ', iostr); rasqal_query_write_sparql_uri(&wc, iostr, update->document_uri); if(update->graph_uri) { raptor_iostream_counted_string_write(" INTO", 5, iostr); rasqal_query_write_graphref(&wc, iostr, update->graph_uri, RASQAL_UPDATE_GRAPH_ONE); } } else { /* everything else is defined by update->applies; only * CLEAR and DROP may apply to >1 graph */ rasqal_query_write_graphref(&wc, iostr, update->graph_uri, update->applies); } raptor_iostream_write_byte('\n', iostr); } } goto tidy; } if(verb != RASQAL_QUERY_VERB_CONSTRUCT) raptor_iostream_string_write(rasqal_query_verb_as_string(query->verb), iostr); if(query->distinct) { if(query->distinct == 1) raptor_iostream_counted_string_write(" DISTINCT", 9, iostr); else raptor_iostream_counted_string_write(" REDUCED", 8, iostr); } if(query->wildcard) raptor_iostream_counted_string_write(" *", 2, iostr); else if(verb == RASQAL_QUERY_VERB_DESCRIBE) { raptor_sequence *lit_seq = query->describes; int count = raptor_sequence_size(lit_seq); for(i = 0; i < count; i++) { rasqal_literal* l = (rasqal_literal*)raptor_sequence_get_at(lit_seq, i); raptor_iostream_write_byte(' ', iostr); rasqal_query_write_sparql_literal(&wc, iostr, l); } } else if(verb == RASQAL_QUERY_VERB_SELECT) { rasqal_query_write_sparql_select(&wc, iostr, query->selects); } raptor_iostream_write_byte('\n', iostr); if(query->data_graphs) { for(i = 0; 1; i++) { rasqal_data_graph* dg = rasqal_query_get_data_graph(query, i); if(!dg) break; if(dg->flags & RASQAL_DATA_GRAPH_NAMED) continue; rasqal_query_write_data_format_comment(&wc, iostr, dg); raptor_iostream_counted_string_write("FROM ", 5, iostr); rasqal_query_write_sparql_uri(&wc, iostr, dg->uri); raptor_iostream_counted_string_write("\n", 1, iostr); } for(i = 0; 1; i++) { rasqal_data_graph* dg = rasqal_query_get_data_graph(query, i); if(!dg) break; if(!(dg->flags & RASQAL_DATA_GRAPH_NAMED)) continue; rasqal_query_write_data_format_comment(&wc, iostr, dg); raptor_iostream_counted_string_write("FROM NAMED ", 11, iostr); rasqal_query_write_sparql_uri(&wc, iostr, dg->name_uri); raptor_iostream_write_byte('\n', iostr); } } if(query->constructs) { raptor_iostream_string_write("CONSTRUCT {\n", iostr); for(i = 0; 1; i++) { rasqal_triple* t = rasqal_query_get_construct_triple(query, i); if(!t) break; raptor_iostream_counted_string_write(" ", 2, iostr); rasqal_query_write_sparql_triple(&wc, iostr, t); raptor_iostream_write_byte('\n', iostr); } raptor_iostream_counted_string_write("}\n", 2, iostr); } if(query->query_graph_pattern) { raptor_iostream_counted_string_write("WHERE ", 6, iostr); rasqal_query_write_sparql_graph_pattern(&wc, iostr, query->query_graph_pattern, -1, 0); raptor_iostream_write_byte('\n', iostr); } if(rasqal_query_get_group_conditions_sequence(query)) { raptor_iostream_counted_string_write("GROUP BY ", 9, iostr); for(i = 0; 1; i++) { rasqal_expression* expr = rasqal_query_get_group_condition(query, i); if(!expr) break; if(i > 0) raptor_iostream_write_byte(' ', iostr); rasqal_query_write_sparql_expression(&wc, iostr, expr); } raptor_iostream_write_byte('\n', iostr); } if(rasqal_query_get_having_conditions_sequence(query)) { raptor_iostream_counted_string_write("HAVING ", 7, iostr); for(i = 0; 1; i++) { rasqal_expression* expr = rasqal_query_get_having_condition(query, i); if(!expr) break; if(i > 0) raptor_iostream_write_byte(' ', iostr); rasqal_query_write_sparql_expression(&wc, iostr, expr); } raptor_iostream_write_byte('\n', iostr); } if(rasqal_query_get_order_conditions_sequence(query)) { raptor_iostream_counted_string_write("ORDER BY ", 9, iostr); for(i = 0; 1; i++) { rasqal_expression* expr = rasqal_query_get_order_condition(query, i); if(!expr) break; if(i > 0) raptor_iostream_write_byte(' ', iostr); rasqal_query_write_sparql_expression(&wc, iostr, expr); } raptor_iostream_write_byte('\n', iostr); } limit = rasqal_query_get_limit(query); offset = rasqal_query_get_offset(query); if(limit >= 0 || offset >= 0) { if(limit >= 0) { raptor_iostream_counted_string_write("LIMIT ", 7, iostr); raptor_iostream_decimal_write(limit, iostr); } if(offset >= 0) { if(limit) raptor_iostream_write_byte(' ', iostr); raptor_iostream_counted_string_write("OFFSET ", 8, iostr); raptor_iostream_decimal_write(offset, iostr); } raptor_iostream_write_byte('\n', iostr); } if(query->bindings) rasqal_write_sparql_bindings(&wc, iostr, query->bindings); tidy: raptor_free_uri(wc.type_uri); if(wc.base_uri) raptor_free_uri(wc.base_uri); raptor_free_namespaces(wc.nstack); return 0; }
/* create a new serializer */ static int raptor_turtle_serialize_init(raptor_serializer* serializer, const char *name) { raptor_turtle_context* context = (raptor_turtle_context*)serializer->context; raptor_uri *rdf_type_uri; context->nstack = raptor_new_namespaces(serializer->world, 1); if(!context->nstack) return 1; context->rdf_nspace = raptor_new_namespace(context->nstack, (const unsigned char*)"rdf", (const unsigned char*)raptor_rdf_namespace_uri, 0); context->namespaces = raptor_new_sequence(NULL, NULL); context->subjects = raptor_new_avltree((raptor_data_compare_handler)raptor_abbrev_subject_compare, (raptor_data_free_handler)raptor_free_abbrev_subject, 0); context->blanks = raptor_new_avltree((raptor_data_compare_handler)raptor_abbrev_subject_compare, (raptor_data_free_handler)raptor_free_abbrev_subject, 0); context->nodes = raptor_new_avltree((raptor_data_compare_handler)raptor_abbrev_node_compare, (raptor_data_free_handler)raptor_free_abbrev_node, 0); rdf_type_uri = raptor_new_uri_for_rdf_concept(serializer->world, (const unsigned char*)"type"); if(rdf_type_uri) { raptor_term* uri_term; uri_term = raptor_new_term_from_uri(serializer->world, rdf_type_uri); raptor_free_uri(rdf_type_uri); context->rdf_type = raptor_new_abbrev_node(serializer->world, uri_term); raptor_free_term(uri_term); } else context->rdf_type = NULL; context->rdf_xml_literal_uri = raptor_new_uri(serializer->world, raptor_xml_literal_datatype_uri_string); context->rdf_first_uri = raptor_new_uri(serializer->world, (const unsigned char*)"http://www.w3.org/1999/02/22-rdf-syntax-ns#first"); context->rdf_rest_uri = raptor_new_uri(serializer->world, (const unsigned char*)"http://www.w3.org/1999/02/22-rdf-syntax-ns#rest"); context->rdf_nil_uri = raptor_new_uri(serializer->world, (const unsigned char*)"http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"); if(!context->rdf_nspace || !context->namespaces || !context->subjects || !context->blanks || !context->nodes || !context->rdf_xml_literal_uri || !context->rdf_first_uri || !context->rdf_rest_uri || !context->rdf_nil_uri || !context->rdf_type) { raptor_turtle_serialize_terminate(serializer); return 1; } /* Note: item 0 in the list is rdf:RDF's namespace */ if(raptor_sequence_push(context->namespaces, context->rdf_nspace)) { raptor_turtle_serialize_terminate(serializer); return 1; } return 0; }