Class SPARQLPrefixResolver

java.lang.Object
org.aksw.qa.commons.sparql.SPARQLPrefixResolver

public class SPARQLPrefixResolver extends Object
  • Field Details

    • LOGGER

      private static org.slf4j.Logger LOGGER
    • globalPrefixes

      private static Properties globalPrefixes
      Refers to resource "prefixes.properties". Left had side is a prefix, right hand side is a corresponding URI.

      Prefixes will be loaded during loading of enclosing class, via static constructor.

    • globalPrefixMapping

      private static org.apache.jena.shared.PrefixMapping globalPrefixMapping
      This mapping will be used to refer to, if the local mapping (e.g.PREFIX declarations in the query itself) cannot resolve a prefix. Will be initialized with all prefixes in globalPrefixes
  • Constructor Details

    • SPARQLPrefixResolver

      public SPARQLPrefixResolver()
  • Method Details

    • getGlobalPrefixMapping

      public static org.apache.jena.shared.PrefixMapping getGlobalPrefixMapping()
      If you want to add/remove a prefix, this is your best bet.
      Returns:
      The global prefix mapping, possibly containing all from resource "prefixes.properties"
    • addMissingPrefixes

      public static String addMissingPrefixes(String sparqlQuery)
      Adds the declaration of a prefix, if its used in the sparql query, but not declared. As global prefix source globalPrefixMapping is used, which is initialized with data from resource "prefixes.properties"

      In query defined prefixes override.

      If uris are given in the query body which can be represented with a prefix, the uris are replaced with a prefix and a prefix declaration will be added. E.g. "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" is present, it will be replaced with "rdf:type", and prefix declaration for "rdf" will be added.

      This will not remove unused prefix declarations.

      if you wonder why keyword "a" is replaced, this is correct behavior. This is, because mapping for rdf: is set in a PrefixMap(its default in global).

      Parameters:
      sparqlQuery - a sparql query
      Returns:
      the same sparql query, but with missing PREFIX declarations added.