Class: JSON::LD::Reader
- Inherits:
-
RDF::Reader
- Object
- RDF::Reader
- JSON::LD::Reader
- Defined in:
- lib/json/ld/reader.rb
Overview
A JSON-LD parser in Ruby.
Defined Under Namespace
Classes: EvaluationContext
Constant Summary collapse
- DEFAULT_CONTEXT =
Default context
{ "rdf" => "http://www.w3.org/1999/02/22-rdf-syntax-ns#", "rdfs" => "http://www.w3.org/2000/01/rdf-schema#", "owl" => "http://www.w3.org/2002/07/owl#", "xsd" => "http://www.w3.org/2001/XMLSchema#", "dcterms" => "http://purl.org/dc/terms/", "foaf" => "http://xmlns.com/foaf/0.1/", "cal" => "http://www.w3.org/2002/12/cal/ical#", "vcard" => "http://www.w3.org/2006/vcard/ns# ", "geo" => "http://www.w3.org/2003/01/geo/wgs84_pos#", "cc" => "http://creativecommons.org/ns#", "sioc" => "http://rdfs.org/sioc/ns#", "doap" => "http://usefulinc.com/ns/doap#", "com" => "http://purl.org/commerce#", "ps" => "http://purl.org/payswarm#", "gr" => "http://purl.org/goodrelations/v1#", "sig" => "http://purl.org/signature#", "ccard" => "http://purl.org/commerce/creditcard#", "@coerce" => { # Note: rdf:type is not in the document, but necessary for this implementation "xsd:anyURI" => ["rdf:type", "foaf:homepage", "foaf:member", "rdf:type"], "xsd:integer" => "foaf:age", } }.freeze
Instance Attribute Summary collapse
-
#graph ⇒ RDF::Graph
readonly
The graph constructed when parsing.
Instance Method Summary collapse
- #each_statement(&block) ⇒ Object
- #each_triple(&block) ⇒ Object
-
#initialize(input = $stdin, options = {}) {|reader| ... } ⇒ Reader
constructor
Initializes the RDF/JSON reader instance.
Constructor Details
#initialize(input = $stdin, options = {}) {|reader| ... } ⇒ Reader
Initializes the RDF/JSON reader instance.
121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/json/ld/reader.rb', line 121 def initialize(input = $stdin, = {}, &block) super do @base_uri = uri([:base_uri]) if [:base_uri] @doc = ::JSON.load(input) if block_given? case block.arity when 0 then instance_eval(&block) else block.call(self) end end end end |
Instance Attribute Details
#graph ⇒ RDF::Graph (readonly)
The graph constructed when parsing.
41 42 43 |
# File 'lib/json/ld/reader.rb', line 41 def graph @graph end |
Instance Method Details
#each_statement(&block) ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/json/ld/reader.rb', line 138 def each_statement(&block) @callback = block # initialize the evaluation context with the appropriate base ec = EvaluationContext.new do |ec| ec.base = @base_uri if @base_uri parse_context(ec, DEFAULT_CONTEXT) end traverse("", @doc, nil, nil, ec) end |
#each_triple(&block) ⇒ Object
153 154 155 156 157 |
# File 'lib/json/ld/reader.rb', line 153 def each_triple(&block) each_statement do |statement| block.call(*statement.to_triple) end end |