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-discussion] Jena and Complex SPARQL query

Timothy Redmond tredmond at stanford.edu
Mon Oct 29 00:05:09 PDT 2012


On 10/22/2012 05:56 AM, Gabriela Medina wrote:
> Hello,
>
> I've been recently using Jena and SPARQL and I have one question.

For any jena questions I would suggest the mailing list at 
jena.sourceforge.net.

> I tried to make a query in which ONE variable (in my case named 
> "Process") is linked to TWO other variables (both are variables of the 
> same class. In my case this class is called Symptoms).

Your example looked a bit complicated so I simplified it to see if I 
understand your issue.  I made a small ontology (attached that includes 
the following abox assertions:

Individual: x
     Types:
         A
     Facts:
      p  y,
      p  z
  
Individual: y
     Types:
         B
     Facts:
      q  1
     
Individual: z
     Types:
         B
     Facts:
      q  2
   

I then ran the following sparql query

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX : <http://protege.org/ontologies/TwoVariables#>
SELECT ?a ?b ?c
	WHERE {
      ?a :p ?b.
      ?b :q "1"^^xsd:integer.
      ?a :p ?c.
      ?c :q "2"^^xsd:integer.
}


and got one resulting row consisting of "x, y, z".  This seems to be 
what you are looking for?

-Timothy

> I need to describe some characteristics or some relations that Process 
> have with other classes and at the same time I have to describe 
> characteristics or some relations that each of the Symptoms have.
>
> To perform this query I have tried two alternatives but I have no 
> success. Here I present the two alternatives:
> 1.The first alternative is a SELECT Query written as follow:
>
> String queryString =
> "PREFIX ONTO: http://www.owl-ontologies.com/Ontology1326704817.owl#
> PREFIX owl: <http://www.w3.org/2002/07/owl#>
> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
> SELECT ?Symptome1 ?Symptome2 ?Deviation1 ?Deviation2 ?Flux1 ?Flux2 
> ?Propriete1 ?Propriete2 ?Process
> {{?Process rdf:type ONTO:MoteurDiesel .
> ?Process ONTO:presente ?Symptome1 .
> ?Symptome1 rdf:type ONTO:Symptome .
> ?Symptome1 ONTO:possedeCaracteristiqueDeviation?Deviation1 .
> FILTER regex(str(?Deviation1), 
> 'http://www.owl-ontologies.com/Ontology1326704817.owl#Moins') .
> ?Symptome1 ONTO:possedeCaracteristiqueFlux?Flux1 .
> ?Flux1 rdf:type ONTO:Huile .
> ?Symptome1 ONTO:possedeCaracteristiquePropriete ?Propriete1 .
> ?Propriete1 rdf:type ONTO:PressionFonctionnement} .
> {?Process ONTO:presente ?Symptome2.
> ?Symptome2 rdf:type ONTO:Symptome .
> ?Symptome2 ONTO:possedeCaracteristiqueDeviation?Deviation2 .
> FILTER regex(str(?Deviation), 
> 'http://www.owl-ontologies.com/Ontology1326704817.owl#Plus') .
> ?Symptome2 ONTO:possedeCaracteristiqueFlux?Flux2 .
> ?Flux2 rdf:type ONTO:Huile .
> ?Symptome2 ONTO:possedeCaracteristiquePropriete ?Propriete2 .
> ?Propriete2 rdf:type ONTO:Temperature}}";
> *try*{
> Query query = QueryFactory./create/(queryString);
> QueryExecution qexecRule = QueryExecutionFactory./create/(query, 
> infmodel);
> ResultSet resultset = qexecRule.execSelect();
> Model _result_ = qexecRule.execConstruct();
> *for*(; resultset.hasNext() ; ) {
> QuerySolution soln= resultset.nextSolution();
> RDFNode x = soln.getResource("Process");
> RDFNode y = soln.getResource("Symptome1");
> RDFNode z = soln.getResource("Symptome2");
> System./out/.println(x.toString()+ " "+ y.toString()+ " "+ z.toString());
> }
> The result of this query is an error saying: "Insufficient memory..."
> 2.The second alternative is a CONSTRUCT Query:
> String queryString =
> "PREFIX ONTO: <http://www.owl-ontologies.com/Ontology1326704817.owl#> 
> PREFIX owl: <http://www.w3.org/2002/07/owl#>
> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
> CONSTRUCT {?Process ONTO:presente ?Symptome1; ONTO:presente ?Symptome2}
> WHERE{
> {?Process rdf:type ONTO:MoteurDiesel .
> ?Process ONTO:presente ?Symptome1 .
> ?Symptome1 rdf:type ONTO:Symptome .
> ?Symptome1 ONTO:possedeCaracteristiqueDeviation?Deviation1 .
> FILTER regex(str(?Deviation1), 
> 'http://www.owl-ontologies.com/Ontology1326704817.owl#Moins') .
> ?Symptome1 ONTO:possedeCaracteristiqueFlux?Flux1 .
> ?Flux1 rdf:type ONTO:Huile .
> ?Symptome1 ONTO:possedeCaracteristiquePropriete ?Propriete1 .
> ?Propriete1 rdf:type ONTO:PressionFonctionnement} .
> {?Process ONTO:presente ?Symptome2.
> ?Symptome2 rdf:type ONTO:Symptome .
> ?Symptome2 ONTO:possedeCaracteristiqueDeviation?Deviation2 .
> FILTER regex(str(?Deviation), 
> 'http://www.owl-ontologies.com/Ontology1326704817.owl#Plus') .
> ?Symptome2 ONTO:possedeCaracteristiqueFlux?Flux2 .
> ?Flux2 rdf:type ONTO:Huile .
> ?Symptome2 ONTO:possedeCaracteristiquePropriete ?Propriete2 .
> ?Propriete2 rdf:type ONTO:Temperature}}";
> *try*{
> Query query = QueryFactory./create/(queryString);
> QueryExecution qexecRule = QueryExecutionFactory./create/(query, 
> infmodel);
> Model result = qexecRule.execConstruct();
> {result.write(System./out/, "Result");
> }
> The result of this query is: "Attempt to have ResultSet from a 
> CONSTRUCT query"
> Do you have any suggestion to obtain the correct query for ONE 
> VARIABLE link to TWO OTHERS each one with their relations?
>
> Thanks in advanced for your reply and for your help,
> Kind regards,
> Gabriela
>
>
> _______________________________________________
> protege-discussion mailing list
> protege-discussion at lists.stanford.edu
> https://mailman.stanford.edu/mailman/listinfo/protege-discussion
>
> Instructions for unsubscribing: http://protege.stanford.edu/doc/faq.html#01a.03

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.stanford.edu/pipermail/protege-discussion/attachments/20121029/1c14392f/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: TwoVariables.owl
Type: application/rdf+xml
Size: 3598 bytes
Desc: not available
URL: <http://mailman.stanford.edu/pipermail/protege-discussion/attachments/20121029/1c14392f/attachment-0001.owl>


More information about the protege-discussion mailing list