Home
Categories
Dictionary
Download
Project Details
Changes Log
FAQ
License

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

VALUES types

VALUES can be of one of the following types: For example, using Individuals as here is valid:
   SparqlRequest request = new SparqlRequest("sitac");
   request.addSelect("zone");
   Individual individual = new Individual(request, "TheZone");
   Individual individual2 = new Individual(request, "TheZone2");
      
   List<? extends Object> list = SparqlRequest.createValuesList(individual, individual2); 
   request.addType("zone", "TaskZone");
   request.addPropertyValues("zone", list);           
It will return the following SPARQL result:
   SELECT ?zone
   WHERE {
      ?zone rdf:type sitac:TaskZone .
      VALUES ?zone { <http://localhost#TheZone> <http://localhost#TheZone2> }
   }
Or here using IRIs:
   SparqlRequest request = new SparqlRequest("sitac");
   request.addSelect("zone");
   IRI iri1 = new IRI("http://localhost#TheZone");
   IRI iri2 = new IRI("http://localhost#TheZone2");
      
   List<? extends Object> list = SparqlRequest.createValuesList(iri1, iri2); 
   request.addType("zone", "TaskZone");
   request.addPropertyValues("zone", list);           
It will return the same SPARQL result:
   SELECT ?zone
   WHERE {
      ?zone rdf:type sitac:TaskZone .
      VALUES ?zone { <http://localhost#TheZone> <http://localhost#TheZone2> }
   }

Creating a values list

The SparqlRequest.createValuesList(Object... values) static method is a utility method which creates a list of values which can be used in the ISparqlRequestGroup.addPropertyValues(String var, List valuesList) method.

Each element of the vararg can be:
  • A Boolean
  • A Number
  • A String
  • An Individual
  • An IRI
  • A Set or a List of Strings (or a Boolean, or a Number)
  • A Set or a List of Individuals
  • A Set or a List of IRIs
For example this is valid:
   SparqlRequest request = new SparqlRequest("sitac");
   request.addSelect("zone");
   request.addType("zone", "TaskZone");    
      
   request.addPropertyValues("zone", "Label", SparqlRequest.createValuesList("label1", "label2"));
It will return the following SPARQL result:
   SELECT ?zone
   WHERE {
      ?zone rdf:type sitac:TaskZone .
      ?zone sitac:Label ?zone .
      VALUES ?zone { "label1" "label2" }
   }
This is also valid:
   SparqlRequest request = new SparqlRequest("sitac");
   request.addSelect("zone");
   request.addType("zone", "TaskZone");
      
   Set<String> set = new TreeSet<>();
   set.add("label1");
   set.add("label2");      
      
   request.addPropertyValues("zone", "Label", SparqlRequest.createValuesList(set));
It will return the same SPARQL result:
   SELECT ?zone
   WHERE {
      ?zone rdf:type sitac:TaskZone .
      ?zone sitac:Label ?zone .
      VALUES ?zone { "label1" "label2" }
   }

Value types

Main Article: Value types

Creating a values list from IRIs

The SparqlRequest.createIRIValuesList(Object... values) static method is a utility method which creates a list of IRI values constructed with Strings which can be used in the ISparqlRequestGroup.addPropertyValues(String var, List valuesList) method.

Each element of the vararg can be:
  • A String which will represent an IRI
  • A Set or a List of Strings which will represent an IRI
For example this is valid:
   SparqlRequest request = new SparqlRequest("sitac");
   request.addSelect("zone");
   request.addType("zone", "TaskZone"); 
   request.addPropertyValues("zone", "Label", SparqlRequest.createIRIValuesList("http://localhost#TheZone", "http://localhost#TheZone2"));
It will return the following SPARQL result:
   SELECT ?zone
   WHERE {
      ?zone rdf:type sitac:TaskZone .
      VALUES ?zone { <http://localhost#TheZone> <http://localhost#TheZone2> }
   }

Using the SparqlRequestHelper class

The SparqlRequestHelper class has the same methods than the SparqlRequest.

For example:
   SparqlRequest request = new SparqlRequest("sitac");
   request.addSelect("zone");
   request.addType("zone", "TaskZone");    
      
   request.addPropertyValues("zone", "Label", SparqlRequestHelper.createValuesList("label1", "label2"));

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