Class: SDL::Exporters::RDFExporter

Inherits:
ServiceExporter show all
Defined in:
lib/sdl/exporters/rdf_exporter.rb

Constant Summary collapse

@@s =
RDF::Vocabulary.new('http://www.open-service-compendium.org/')

Instance Attribute Summary

Attributes inherited from Exporter

#compendium, #options

Instance Method Summary collapse

Methods inherited from ServiceExporter

#export_service_to_file

Methods inherited from Exporter

#export_to_file, #initialize

Constructor Details

This class inherits a constructor from SDL::Exporters::Exporter

Instance Method Details

#expand_properties(type_instance, graph) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/sdl/exporters/rdf_exporter.rb', line 19

def expand_properties(type_instance, graph)
  type_instance.property_values.each do |property, value|
    [value].flatten.each do |v|
      graph << [RDF::URI.new(type_instance.uri), @@s["#{property.name.underscore}"], v.rdf_object] unless v.nil?
    end

    if property.type < SDL::Base::Type
      [value].flatten.each do |v| expand_properties(v, graph) end
    end
  end
end

#export_service(service) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/sdl/exporters/rdf_exporter.rb', line 7

def export_service(service)
  graph = RDF::Graph.new

  service.facts.each do |fact|
    graph << [RDF::URI.new(service.uri), @@s["has_#{fact.class.local_name.underscore}"], RDF::URI.new(fact.uri)]

    expand_properties(fact, graph)
  end

  graph.dump(:rdf)
end