Class: RDF::Normalize::Writer

Inherits:
RDF::NQuads::Writer show all
Defined in:
vendor/bundler/ruby/2.5.0/bundler/gems/rdf-normalize-3ebba07282f6/lib/rdf/normalize/writer.rb

Overview

A RDF Graph normalization serialiser.

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

Author:

Constant Summary

Constants inherited from RDF::NTriples::Writer

RDF::NTriples::Writer::ESCAPE_PLAIN, RDF::NTriples::Writer::ESCAPE_PLAIN_U

Instance Attribute Summary collapse

Attributes inherited from Writer

#options

Instance Method Summary collapse

Methods inherited from RDF::NQuads::Writer

#format_quad, #format_statement

Methods inherited from RDF::NTriples::Writer

escape, escape_ascii, escape_unicode, escape_utf16, escape_utf32, #format_literal, #format_node, #format_statement, #format_triple, #format_uri, serialize, #write_comment, #write_triple

Methods included from Util::Logger

#log_debug, #log_depth, #log_error, #log_fatal, #log_info, #log_recover, #log_recovering?, #log_statistics, #log_warn, #logger

Methods inherited from Writer

#base_uri, buffer, #canonicalize?, dump, each, #encoding, #escaped, #flush, for, format, #format_list, #format_literal, #format_node, #format_term, #format_uri, #node_id, open, options, #prefix, #prefixes, #prefixes=, #puts, #quoted, #to_sym, to_sym, #uri_for, #validate?, #write_comment, #write_prologue, #write_statement, #write_triple, #write_triples

Methods included from Util::Aliasing::LateBound

#alias_method

Methods included from Writable

#<<, #insert, #insert_graph, #insert_reader, #insert_statement, #writable?

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:

Yield Returns:

  • (void)


26
27
28
29
30
31
32
33
34
35
36
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-normalize-3ebba07282f6/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

Instance Attribute Details

#repoObject

Returns the value of attribute repo



12
13
14
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-normalize-3ebba07282f6/lib/rdf/normalize/writer.rb', line 12

def repo
  @repo
end

Instance Method Details

#insert_statements(enumerable) (protected)

This method returns an undefined value.

Insert an Enumerable

Parameters:



74
75
76
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-normalize-3ebba07282f6/lib/rdf/normalize/writer.rb', line 74

def insert_statements(enumerable)
  @repo = enumerable
end

#write_epilogue

This method returns an undefined value.

Outputs the Graph representation of all stored triples.



55
56
57
58
59
60
61
62
63
64
65
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-normalize-3ebba07282f6/lib/rdf/normalize/writer.rb', line 55

def write_epilogue
  statements = 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)

This method returns an undefined value.

Adds statements to the repository to be serialized in epilogue.

Parameters:



47
48
49
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-normalize-3ebba07282f6/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