Module: ROF::Translators::JsonldToRof::PredicateHandler

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

Overview

Responsible for dealing with registered predicates and how those are handled.

The two primary entry points are ‘.call` and `.register`

Defined Under Namespace

Classes: UnhandledPredicateError

Class Method Summary collapse

Class Method Details

.call(predicate, object, accumulator, blank_node = false) ⇒ 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 and RDF object and add it’s contents to the accumulator

Examples:

Given the following 4 RDF N-Triples (subject, predicate, object). The first two, with subject "_:b0" represent blank nodes.
The last one with subject "<https://curate.nd.edu/show/zk51vd69n1r>" has an object that points to the "_:b0" blank node.
  _: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> .
For the first two N-Triples you would get a BlankNodeHandler; For the last two, you would get a UriSubjectHandler

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::UnhandledPredicateError)

    when we are unable to handle the given predicate

See Also:



42
43
44
45
46
# File 'lib/rof/translators/jsonld_to_rof/predicate_handler.rb', line 42

def self.call(predicate, object, accumulator, blank_node = false)
  handler = registry.handler_for(predicate)
  handler.handle(object, accumulator, blank_node)
  accumulator
end

.register(url) {|| ... } ⇒ Object

Register a map of an RDF Predicate URL to it’s spot in the ROF Hash.

Parameters:

  • url (String)
    • The URL that we want to match against

Yields:

  • The block to configure how we handle RDF Predicates that match the gvien URL

Yield Parameters:

  • (ROF::JsonldToRof::PredicateHandler::UrlHandler)

See Also:



58
59
60
# File 'lib/rof/translators/jsonld_to_rof/predicate_handler.rb', line 58

def self.register(url, &block)
  registry << UrlHandler.new(url, &block)
end