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
18 19 20 |
# File 'lib/json/ld/streaming_reader.rb', line 18 def base @base end |
#namer ⇒ Object (readonly)
Returns the value of attribute namer.
19 20 21 |
# File 'lib/json/ld/streaming_reader.rb', line 19 def namer @namer end |
Class Method Details
Instance Method Details
#stream_statement(&block) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/json/ld/streaming_reader.rb', line 25 def stream_statement(&block) unique_bnodes, rename_bnodes = @options[:unique_bnodes], @options.fetch(:rename_bnodes, true) # FIXME: document loader doesn't stream @base = RDF::URI(@options[:base] || base_uri) value = MultiJson.load(@doc, **@options) context_ref = @options[:expandContext] #context_ref = @options.fetch(:expandContext, remote_doc.contextUrl) context = Context.parse(context_ref, **@options) @namer = unique_bnodes ? BlankNodeUniqer.new : (rename_bnodes ? BlankNodeNamer.new("b") : BlankNodeMapper.new) # 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 if st.to_a.all? {|r| r.is_a?(RDF::Term) && (r.uri? ? r.valid? : true)} block.call(st) end end rescue ::JSON::ParserError, ::JSON::LD::JsonLdError => e log_fatal("Failed to parse input document: #{e.}", exception: RDF::ReaderError) end |