Class: JSON::LD::Reader

Inherits:
RDF::Reader show all
Includes:
StreamingReader
Defined in:
vendor/bundler/ruby/3.3.0/bundler/gems/json-ld-f1de87658826/lib/json/ld/reader.rb

Overview

A JSON-LD parser in Ruby.

Direct Known Subclasses

YAML_LD::Reader

Constant Summary

Constants included from RDF::Util::Logger

RDF::Util::Logger::IOWrapper

Instance Attribute Summary

Attributes included from StreamingReader

#base, #namer

Attributes inherited from RDF::Reader

#options

Attributes included from RDF::Enumerable

#existentials, #universals

Class Method Summary collapse

Instance Method Summary collapse

Methods included from StreamingReader

format, #stream_statement

Methods included from ToRDF

#item_to_rdf, #node, #parse_list

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?

Methods inherited from RDF::Reader

#base_uri, #canonicalize?, #close, each, #each_pg_statement, #encoding, #fail_object, #fail_predicate, #fail_subject, for, format, #intern?, #lineno, open, #prefix, #prefixes, #prefixes=, #read_statement, #read_triple, #rewind, #to_sym, to_sym, #valid?, #validate?

Methods included from RDF::Util::Aliasing::LateBound

#alias_method

Methods included from RDF::Enumerable

add_entailment, #canonicalize, #canonicalize!, #dump, #each_graph, #each_object, #each_predicate, #each_quad, #each_subject, #each_term, #entail, #enum_graph, #enum_object, #enum_predicate, #enum_quad, #enum_statement, #enum_subject, #enum_term, #enum_triple, #graph?, #graph_names, #invalid?, #method_missing, #object?, #objects, #predicate?, #predicates, #project_graph, #quad?, #quads, #respond_to_missing?, #statement?, #statements, #subject?, #subjects, #supports?, #term?, #terms, #to_a, #to_h, #to_set, #triple?, #triples, #valid?, #validate!

Methods included from RDF::Isomorphic

#bijection_to, #isomorphic_with?

Methods included from RDF::Countable

#count, #empty?

Methods included from RDF::Readable

#readable?

Methods included from RDF::Util::Logger

#log_debug, #log_depth, #log_error, #log_fatal, #log_info, #log_recover, #log_recovering?, #log_statistics, #log_warn, #logger

Constructor Details

#initialize(input = $stdin, **options) {|reader| ... } ⇒ Reader

Initializes the JSON-LD reader instance.

Parameters:

  • input (IO, File, String) (defaults to: $stdin)
  • options (Hash{Symbol => Object})

    any additional options (see RDF::Reader#initialize and API.initialize)

Yields:

  • (reader)

    self

Yield Parameters:

Yield Returns:

  • (void)

    ignored

Raises:



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/json-ld-f1de87658826/lib/json/ld/reader.rb', line 76

def initialize(input = $stdin, **options, &block)
  options[:base_uri] ||= options[:base]
  options[:rename_bnodes] = false unless options.key?(:rename_bnodes)
  super do
    @options[:base] ||= base_uri.to_s if base_uri
    # Trim non-JSON stuff in script.
    @doc = if input.respond_to?(:read)
      input
    else
      StringIO.new(input.to_s.sub(/\A[^{\[]*/m, '').sub(/[^}\]]*\Z/m, ''))
    end

    if block
      case block.arity
      when 0 then instance_eval(&block)
      else yield(self)
      end
    end
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class RDF::Enumerable

Class Method Details

.optionsObject

JSON-LD Reader options



17
18
19
20
21
22
23
24
25
26
27
28
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
55
56
57
58
59
60
61
62
63
64
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/json-ld-f1de87658826/lib/json/ld/reader.rb', line 17

def self.options
  super + [
    RDF::CLI::Option.new(
      symbol: :expandContext,
      control: :url2,
      datatype: RDF::URI,
      on: ["--expand-context CONTEXT"],
      description: "Context to use when expanding."
    ) { |arg| RDF::URI(arg).absolute? ? RDF::URI(arg) : StringIO.new(File.read(arg)) },
    RDF::CLI::Option.new(
      symbol: :extractAllScripts,
      datatype: TrueClass,
      default: false,
      control: :checkbox,
      on: ["--[no-]extract-all-scripts"],
      description: "If set to true, when extracting JSON-LD script elements from HTML, unless a specific fragment identifier is targeted, extracts all encountered JSON-LD script elements using an array form, if necessary."
    ) { |arg| RDF::URI(arg) },
    RDF::CLI::Option.new(
      symbol: :lowercaseLanguage,
      datatype: TrueClass,
      control: :checkbox,
      on: ["--[no-]lowercase-language"],
      description: "By default, language tags are left as is. To normalize to lowercase, set this option to `true`."
    ),
    RDF::CLI::Option.new(
      symbol: :processingMode,
      datatype: %w[json-ld-1.0 json-ld-1.1],
      control: :radio,
      on: ["--processingMode MODE", %w[json-ld-1.0 json-ld-1.1]],
      description: "Set Processing Mode (json-ld-1.0 or json-ld-1.1)"
    ),
    RDF::CLI::Option.new(
      symbol: :rdfDirection,
      datatype: %w[i18n-datatype compound-literal],
      default: 'null',
      control: :select,
      on: ["--rdf-direction DIR", %w[i18n-datatype compound-literal]],
      description: "How to serialize literal direction (i18n-datatype compound-literal)"
    ) { |arg| RDF::URI(arg) },
    RDF::CLI::Option.new(
      symbol: :stream,
      datatype: TrueClass,
      control: :checkbox,
      on: ["--[no-]stream"],
      description: "Optimize for streaming JSON-LD to RDF."
    ) { |arg| arg }
  ]
end