Class SPARQLQueries

java.lang.Object
org.eclipse.rdf4j.query.parser.sparql.SPARQLQueries
Direct Known Subclasses:
SPARQLUtil

public class SPARQLQueries extends Object
Utility functions for working with SPARQL query strings.
Author:
Jeen Broekstra
  • Constructor Details

    • SPARQLQueries

      public SPARQLQueries()
  • Method Details

    • getPrefixClauses

      public static String getPrefixClauses(Iterable<Namespace> namespaces)
      Creates a string representing of the supplied namespaces as SPARQL prefix declarations. This can be used when composing a SPARQL query string in code, for example:
       
       String query = SPARQLQueries.getPrefixClauses(connection.getNamespaces()) + "SELECT * WHERE { ?s ex:myprop ?o }";
       
       
      Parameters:
      namespaces - one or more Namespace objects.
      Returns:
      one or more SPARQL prefix declarations (each separated by a newline), as a String.
      Since:
      3.6.0
    • escape

      public static String escape(String s)
      Escape the supplied string with backslashes for any special characters, so it can be used as a string literal value in a SPARQL query.
      Since:
      3.6.0
      See Also:
      SPAQL 1.1 grammar escapes
    • unescape

      public static String unescape(String s)
      Un-escapes a backslash-escaped SPARQL literal value string. Any recognized \-escape sequences are substituted with their un-escaped value.
      Parameters:
      s - An SPARQL literal string with backslash escapes.
      Returns:
      The un-escaped string.
      Throws:
      IllegalArgumentException - If the supplied string is not a correctly escaped SPARQL string.
      Since:
      3.6.0
      See Also:
      SPAQL 1.1 grammar escapes