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

Gabriela Medina gabrielamedinaoliva at yahoo.com
Mon Oct 22 05:56:22 PDT 2012


Hello,

I've been recently using Jena and SPARQL and I have one question. 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). 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.stanford.edu/pipermail/protege-discussion/attachments/20121022/defd58aa/attachment-0001.html>


More information about the protege-discussion mailing list