Class: Qa::LDF::JsonMapper

Inherits:
Object
  • Object
show all
Defined in:
lib/qa/ldf/json_mapper.rb

Overview

A customizable mapper from RDF::Graphs to JSON-like hashes for use in Questioning Authority.

@todo: Add configuration

Examples:

maps a graphs to QA JSON objects.

mapper = JsonMapper.new

uri   = 'http://id.loc.gov/authorities/subjects/sh2004002557'
graph = RDF::Graph.load(uri)

mapper.map_resource(uri, graph)
# => { id:    'http://id.loc.gov/authorities/subjects/sh2004002557',
#      label: 'Marble Island (Nunavut)' }

Instance Method Summary collapse

Instance Method Details

#map_resource(uri, graph) ⇒ Hash<Symbol, String>

Parameters:

  • uri (String)

    a URI-like string

  • graph (RDF::Queryable)

Returns:

  • (Hash<Symbol, String>)


26
27
28
29
30
31
32
# File 'lib/qa/ldf/json_mapper.rb', line 26

def map_resource(uri, graph)
  labels =
    graph.query(subject:   RDF::URI.intern(uri),
                predicate: RDF::Vocab::SKOS.prefLabel).objects

  { id: uri, label: labels.first.to_s }
end