Class: RoadForest::TypeHandlers::RDFHandler

Inherits:
Handler
  • Object
show all
Includes:
Graph::Normalization
Defined in:
lib/roadforest/type-handlers/rdf-handler.rb

Direct Known Subclasses

JSONLD, RDFPost, RDFa

Constant Summary

Constants included from Graph::Normalization

Graph::Normalization::Vocabs

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 Handler

#add_child_to, #build_response, #local_to_network, #network_to_local, #parse_for, #render_for, #update_interface

Instance Method Details

#child_for_interface(interface, data) ⇒ Object



30
31
32
33
# File 'lib/roadforest/type-handlers/rdf-handler.rb', line 30

def child_for_interface(interface, data)
  interface.add_graph_child(data)
  interface.processed
end

#get_output(interface) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/roadforest/type-handlers/rdf-handler.rb', line 8

def get_output(interface)
  graph = super
  root_uri = interface.canonical_uri

  graph.each_statement do |statement|
    original = statement.dup
    if ::RDF::URI === statement.subject and statement.subject.relative?
      statement.subject = normalize_resource(root_uri.join(statement.subject))
    end

    if ::RDF::URI === statement.object and statement.object.relative?
      statement.object = normalize_resource(root_uri.join(statement.object))
    end

    if statement != original
      graph.delete(original)
      graph.insert(statement)
    end
  end
  graph
end