Class: RoadForest::TypeHandlers::JSONLD
- Inherits:
-
RDFHandler
- Object
- Handler
- RDFHandler
- RoadForest::TypeHandlers::JSONLD
- Includes:
- Graph::Normalization
- Defined in:
- lib/roadforest/type-handlers/jsonld.rb
Overview
application/ld+json
Constant Summary
Constants included from Graph::Normalization
Instance Method Summary collapse
Methods included from Graph::Normalization
#expand_curie, #expand_curie_pair, #interned_uri, #literal, #normalize_context, #normalize_property, #normalize_resource, #normalize_statement, #normalize_term, #normalize_tuple, #normalize_uri, #relevant_prefixes_for_graph, #root_url, #uri, #vocabularies_in_graph
Methods inherited from RDFHandler
#child_for_interface, #get_output
Methods inherited from Handler
#add_child_to, #build_response, #child_for_interface, #get_output, #parse_for, #render_for, #update_interface
Instance Method Details
#local_to_network(base_uri, rdf) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/roadforest/type-handlers/jsonld.rb', line 9 def local_to_network(base_uri, rdf) raise "Invalid base uri: #{base_uri}" if base_uri.nil? prefixes = relevant_prefixes_for_graph(rdf) prefixes.keys.each do |prefix| prefixes[prefix.to_sym] = prefixes[prefix] end JSON::LD::Writer.buffer(:base_uri => base_uri.to_s, :prefixes => prefixes) do |writer| rdf.each_statement do |statement| writer << statement end end end |
#network_to_local(base_uri, source) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/roadforest/type-handlers/jsonld.rb', line 23 def network_to_local(base_uri, source) raise "Invalid base uri: #{base_uri.inspect}" if base_uri.nil? graph = ::RDF::Graph.new reader = JSON::LD::Reader.new(source.to_s, :base_uri => base_uri.to_s) reader.each_statement do |statement| graph.insert(statement) end graph end |