Search Mailing List Archives


Limit search to: Subject & Body Subject Author
Sort by: Reverse Sort
Limit to: All This Week Last Week This Month Last Month
Select Date Range     through    

[protege-owl] SPARQL help to write a query

James Howison james at howison.name
Tue Aug 5 08:23:00 PDT 2008


On Aug 5, 2008, at 2:47 AM, anuj kumar wrote:

> Hi,
>
> I have a below OWL ontology structure:-
>
> class1
>   dataproperty1
>   dataproperty2
>   objectproperty1 (range is class2)
>   objectproperty2 (range is class2)
>
> class2
>  dataproperty3
>  dataproperty4
>  objectproperty3 (range is class3)
>  objectproperty4 (range is class3)
>
> class3
>   dataproperty5
>
> I want to execute a query as follows:-
> select all individuals belonging to class1 , select there  
> corresponding
> dataproperty1 ,

SELECT *
WHERE {
  ?class1_url rdf:type yourNS:Class1 ;
              yourNS: dataproperty1 ?data1_value .
}

> that are related with objectproperty1 with class2

SELECT *
WHERE {
  ?class1_url rdf:type yourNS:Class1 ;
              yourNS: dataproperty1 ?data1_value ;
              yourNS: objectproperty1 ?class2_url .
}


> and select
> corresponding class2 individuals and their dataproperty4 ,


SELECT *
WHERE {
  ?class1_url rdf:type yourNS:Class1 ;
              yourNS: dataproperty1 ?data1_value ;
              yourNS: objectproperty1 ?class2_url .
  ?class2_url yourNS:dataproperty4 ?data4_value .
}


> that are related
> with objectproperty4 with class3 and select class 3 corresponding
> individuals.

SELECT *
WHERE {
  ?class1_url rdf:type yourNS:Class1 ;
              yourNS: dataproperty1 ?data1_value ;
              yourNS: objectproperty1 ?class2_url .
  ?class2_url yourNS:dataproperty4 ?data4_value ;
              yourNS:objectproperty4 ?class3_url .
}

You'll get one solution for each set of variables (the parts with ?)  
that satisfy the graph pattern.

Remember that you'll need PREFIX for rdf and yourNS at the start of  
the query.  eg:

PREFIX rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX yourNS:  <http://yourNS.com/ontology#>

> As I am pretty new to sparql , I am unable to understand how to  
> simply get
> all instances of a class using sparql. Any guidance or help will be  
> greatly
> appreciated.

SELECT *
WHERE {
   ?indiv_url rdf:type yourNS:Class1 .
}

The most important thing to do is to view your Individuals data in n3/ 
Turtle format (eg using Jena model.writeAll(System.out, "Turtle",  
null), or save as Turtle), then you write patterns to match the  
triples that you see.  Minimal test data (individuals in Turtle  
format) would help more.

--J



More information about the protege-owl mailing list