Module: RDF::TriG::StreamingWriter

Included in:
Writer
Defined in:
vendor/bundler/ruby/2.4.0/bundler/gems/rdf-trig-d2d7b59405db/lib/rdf/trig/streaming_writer.rb

Overview

Streaming writer interface

Author:

Instance Method Summary collapse

Instance Method Details

#stream_epilogue

This method returns an undefined value.

Complete open statements



38
39
40
41
42
43
44
# File 'vendor/bundler/ruby/2.4.0/bundler/gems/rdf-trig-d2d7b59405db/lib/rdf/trig/streaming_writer.rb', line 38

def stream_epilogue
  case
  when @previous_statement.nil? ;
  when @streaming_graph then @output.puts " }"
  else @output.puts " ."
  end
end

#stream_statement(statement)

This method returns an undefined value.

Write out a statement, retaining current subject and predicate to create more compact output



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'vendor/bundler/ruby/2.4.0/bundler/gems/rdf-trig-d2d7b59405db/lib/rdf/trig/streaming_writer.rb', line 10

def stream_statement(statement)
  if statement.graph_name != @streaming_graph
    stream_epilogue
    if statement.graph_name
      @output.write "#{format_term(statement.graph_name, options)} {"
    end
    @streaming_graph, @streaming_subject, @streaming_predicate = statement.graph_name, statement.subject, statement.predicate
    @output.write "#{format_term(statement.subject, options)} "
    @output.write "#{format_term(statement.predicate, options)} "
  elsif statement.subject != @streaming_subject
    @output.puts " ." if @previous_statement
    @output.write "#{indent(@streaming_subject ? 1 : 0)}"
    @streaming_subject, @streaming_predicate = statement.subject, statement.predicate
    @output.write "#{format_term(statement.subject, options)} "
    @output.write "#{format_term(statement.predicate, options)} "
  elsif statement.predicate != @streaming_predicate
    @streaming_predicate = statement.predicate
    @output.write ";\n#{indent(@streaming_subject ? 2 : 1)}#{format_term(statement.predicate, options)} "
  else
    @output.write ",\n#{indent(@streaming_subject ? 3 : 2)}"
  end
  @output.write("#{format_term(statement.object, options)}")
  @previous_statement = statement
end