Class SPARQLQueries
- java.lang.Object
-
- org.eclipse.rdf4j.query.parser.sparql.SPARQLQueries
-
- Direct Known Subclasses:
SPARQLUtil
public class SPARQLQueries extends java.lang.Object
Utility functions for working with SPARQL query strings.
-
-
Constructor Summary
Constructors Constructor Description SPARQLQueries()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.String
escape(java.lang.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.static java.lang.String
getPrefixClauses(java.lang.Iterable<Namespace> namespaces)
Creates a string representing of the suppliednamespaces
as SPARQL prefix declarations.static java.lang.String
unescape(java.lang.String s)
Un-escapes a backslash-escaped SPARQL literal value string.
-
-
-
Method Detail
-
getPrefixClauses
public static java.lang.String getPrefixClauses(java.lang.Iterable<Namespace> namespaces)
Creates a string representing of the suppliednamespaces
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 moreNamespace
objects.- Returns:
- one or more SPARQL prefix declarations (each separated by a newline), as a String.
- Since:
- 3.6.0
-
escape
public static java.lang.String escape(java.lang.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 java.lang.String unescape(java.lang.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:
java.lang.IllegalArgumentException
- If the supplied string is not a correctly escaped SPARQL string.- Since:
- 3.6.0
- See Also:
- SPAQL 1.1 grammar escapes
-
-