Home
Categories
Dictionary
Download
Project Details
Changes Log
FAQ
License

Prefix declarations



The SparqlPrefixDeclarations class specifies the prefixes to include in the SPARQL requests.

Including the prefix declarations in the SPARQL result

By default SPARQL requests created by the framework do not include the prefix declarations.

For example suppose the following code:
   SparqlRequest request = new SparqlRequest("sitac");
   request.addSelect("zone");
   request.addType("zone", "TaskZone");
   request.addPropertyValue("zone", "isTasked", true);
   String sparql = request.getSPARQL();
The result will be:
   SELECT ?zone
   WHERE {
     ?zone rdf:type sitac:TaskZone .
     ?zone sitac:isTasked "true" .
   }

Including the default prefixes to the prefixes declarations

To include the prefix declarations in the resulting SPARQL request, you must add a SparqlPrefixDeclarations as an argument to the request constructor.

By default the prefixes will include:
  • The owl prefix for http://www.w3.org/2002/07/owl#
  • The rdf prefix for http://www.w3.org/1999/02/22-rdf-syntax-ns#
  • The rdfs prefix for http://www.w3.org/2000/01/rdf-schema#
  • The xsd prefix for http://www.w3.org/2001/XMLSchema#
  • The time prefix for http://www.w3.org/2006/time# if the SparqlPrefixDeclarations.hasOwlTimePrefix() method returns true
  • The following prefixes if the SparqlPrefixDeclarations.hasGeoSparqlPrefix() method returns true:
    • The geo prefix for http://www.opengis.net/ont/geosparql#
    • The unit prefix for http://qudt.org/vocab/unit#
    • The uom prefix for http://www.opengis.net/def/uom/OGC/1.0/#
    • The geof prefix for http://www.opengis.net/def/function/geosparql/
  • The math prefix for http://www.w3.org/2005/xpath-functions/math# if the SparqlPrefixDeclarations.hasXPathPrefix() method returns true
For example with the following code:
   SparqlPrefixDeclarations prefixDecl = new SparqlPrefixDeclarations();     
      
   SparqlRequest request = new SparqlRequest("sitac", prefixDecl);
   request.addSelect("zone");
   request.addType("zone", "TaskZone");
   request.addPropertyValue("zone", "isTasked", true);
   String sparql = request.getSPARQL();
The result will be:
   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#>
   PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
   SELECT ?zone
   WHERE {
     ?zone rdf:type sitac:TaskZone .
     ?zone sitac:isTasked "true" .
   }

Including the owl-time prefix

The SparqlPrefixDeclarations.addOwlTimePrefix(boolean) allows to ensure that the owl-time prefix will be included in the prefixes declarations.

See https://www.w3.org/TR/owl-time/ for more information.


For example with the following code:
   SparqlPrefixDeclarations prefixDecl = new SparqlPrefixDeclarations();   
   prefixDecl.addOwlTimePrefix(true); 
      
   SparqlRequest request = new SparqlRequest("sitac", prefixDecl);
   request.addSelect("zone");
   request.addType("zone", "TaskZone");
   request.addPropertyValue("zone", "isTasked", true);
   String sparql = request.getSPARQL();
The result will be:
   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#>
   PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
   PREFIX time: <http://www.w3.org/2006/time#>
   SELECT ?zone
   WHERE {
     ?zone rdf:type sitac:TaskZone .
     ?zone sitac:isTasked "true" .
   }

Including the geosparql prefix

The SparqlPrefixDeclarations.addGeoSparqlPrefix(boolean) allows to ensure that the GeoSparql prefixes will be included in the prefixes declarations.
See https://www.ogc.org/standards/geosparql/ for more information.


For example with the following code:
   SparqlPrefixDeclarations prefixDecl = new SparqlPrefixDeclarations();   
   prefixDecl.addGeoSparqlPrefix(true); 
      
   SparqlRequest request = new SparqlRequest("sitac", prefixDecl);
   request.addSelect("zone");
   request.addType("zone", "TaskZone");
   request.addPropertyValue("zone", "isTasked", true);
   String sparql = request.getSPARQL();
The result will be:
   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#>
   PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
   PREFIX geo: <http://www.opengis.net/ont/geosparql#>
   PREFIX unit: <http://qudt.org/vocab/unit#>
   PREFIX uom: <http://www.opengis.net/def/uom/OGC/1.0/#>
   PREFIX geof: <http://www.opengis.net/def/function/geosparql/>
   SELECT ?zone
   WHERE {
     ?zone rdf:type sitac:TaskZone .
     ?zone sitac:isTasked "true" .
   }

Including the XPath math prefix


The SparqlPrefixDeclarations.addXPathPrefix(boolean) allows to ensure that the XPath math prefix will be included in the prefixes declarations.



For example with the following code:
   SparqlPrefixDeclarations prefixDecl = new SparqlPrefixDeclarations();   
   prefixDecl.addXPathPrefix(true); 
      
   SparqlRequest request = new SparqlRequest("sitac", prefixDecl);
   request.addSelect("zone");
   request.addType("zone", "TaskZone");
   request.addPropertyValue("zone", "isTasked", true);
   String sparql = request.getSPARQL();
The result will be:
   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#>
   PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
   PREFIX math: <http://www.w3.org/2005/xpath-functions/math#>
   SELECT ?zone
   WHERE {
     ?zone rdf:type sitac:TaskZone .
     ?zone sitac:isTasked "true" .
   }

Adding custom prefixes to the prefixes declarations

To bind prefixes to IRIs to the prefixes declarations, you can use the following methods: For example with the following code:
   SparqlPrefixDeclarations prefixDecl = new SparqlPrefixDeclarations();
   prefixDecl.addPrefix("sitac", "http://example.com/");      
      
   SparqlRequest request = new SparqlRequest("sitac", prefixDecl);
   request.addSelect("zone");
   request.addType("zone", "TaskZone");
   request.addPropertyValue("zone", "isTasked", true);
   String sparql = request.getSPARQL();
The result will be:
   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#>
   PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
   PREFIX sitac: <http://example.com/>
   SELECT ?zone
   WHERE {
     ?zone rdf:type sitac:TaskZone .
     ?zone sitac:isTasked "true" .
   }

Default prefix declarations

Main Article: Library configuration

It is possible to define a default prefix declarations by calling the SparqlHelperConfig.setDefaultPrefixDeclarations(SparqlPrefixDeclarations decl) method.

For example with the following code:
   SparqlPrefixDeclarations prefixDecl = new SparqlPrefixDeclarations();      
   prefixDecl.addPrefix("sitac", "http://example.com/");    
   prefixDecl.addGeoSparqlPrefix();
   prefixDecl.addOwlTimePrefix();      
   SparqlHelperConfig.getInstance().setDefaultPrefixDeclarations(prefixDecl);  
      
   SparqlRequest request = new SparqlRequest("sitac");
   request.addSelect("zone");
   request.addType("zone", "TaskZone");
   request.addPropertyValue("zone", "isTasked", true);
   String sparql = request.getSPARQL();
The result will be:
   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#>
   PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
   PREFIX geo: <http://www.opengis.net/ont/geosparql#>
   PREFIX geof: <http://www.opengis.net/def/function/geosparql/>
   PREFIX sitac: <http://example.com/>
   PREFIX time: <http://www.w3.org/2006/time#>
   PREFIX unit: <http://qudt.org/vocab/unit#>
   PREFIX uom: <http://www.opengis.net/def/uom/OGC/1.0/#>
   SELECT ?zone
   WHERE {
     ?zone rdf:type sitac:TaskZone .
     ?zone sitac:isTasked "true" .
   }      

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