Class: SPARQL::Algebra::Operator::Load

Inherits:
Operator
  • Object
show all
Includes:
Update
Defined in:
lib/sparql/algebra/operator/load.rb

Overview

The SPARQL UPDATE load operator.

The LOAD operation reads an RDF document from a IRI and inserts its triples into the specified graph in the Graph Store. The specified destination graph should be created if required; again, implementations providing an update service over a fixed set of graphs must return with failure for a request that would create a disallowed graph. If the destination graph already exists, then no data in that graph will be removed.

[31] Load ::= 'LOAD' 'SILENT'? iri ( 'INTO' GraphRef )?

Examples:

SPARQL Grammar

LOAD <http://example.org/remote> INTO GRAPH <http://example.org/g> ;

SSE

(update (load <http://example.org/remote> <http://example.org/g>))

See Also:

Constant Summary collapse

NAME =
[:load]

Instance Method Summary collapse

Methods included from Update

#empty?, #graph_name=, #unshift, #variables

Instance Method Details

#execute(queryable, **options) ⇒ RDF::Queryable

Executes this upate on the given writable graph or repository.

Parameters:

  • queryable (RDF::Queryable)

    the graph or repository to write

  • options (Hash{Symbol => Object})

    any additional keyword options

Options Hash (**options):

  • debug (Boolean)

    Query execution debugging

Returns:

Raises:

  • (IOError)

    If from does not exist, unless the silent operator is present

See Also:



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/sparql/algebra/operator/load.rb', line 38

def execute(queryable, **options)
  debug(options) {"Load"}
  silent = operands.first == :silent
  operands.shift if silent

  raise ArgumentError, "load expected one or two operands, got #{operands.length}" unless [1,2].include?(operands.length)

  location, name = operands
  queryable.load(location, graph_name: name)
rescue IOError, Errno::ENOENT
  raise unless silent
ensure
  queryable
end

#to_sparql(**options) ⇒ String

Returns a partial SPARQL grammar for this operator.

Returns:

  • (String)


58
59
60
61
62
63
64
65
66
67
68
# File 'lib/sparql/algebra/operator/load.rb', line 58

def to_sparql(**options)
  silent = operands.first == :silent
  ops = silent ? operands[1..-1] : operands
  location, name = ops

  str = "LOAD "
  str << "SILENT " if silent
  str << location.to_sparql(**options)
  str << " INTO GRAPH " + name.to_sparql(**options) if name
  str
end