Class: RDF::Normalize::Writer

Inherits:
RDF::NQuads::Writer
  • Object
show all
Defined in:
lib/rdf/normalize/writer.rb

Overview

A RDF Graph normalization serialiser.

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output = $stdout, options = {}) {|writer| ... } ⇒ Writer

Initializes the writer instance.

Parameters:

  • output (IO, File) (defaults to: $stdout)

    the output stream

  • options (Hash{Symbol => Object}) (defaults to: {})

    any additional options

Yields:

  • (writer)

    ‘self`

  • (writer)

Yield Parameters:

  • writer (RDF::Writer)
  • writer (RDF::Writer)

Yield Returns:

  • (void)


26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rdf/normalize/writer.rb', line 26

def initialize(output = $stdout, options = {}, &block)
  super do
    @options[:depth] ||= 0
    @repo = RDF::Repository.new
    if block_given?
      case block.arity
        when 0 then instance_eval(&block)
        else block.call(self)
      end
    end
  end
end

Instance Attribute Details

#repoObject

Returns the value of attribute repo.



12
13
14
# File 'lib/rdf/normalize/writer.rb', line 12

def repo
  @repo
end

Instance Method Details

#write_epiloguevoid

This method returns an undefined value.

Outputs the Graph representation of all stored triples.



49
50
51
52
53
54
55
56
57
58
# File 'lib/rdf/normalize/writer.rb', line 49

def write_epilogue
  statements = RDF::Normalize.new(@repo, @options).
    statements.
    reject(&:variable?).
    map {|s| format_statement(s)}.
    sort.
    each do |line|
      puts line
    end
end

#write_statement(statement) ⇒ Object

Defer writing to epilogue



41
42
43
# File 'lib/rdf/normalize/writer.rb', line 41

def write_statement(statement)
  self
end