Module: JSON::LD::StreamingReader
Overview
A streaming JSON-LD parser in Ruby.
Instance Attribute Summary collapse
-
#base ⇒ RDF::URI
readonly
The base URI to use when resolving relative URIs.
-
#namer ⇒ Object
readonly
Returns the value of attribute namer.
Class Method Summary collapse
Instance Method Summary collapse
Methods included from ToRDF
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
#base ⇒ RDF::URI (readonly)
The base URI to use when resolving relative URIs
20 21 22 |
# File 'lib/json/ld/streaming_reader.rb', line 20 def base @base end |
#namer ⇒ Object (readonly)
Returns the value of attribute namer.
21 22 23 |
# File 'lib/json/ld/streaming_reader.rb', line 21 def namer @namer end |
Class Method Details
Instance Method Details
#stream_statement ⇒ Object
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 '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.}", exception: RDF::ReaderError) end |