Module: ROF::Translators::JsonldToRof::PredicateObjectHandler

Defined in:
lib/rof/translators/jsonld_to_rof/predicate_object_handler.rb

Overview

We need to handle the Predicate / Object pair as one (thank you RDF blank nodes for this nuance)

Defined Under Namespace

Classes: UnknownRdfObjectTypeError

Class Method Summary collapse

Class Method Details

.call(predicate, object, accumulator, options = {}) ⇒ ROF::Translators::JsonldToRof::Accumulator

Note:

It is assumed that all blank nodes (e.g. RDF::Node) will be processed before you process any RDF::URI nodes.

Parse the RDF::Predicate, RDF::Object and the relevant data to the contents to the accumulator

Examples:

Given the following 4 RDF N-Triples (subject, predicate, object). The first and second RDF objects are RDF::Literal. The 3rd triple's object is
and RDF::Node. And the last is an RDF::URI. Each require different handlers as they have nuanced differences.
  _:b0 <http://purl.org/dc/terms/contributor> "David R.Hyde" .
  _:b0 <http://www.ndltd.org/standards/metadata/etdms/1.1/role> "Research Director" .
  <https://curate.nd.edu/show/zk51vd69n1r> <http://purl.org/dc/terms/contributor> _:b0 .
  <https://curate.nd.edu/show/zk51vd69n1r> <http://projecthydra.org/ns/relations#hasEditorGroup> <https://curate.nd.edu/show/q524jm23g92> .

Parameters:

  • predicate (RDF::Predicate)
    • the RDF predicate that we will parse and add to the appropriate spot in the accumulator

  • object (RDF::Object)
    • the RDF object that we will parse and add to the appropriate spot in the accumulator

  • accumulator (ROF::Translators::JsonldToRof::Accumulator)
    • a data accumulator that will be changed in place

Returns:

Raises:

  • (ROF::Translators::JsonldToRof::UnknownRdfObjectTypeError)

    when the RDF::Object’s subject is not a valid type



28
29
30
31
# File 'lib/rof/translators/jsonld_to_rof/predicate_object_handler.rb', line 28

def self.call(predicate, object, accumulator, options = {})
  new(predicate, object, accumulator, options).call
  accumulator
end

.klass_for(object) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/rof/translators/jsonld_to_rof/predicate_object_handler.rb', line 47

def self.klass_for(object)
  case object
  when RDF::URI
    UriPredicateObjectHandler
  when RDF::Node
    NodePredicateObjectHandler
  when RDF::Literal
    LiteralPredicateObjectHandler
  else
    raise UnknownRdfObjectTypeError, "Unable to determine object handler for #{object.inspect}"
  end
end

.new(predicate, object, accumulator, options) ⇒ #call

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • predicate (RDF::Predicate)
    • the RDF predicate that we will parse and add to the appropriate spot in the accumulator

  • object (RDF::Object)
    • the RDF object that we will parse and add to the appropriate spot in the accumulator

  • accumulator (ROF::Translators::JsonldToRof::Accumulator)
    • a data accumulator that will be changed in place

Returns:



39
40
41
# File 'lib/rof/translators/jsonld_to_rof/predicate_object_handler.rb', line 39

def self.new(predicate, object, accumulator, options)
  klass_for(object).new(predicate, object, accumulator, options)
end