Module: JSON::LD::StreamingReader

Includes:
ToRDF, Utils
Included in:
Reader
Defined in:
vendor/bundler/ruby/3.3.0/bundler/gems/json-ld-f1de87658826/lib/json/ld/streaming_reader.rb

Overview

A streaming JSON-LD parser in Ruby.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ToRDF

#item_to_rdf, #node

Methods included from Utils

#add_value, #as_array, #as_resource, #blank_node?, #compare_values, #graph?, #has_value?, #index?, #list?, #node?, #node_or_ref?, #node_reference?, #property?, #simple_graph?, #value?

Instance Attribute Details

#baseRDF::URI (readonly)

The base URI to use when resolving relative URIs

Returns:



20
21
22
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/json-ld-f1de87658826/lib/json/ld/streaming_reader.rb', line 20

def base
  @base
end

#namerObject (readonly)

Returns the value of attribute namer.



21
22
23
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/json-ld-f1de87658826/lib/json/ld/streaming_reader.rb', line 21

def namer
  @namer
end

Class Method Details

.formatObject



23
24
25
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/json-ld-f1de87658826/lib/json/ld/streaming_reader.rb', line 23

def self.format
  JSON::LD::Format
end

Instance Method Details

#stream_statementObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/json-ld-f1de87658826/lib/json/ld/streaming_reader.rb', line 29

def stream_statement
  unique_bnodes = @options[:unique_bnodes]
  rename_bnodes = @options.fetch(:rename_bnodes, true)
  # FIXME: document loader doesn't stream
  @base = RDF::URI(@options[:base] || base_uri)
  mj_opts = @options.keep_if { |k, v| k != :adapter || MUTLI_JSON_ADAPTERS.include?(v) }
  value = MultiJson.load(@doc, mj_opts)
  context_ref = @options[:expandContext]
  # context_ref = @options.fetch(:expandContext, remote_doc.contextUrl)
  context = Context.parse(context_ref, **@options)

  @namer = if unique_bnodes
    BlankNodeUniqer.new
  else
    (rename_bnodes ? BlankNodeNamer.new("b") : BlankNodeMapper.new)
  end
  # Namer for naming provisional nodes, which may be determined later to be actual
  @provisional_namer = BlankNodeNamer.new("p")

  parse_object(value, nil, context, graph_is_named: false) do |st|
    # Only output reasonably valid triples
    yield(st) if st.to_a.all? { |r| r.is_a?(RDF::Term) && (r.uri? ? r.valid? : true) }
  end
rescue ::JSON::ParserError, ::JSON::LD::JsonLdError => e
  log_fatal("Failed to parse input document: #{e.message}", exception: RDF::ReaderError)
end