Class: RDF::Normalize::Writer
- Inherits:
-
RDF::NQuads::Writer
- Object
- RDF::NQuads::Writer
- RDF::Normalize::Writer
- 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
-
#repo ⇒ RDF::Repository
Repository of statements to serialized.
Instance Method Summary collapse
-
#initialize(output = $stdout, **options) {|writer| ... } ⇒ Writer
constructor
Initializes the writer instance.
-
#insert_statements(enumerable)
protected
Insert an Enumerable.
-
#write_epilogue
Outputs the Graph representation of all stored triples.
-
#write_quad(subject, predicate, object, graph_name)
Adds statements to the repository to be serialized in epilogue.
Constructor Details
#initialize(output = $stdout, **options) {|writer| ... } ⇒ Writer
Initializes the writer instance.
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/rdf/normalize/writer.rb', line 26 def initialize(output = $stdout, **, &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
#repo ⇒ RDF::Repository
Returns Repository of statements to serialized.
12 13 14 |
# File '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
74 75 76 |
# File '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 '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)
This method returns an undefined value.
Adds statements to the repository to be serialized in epilogue.
47 48 49 |
# 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 |