Re: Suggestion on Limiting query results to specific vocabulary/ontology/namespace

Hi Amit:

A properly designed vocabulary will link the conceptual elements to the IRI defining the ontology (or the ontology document; there is a bit of a debate about that) using rdfs:isDefinedBy.

So e.g. for 
* http://purl.org/goodrelations/v1
* http://purl.org/vso/ns
* http://www.productontology.org/#

you could query for all classes from the three ontologies using

SELECT DISTINCT(?c) WHERE 
{ ?c a owl:Class.
{
 { ?c rdfs:isDefinedBy <http://purl.org/goodrelations/v1>}
 UNION
 { ?c rdfs:isDefinedBy <http://purl.org/vso/ns>}
 UNION
 { ?c rdfs:isDefinedBy <http://www.productontology.org/#>}
}
}
LIMIT 1000

This is orders of magnitude faster than regex. All good vocabularies can be expected to support this pattern; if not, ask the authors ;-)

Martin


On Nov 1, 2011, at 10:13 PM, Amit Krishna Joshi wrote:

> (Apologies for cross-posting)
> Hi, 
> 
> I am looking for a generic solution to limit the query results to specific
> vocabulary or a set of vocabularies.
> 
> A simple query like below is proving to be quite expensive while sending it
> to sparql endpoints.
> select * where { 
> ?s ?p ?o.
> filter  regex(str(?s),"http://purl.org/vocab/ ","i")
> }
> limit 1
> 
> Virtuoso S1T00 Error SR171: Transaction timed out
> (http://dbpedia.org/sparql)
> 
> This is required for us since we are dealing with distributing querying of
> LOD cloud and  we often need to limit the results to specific
> ontology/vocabulary. 
> One of the obvious solution would be to query without the filter operator
> and perform filter locally if there's any matching triples.  This does not
> help because the number of returned results might not include the triples
> containing the required vocabulary though the dataset might contain it. 
> 
> It would be great if I could receive insights and thoughts on dealing with
> it.
> 
> 1. Does it require extending sparql to include special function/operator ?
> (The above query would return results if resource is not limited)
> 
> 2. Is it a problem with the RDF stores that they don't' maintain the
> 'prefix-based index' ?
> 
> Thanks,
> Amit
> 
> 
> 
> 
> 
> 
> 
> 
> 

Received on Wednesday, 2 November 2011 08:49:26 UTC