Class SparqlScriptProcessor

java.lang.Object
org.aksw.jena_sparql_api.rx.script.SparqlScriptProcessor

public class SparqlScriptProcessor extends Object
Convenient SPARQL statement loader. Probes arguments whether they are inline SPARQL statements or refer to files. Referred files may contain RDF or sequences of SPARQL statements. RDF files are loaded fully into memory as UpdateModify statements. Usually the SparqlQueryParserWrapperSelectShortForm should be active which allows omitting the SELECT keyword making querying even less verbose Prefixes from an input source carry over to the next. Hence, if an RDF file is loaded, its prefixes can be used in subsequent SPARQL statements without need for declaration. For example assuming that mydata defines a foo prefix ad-hoc querying becomes possible simply using the arguments ["people.ttl", "?s { ?s a foaf:Person }"] Arguments that start with cwd=/some/path sets the current working directory on which SPARQL queries operate. Effectively it sets the base URL of the following SPARQL queries. Relative paths are resolved against the current working directory as reported by the JVM. Use "cwd=" (with an empty string) to reset the CWD to that of the JVM Graphs can be pinned for all subsequent arguments using "graph=your://graph.name". Use "graph=" (nothing after the =) to use the default graph.
Author:
Claus Stadler
  • Field Details

    • cwdKey

      public static final String cwdKey
      See Also:
    • cwdResetCwd

      public static final String cwdResetCwd
      See Also:
    • graphKey

      public static final String graphKey
      See Also:
    • graphResetKey

      public static final String graphResetKey
      See Also:
    • sparqlParserFactory

      protected Function<? super org.apache.jena.sparql.core.Prologue,? extends org.aksw.jenax.stmt.core.SparqlStmtParser> sparqlParserFactory
    • globalPrefixes

      protected org.apache.jena.shared.PrefixMapping globalPrefixes
      The set of global prefixes will be extended with the prefixes of every parsed query. Set this attribute to null to disable global prefixes.
    • cwd

      protected Path cwd
    • targetGraph

      protected org.apache.jena.graph.Node targetGraph
      Graph name in which to insert triples
    • sparqlStmts

      protected List<Map.Entry<org.aksw.jenax.stmt.core.SparqlStmt,SparqlScriptProcessor.Provenance>> sparqlStmts
    • postTransformers

      protected List<Function<? super org.aksw.jenax.stmt.core.SparqlStmt,? extends org.aksw.jenax.stmt.core.SparqlStmt>> postTransformers
  • Constructor Details

    • SparqlScriptProcessor

      public SparqlScriptProcessor(Function<? super org.apache.jena.sparql.core.Prologue,? extends org.aksw.jenax.stmt.core.SparqlStmtParser> sparqlParserFactory, org.apache.jena.shared.PrefixMapping globalPrefixes)
  • Method Details

    • addPostTransformer

      public void addPostTransformer(Function<? super org.aksw.jenax.stmt.core.SparqlStmt,? extends org.aksw.jenax.stmt.core.SparqlStmt> transformer)
    • addPostMutator

      public void addPostMutator(Consumer<? super org.aksw.jenax.stmt.core.SparqlStmt> mutator)
    • getSparqlStmts

      public List<Map.Entry<org.aksw.jenax.stmt.core.SparqlStmt,SparqlScriptProcessor.Provenance>> getSparqlStmts()
    • getPlainSparqlStmts

      public List<org.aksw.jenax.stmt.core.SparqlStmt> getPlainSparqlStmts()
    • getSparqlParser

      public org.aksw.jenax.stmt.core.SparqlStmtParser getSparqlParser()
    • createParserPlain

      public static org.aksw.jenax.stmt.core.SparqlStmtParser createParserPlain(org.apache.jena.sparql.core.Prologue prologue, String base)
    • createParserWithEnvSubstitution

      public static org.aksw.jenax.stmt.core.SparqlStmtParser createParserWithEnvSubstitution(org.apache.jena.sparql.core.Prologue prologue)
    • createParserWithEnvSubstitution

      public static org.aksw.jenax.stmt.core.SparqlStmtParser createParserWithEnvSubstitution(org.apache.jena.sparql.core.Prologue prologue, Function<String,String> lookup)
    • createWithEnvSubstitution

      public static SparqlScriptProcessor createWithEnvSubstitution(org.apache.jena.shared.PrefixMapping globalPrefixes)
      Create a script processor that substitutes references to environment variables with the appropriate values.
      Parameters:
      pm -
      Returns:
    • createWithEnvSubstitution

      public static SparqlScriptProcessor createWithEnvSubstitution(org.apache.jena.shared.PrefixMapping globalPrefixes, Function<String,String> lookup)
    • createPlain

      public static SparqlScriptProcessor createPlain(org.apache.jena.shared.PrefixMapping globalPrefixes, String base)
    • process

      public void process(List<String> filenames)
    • processPaths

      public void processPaths(Collection<Path> paths)
    • process

      public void process(int index, Path path)
    • process

      public void process(String filename)
    • process

      public void process(int index, String filename)
    • createParser

      public org.aksw.jenax.stmt.core.SparqlStmtParser createParser(String baseIri)
    • process

      public void process(int index, String filename, List<Map.Entry<org.aksw.jenax.stmt.core.SparqlStmt,SparqlScriptProcessor.Provenance>> result)
    • tryLoadFileAsUpdateRequest

      public static org.apache.jena.update.UpdateRequest tryLoadFileAsUpdateRequest(String filename, org.apache.jena.graph.Node targetGraph, org.apache.jena.shared.PrefixMapping globalPrefixes, Collection<Map.Entry<org.apache.jena.riot.Lang,Throwable>> errorCollector) throws IOException
      Throws:
      IOException