Class PrefixDeclarations

All Implemented Interfaces:

public class PrefixDeclarations extends StandardQueryElementCollection<Prefix>
A collection of SPARQL Prefix declarations
See Also:
  • Constructor Details

    • PrefixDeclarations

      public PrefixDeclarations()
  • Method Details

    • addPrefix

      public PrefixDeclarations addPrefix(Prefix... prefixes)
      Add prefix declarations to this collection
      prefixes - the prefixes
    • replacePrefixesInQuery

      public String replacePrefixesInQuery(String queryString)
      Replaces all occurrences of all declared namespaces with their prefix labels in the specified query string.

      For example, if the foaf: prefix is declared with PrefixDeclarations, the query

       SELECT ?name WHERE {
         ?x <> ?name .

      is transformed to

       SELECT ?name WHERE {
         ?x foaf:name ?name .

      Rules applied:

      • The longest matching namespace wins (if one namespace is a substring of another)
      • No replacement if the namespace occurs in a string, i.e., within " or '''
      • Only replace if the continuation of the match is a local name (
      queryString - the query string
      the query string, namespaces replaced with prefix label