Home
Categories
Dictionary
Download
Project Details
Changes Log
FAQ
License

WHERE content



Accessing the WHERE form of a SPARQL requust can be performed with the ISparqlRequestGroup.getWhereForm() method.

For example:
   SparqlRequest request = new SparqlRequest("sitac");
   request.addSelect("elt");
   WhereForm form = request.getWhereForm();
   form.addType("elt", "Aircraft");
   String query = request.getSPARQL();

Almost all the methods which create expressions return an OperationResult.

Adding expressions in the WHERE form

Adding expressions in the ASK form can be performed directly in the WhereForm, or through the ISparqlRequestGroup.

By default the library will consider that a WHERE form has been created, except an ASK form is created.


For example, the following are equivalent:
   SparqlRequest request = new SparqlRequest("sitac");
   request.addSelect("elt");
   WhereForm form = request.getWhereForm();
   form.addType("elt", "Aircraft");
   String query = request.getSPARQL();
or
   SparqlRequest request = new SparqlRequest("sitac");
   request.addSelect("elt");
   request.addType("elt", "Aircraft");
   String query = request.getSPARQL();

Additional variables

Prefixed names

Main Article: PrefixedName

Many of the constructs defined in the SPARQLRequest use PrefixedNames as keys.

Adding a rdf contruct

Specifying the type of a variable

The ISparqlRequestGroup.addType(String var, String type) method allows to specify a rdf:type for a variable. For example:
   SparqlRequest request = new SparqlRequest("sitac");
   request.addSelect("zone");
   request.addType("zone", "TaskZone");
Will return the following SPARQL content:
   SELECT ?zone
   WHERE {
      ?zone rdf:type sitac:TaskZone .
   }

Specifying the subclass of a variable

The ISparqlRequestGroup.addSubClassOf(String var, String type) method allows to specify a rdf:subClassOf for a variable. For example:
   SparqlRequest request = new SparqlRequest("sitac");
   request.addSelect("zone");
   request.addSubClassOf("zone", "TaskZone");
Will return the following SPARQL content:
   SELECT ?zone
   WHERE {
      ?zone rdf:subClassOf sitac:TaskZone .
   }
The ISparqlRequestGroup.addSubClassOfStar(String var, String type) method allows to specify a rdf:subClassOf* for a variable[1] . For example:
   SparqlRequest request = new SparqlRequest("sitac");
   request.addSelect("zone");
   request.addSubClassOfStar("zone", "TaskZone");
Will return the following SPARQL content:
   SELECT ?zone
   WHERE {
      ?zone rdf:subClassOf* sitac:TaskZone .
   }

Adding a property

Specifying a triple between two variables and a property

The ISparqlRequestGroup.addPropertyRef(String var, String propertyName, String varRef) method allows to specify a triple pattern between two variables and a property. For example:
   SparqlRequest request = new SparqlRequest("sitac");
   request.addSelect("zone");
   request.addAdditionalVariable("index");
   request.addPropertyRef("zone", "hasIndex", "index");  
Will return the following SPARQL content:
   SELECT ?zone
   WHERE {
      ?zone sitac:hasIndex ?index .
   }

Specifying a triple between a variable, a value, and a property

The ISparqlRequestGroup.addPropertyValue(String var, String propertyName, Object propertyValue) method allows to specify a triple pattern between a variable, a value, and a property. For example:
   SparqlRequest request = new SparqlRequest("sitac");
   request.addSelect("zone");
   request.addPropertyValue("zone", "isTasked", true);  
Will return the following SPARQL content:
   SELECT ?zone
   WHERE {
      ?zone sitac:isTasked "true" .
   }

Specifying a triple between a variable, a list of values, and a property

The ISparqlRequestGroup.addPropertyValues(String var, List valuesList) method allows to specify a triple pattern between a variable, a list of values, and a property. For example:
   SparqlRequest request = new SparqlRequest("sitac");
   request.addSelect("zone");
   request.addType("zone", "TaskZone");
   request.addAdditionalVariable("label");
   request.addPropertyRef("zone", "Label", "label");
   request.addPropertyValues("label", SparqlRequest.createValuesList("label1", "label2"));      
Will return the following SPARQL content:
   SELECT ?zone
   WHERE {
      ?zone rdf:type sitac:TaskZone .
      ?zone sitac:Label ?label .
      VALUES ?label {"label1" "label2" }
   }

Adding an individual

Main Article: Prefix declarations

The ISparqlRequestGroup.addPropertyIndividualRef(String var, String propertyName, String individual) method allow to set an individual as the target of a property.

For example:
   SparqlPrefixDeclarations decl = new SparqlPrefixDeclarations(false);
   decl.addPrefix("sitac", "http://localhost/SITAC");
   SparqlRequest request = new SparqlRequest("sitac", decl);
   request.addSelect("group0");
   request.addPropertyIndividualRef("group0", "isClassifiedAs", "Own");
Will have the following SPARQL result:
   SELECT ?group0
   WHERE {
      ?group0 sitac:isClassifiedAs ?auto_1 .
      VALUES ?auto_1 { <http://localhost/SITAC#Own> }
   }

Groups

Optional constructs

The SPARQLRequest.addOptionalConstruct() method allows to create an OPTIONAL construct within the Sparql request. This construct can contain several expressions. The returned construct have the same API as the root request.

For example, for an OPTIONAL construct for only one property:
   SparqlRequest request = new SparqlRequest("sitac");
   request.addSelect("zone");
   request.addType("zone", "TaskZone");
   request.addPropertyValue("zone", "isTasked", true, true);      
Will return the following SPARQL content:
   SELECT ?zone
   WHERE {
      ?zone rdf:type sitac:TaskZone .
      OPTIONAL { ?zone sitac:isTasked "true" }
   }
For an OPTIONAL construct for several properties:
   SparqlRequest request = new SparqlRequest("sitac");
   request.addSelect("zone");
   request.addType("zone", "TaskZone");
   SparqlRequest.Group optional = request.addOptionalConstruct();
   optional.addPropertyValue("zone", "isTasked", true);
   optional.addPropertyValue("zone", "isFriend", true);      
Will return the following SPARQL content:
   SELECT ?zone
   WHERE {
      ?zone rdf:type sitac:TaskZone .
      OPTIONAL {
        ?zone sitac:isFriend "true" .
        ?zone sitac:isTasked "true" .
      }
   }

Unions

The SPARQLRequest.addUnionConstruct() method creates a list of UNION constructs within the Sparql request.

This construct can contain several groups. For example:
   SparqlRequest request = new SparqlRequest("sitac");
   request.addSelect("zone");
   request.addType("zone", "TaskZone");

   Union union = request.addUnionConstruct();
   SparqlRequestGroup group = union.addGroup();
   group.addPropertyValue("zone", "isTasked", true);
   group = union.addGroup();
   group.addPropertyValue("zone", "isFriend", true);      
Will create the following result:
   SELECT ?zone
   WHERE {
      ?zone rdf:type sitac:TaskZone .
   {
      ?zone sitac:isTasked "true" .
   }
   UNION {
      ?zone sitac:isFriend "true" .
   }
   }

Sub-queries

The SPARQLRequest.addInnerQuery() method adds an inner query (sub-query) to a query.

For example:
   SparqlRequest request = new SparqlRequest("map");
   request.addSelect("label");
   request.addSelect("distance");
   request.addSelect("visibility");

   SparqlRequest innerRequest = request.addInnerQuery();
   innerRequest.addSelect("label");
   innerRequest.addSelect("distance");
   innerRequest.addAdditionalVariable("wpt");
   innerRequest.addAdditionalVariable("ac");      
   ...

Notes

See also


Categories: Requestcreation

Copyright 2025 Dassault Aviation. All Rights Reserved. Documentation and source under the LGPL v3 licence

Project Web Hosted by SourceForge.net Copyright 1999-2010 - Geeknet, Inc., All Rights Reserved About - Legal - Help