Class: Rialto::Etl::Writers::NtriplesWriter

Inherits:
Traject::LineWriter
  • Object
show all
Defined in:
lib/rialto/etl/writers/ntriples_writer.rb

Overview

Write NTriples records

Instance Method Summary collapse

Instance Method Details

#serialize(context) ⇒ String

Overrides the serialization routine from superclass

Parameters:

  • context (Traject::Indexer::Context)

    a Traject context object containing the output of the mapping

Returns:

  • (String)

    NTriples representation of the mapping



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rialto/etl/writers/ntriples_writer.rb', line 17

def serialize(context)
  hash = context.output_hash
  subject = RDF::URI.new(hash.delete('@id'))
  type = RDF::URI.new(hash.delete('@type'))
  graph = RDF::Graph.new << [subject, RDF.type, type]
  hash.each_pair do |field, values|
    Array(values).each do |value|
      graph << [subject, RDF::URI.new(field), value]
    end
  end
  graph.dump(:ntriples)
end