Home
Categories
Dictionary
Download
Project Details
Changes Log
FAQ
License

Adding values



The following methods allow to set a value or values as a target to a triple:

Adding one value

The ISparqlRequestGroup.addPropertyValue(String var, String propertyName, Object propertyValue) method adds a property value specification for a variable property in the WHERE part of the request.

The result is an OperationResult where: For example:
   SparqlRequest request = new SparqlRequest("people");
   request.addSelect("person");
   request.addPropertyValue("person", "hasFirstName", "Paul");  
Will return the following SPARQL content:
   SELECT ?person
   WHERE {
      ?person people:hasFirstName "Paul" .
   }

Adding an individual

Main Article: adding an individual

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> }
   }

Adding a list of values


The ISparqlRequestGroup.addPropertyValues(String var, List valuesList) method allows to specify a triple 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" }
   }

Value types

Main Article: Value types

The API will create the value in the SPARQL request according to the Class of the property value, for boolean or primitive types. For example:
  • For a boolean: the datatype IRI will be xsd:boolean
  • For an int: the datatype IRI will be xsd:int
Note that if no primitive type is found, the type will be the default String litteral.

For example, the following code:
   SparqlRequest request = new SparqlRequest("sitac");
   request.addSelect("elt");
   request.addType("elt", "Waypoint");
   request.addPropertyValue("elt", "inFlightPlan", true);
   String query = request.getSPARQL();
We will generate the following query:
   SELECT ?elt
   WHERE {
     ?elt rdf:type sitac:Waypoint .
     ?elt sitac:inFlightPlan "true"^^xsd:boolean .      
   }      
But this code:
   SparqlRequest request = new SparqlRequest("sitac");
   request.addSelect("elt");
   request.addType("elt", "Waypoint");
   request.addPropertyValue("elt", "inFlightPlan", "true");
   String query = request.getSPARQL();
We will generate the following query:
   SELECT ?elt
   WHERE {
     ?elt rdf:type sitac:Waypoint .
     ?elt sitac:inFlightPlan "true" .      
   }      

Notes

  1. ^ See checking variables existence for more information

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