Class PrefixDeclarations

All Implemented Interfaces:
QueryElement

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
      Parameters:
      prefixes - the prefixes
      Returns:
      this
    • 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 <http://xmlns.com/foaf/0.1/name> ?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 (
      Parameters:
      queryString - the query string
      Returns:
      the query string, namespaces replaced with prefix label
    • isOpeningAngledBracket

      private boolean isOpeningAngledBracket(String queryString, int pos)
    • isMultilineQuote

      private boolean isMultilineQuote(String queryString, int pos)
    • isEscapeChar

      private boolean isEscapeChar(String queryString, int pos)
    • isDoubleQuote

      private boolean isDoubleQuote(String queryString, int pos)
    • findNextRelevantIndex

      private int findNextRelevantIndex(String queryString, int lastPos, boolean isInsideString)
    • findMatchingPrefix

      private Prefix findMatchingPrefix(String queryString, int pos)
      Returns the longest prefix that is found starting at position pos in the queryString
      Parameters:
      queryString - the query string
      pos - the position at which to start looking
      Returns:
      the longest prefixIri that matches fully (no tie-break for duplicates)
    • isContinuationALocalName

      private boolean isContinuationALocalName(String continuation)
    • findNextWhitespace

      private int findNextWhitespace(String continuation)
    • getIRIStringFromPrefix

      private String getIRIStringFromPrefix(Prefix p)