Home
Categories
Dictionary
Download
Project Details
Changes Log
FAQ
License

Configuration



The SparqlHelperConfig class contains the configuration of the library.

Library release version

The SparqlHelperConfig.getVersion() method return the version of the library.

The SparqlHelperConfig.getDate() method return the date of the release of the library.

The SparqlHelperConfig.printRelease() method print the release of the library.

For example:
   SparqlHelperConfig.printRelease();
will print on System.out:
      SparlHelper version: 0.3 release: 11/03/2026

Configuration properties

The following properties can be configured through the SparqlHelperConfig:
  • The default prefix declarations for all subsequent SPARQLRequest creations
  • The property specifying if standard functions names are normalized in function expressions
  • The property which specifies the indentation of the SPARQL serialization
  • The property specifying how the SPARQLParser should behave for malformed requests
The SparqlHelperConfig.reset() resets to the default properties.

Default prefix declarations

Main Article: Prefix declarations

The SparqlHelperConfig.setDefaultPrefixDeclarations(SparqlPrefixDeclarations decl) method allows to set the default prefix declarations for all subsequent SPARQLRequest creations.

Of course, if you explictly specify the prefix declarations when you create your SPARQLRequest (such as for example with SPARQLRequest(String prefix, SparqlPrefixDeclarations decl)), the default prefix declarations will not be used.

Usage

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

Normalizing standard functions names

By default if you create function expressions by using their names, they will be defined by their names even if they are Built-in functions. For example:
   VariableExpression varExpr = new VariableExpression("var");
   FunctionExpression expression = new FunctionExpression("floor", varExpr);      
   short functionType = expression.getFunction(); // function type will be FunctionTypes.FUNCTION_CUSTOM
If you set the SparqlHelperConfig.normalizeStandardFunctions(boolean normalize) method, then the built-in function will be defined by their id even if they are created by their names. For example:
   SparqlHelperConfig.normalizeStandardFunctions(true);
   VariableExpression varExpr = new VariableExpression("var");
   FunctionExpression expression = new FunctionExpression("floor", varExpr);      
   short functionType = expression.getFunction(); // function type will be FunctionTypes.FLOOR

This will have to consequence on the way the function is serialized in the SPARQL expression.

Indentation

The SparqlHelperConfig.setIndentationValue(int indentation) allows to define the number of space characters used for the serialized SPARQL indentation. The default is none, which means that the serialized SPARQL will not be serialized.

For example, if you perform:
   SparqlRequest request = new SparqlRequest("sitac");
   request.addSelect("elt");
   request.addType("elt", "Aircraft");
   String query = request.getSPARQL();
You will have the following result:
   SELECT ?elt
   WHERE {
   ?elt rdf:type sitac:Aircraft .
   }      
But if you perform:
   SparqlHelperConfig.getInstance().setIndentationValue(2);
   SparqlRequest request = new SparqlRequest("sitac");
   request.addSelect("elt");
   request.addType("elt", "Aircraft");
   String query = request.getSPARQL();
You will have the following result:
   SELECT ?elt
   WHERE {
     ?elt rdf:type sitac:Aircraft .
   }      

Behavior of the parser with malformed requests

Main Article: Malformed requests

The SparqlHelperConfig.setErrorsHandlingType(char errorsHandlingType) specifies how the SPARQLParser should behave for malformed requests:
The default value is ErrorsHandlingType.EXCEPTION.

See also


Categories: General

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