class RDF::Normalize::Writer

A RDF Graph normalization serialiser.

Normalizes the enumerated statements into normal form in the form of N-Quads.

@author [Gregg Kellogg](greggkellogg.net/)

Attributes

repo[RW]

@return [RDF::Repository] Repository of statements to serialized

Public Class Methods

new(output = $stdout, **options, &block) click to toggle source

Initializes the writer instance.

@param [IO, File] output

the output stream

@param [Hash{Symbol => Object}] options

any additional options

@yield [writer] ‘self` @yieldparam [RDF::Writer] writer @yieldreturn [void] @yield [writer] @yieldparam [RDF::Writer] writer

Calls superclass method
# File lib/rdf/normalize/writer.rb, line 26
def initialize(output = $stdout, **options, &block)
  super do
    @repo = RDF::Repository.new
    if block_given?
      case block.arity
        when 0 then instance_eval(&block)
        else block.call(self)
      end
    end
  end
end

Public Instance Methods

write_epilogue() click to toggle source

Outputs the Graph representation of all stored triples.

@return [void]

Calls superclass method
# File lib/rdf/normalize/writer.rb, line 55
def write_epilogue
  RDF::Normalize.new(@repo, **@options).
    statements.
    reject(&:variable?).
    map {|s| format_statement(s)}.
    sort.
    each do |line|
      puts line
    end
  super
end
write_quad(subject, predicate, object, graph_name) click to toggle source

Adds statements to the repository to be serialized in epilogue.

@param [RDF::Resource] subject @param [RDF::URI] predicate @param [RDF::Value] object @param [RDF::Resource] graph_name @return [void]

# File lib/rdf/normalize/writer.rb, line 47
def write_quad(subject, predicate, object, graph_name)
  @repo.insert(RDF::Statement(subject, predicate, object, graph_name: graph_name))
end

Protected Instance Methods

insert_statements(enumerable) click to toggle source

Insert an Enumerable

@param [RDF::Enumerable] enumerable @return [void]

# File lib/rdf/normalize/writer.rb, line 74
def insert_statements(enumerable)
  @repo = enumerable
end