Hello Percy, Wed, 2011-05-25 at 13:47 -0300, Percy Enrique Rivera Salas wrote: > Hello everyone > > I would like to know if virtuoso have a function similar to > bif:contains, for predicate values. > > Your request is the first one, so there was no need before and hence no such feature. It is technically possible to make it, but rather later than sooner.
> For example: I want to get all the properties from DBpedia which > predicates start with "http://dbpedia.org". > > I'm currently using the following SPARQL query that use expensive > regular expression (regex) > > select ?p > where{ > ?s ?p ?o. > FILTER(regex(?p,"http://dbpedia.org")) > } For things like that, a Virtuoso/PL procedure can be used, listed below. If you want to use its output inside SPARQL queries it can be wrapped by a procedure view and it in turn can be used in an RDF View but it is redundand for most of applications. For typical "almost static" data, it is more practical to write a procedure that will store all found predicates in some dedicated "dictionary" graph and then use the graph as usual. Best Regards, Ivan Mikhailov OpenLink Software http://virtuoso.openlinksw.com -- The procedure: create procedure PREDICATES_OF_IRI_PATH (in path varchar, in dump_iri_ids integer := 0) { declare PRED_IRI varchar; declare PRED_IRI_ID IRI_ID; declare path_head_len integer; if (dump_iri_ids) result_names (PRED_IRI_ID); else result_names (PRED_IRI); for (select RP_NAME, RP_ID from RDF_PREFIX where (RP_NAME >= path) and (RP_NAME < path || chr(255)) ) do { declare fourbytes varchar; fourbytes := '----'; fourbytes[0] := bit_shift (RP_ID, -24); fourbytes[1] := bit_and (bit_shift (RP_ID, -16), 255); fourbytes[2] := bit_and (bit_shift (RP_ID, -8), 255); fourbytes[3] := bit_and (RP_ID, 255); for (select RI_NAME, RI_ID from RDF_IRI where (RI_NAME >= fourbytes) and (RI_NAME < fourbytes || chr(255)) ) do { if (exists (select top 1 1 from RDF_QUAD where P=RI_ID)) result (case when (dump_iri_ids) then RI_ID else RP_NAME || subseq (RI_NAME, 4) end); } } for (path_head_len := length (path)-1; path_head_len >= 0; path_head_len := path_head_len - 1) { for (select RP_NAME, RP_ID from RDF_PREFIX where RP_NAME = subseq (path, 0, path_head_len) ) do { declare fourbytes varchar; fourbytes := '----'; fourbytes[0] := bit_shift (RP_ID, -24); fourbytes[1] := bit_and (bit_shift (RP_ID, -16), 255); fourbytes[2] := bit_and (bit_shift (RP_ID, -8), 255); fourbytes[3] := bit_and (RP_ID, 255); for (select RI_NAME, RI_ID from RDF_IRI where (RI_NAME >= fourbytes || subseq (path, path_head_len)) and (RI_NAME < fourbytes || subseq (path, path_head_len) || chr(255)) ) do { if (exists (select top 1 1 from RDF_QUAD where P=RI_ID)) result (case when (dump_iri_ids) then RI_ID else RP_NAME || subseq (RI_NAME, 4) end); } } } } ; -- The basic test: set echo on; PREDICATES_OF_IRI_PATH ('http://www.openlinksw.com/', 1); PREDICATES_OF_IRI_PATH ('http://www.openlinksw.com/schemas/virtrdf', 1); PREDICATES_OF_IRI_PATH ('http://www.openlinksw.com/schemas/virtrdf#', 1); PREDICATES_OF_IRI_PATH ('http://www.openlinksw.com/schemas/virtrdf#i', 1); PREDICATES_OF_IRI_PATH ('no://such :)', 1); PREDICATES_OF_IRI_PATH ('http://www.openlinksw.com/'); PREDICATES_OF_IRI_PATH ('http://www.openlinksw.com/schemas/virtrdf'); PREDICATES_OF_IRI_PATH ('http://www.openlinksw.com/schemas/virtrdf#'); PREDICATES_OF_IRI_PATH ('http://www.openlinksw.com/schemas/virtrdf#i'); PREDICATES_OF_IRI_PATH ('no://such :)');
