Class: JSON::LD::Reader::EvaluationContext
- Inherits:
-
Object
- Object
- JSON::LD::Reader::EvaluationContext
- Defined in:
- lib/json/ld/reader.rb
Overview
Context
The ‘@context` keyword is used to change how the JSON-LD processor evaluates key- value pairs. In this case, it was used to map one string (`’myvocab’‘) to another string, which is interpreted as a IRI. In the example above, the `myvocab` string is replaced with “example.org/myvocab#” when it is detected. In the example above, `“myvocab:personality”` would expand to “example.org/myvocab#personality”.
This mechanism is a short-hand for RDF, called a ‘CURIE`, and provides developers an unambiguous way to map any JSON value to RDF.
Instance Attribute Summary collapse
-
#base ⇒ Object
The base.
-
#coerce ⇒ Object
Type coersion.
-
#mappings ⇒ Object
A list of current, in-scope URI mappings.
-
#vocab ⇒ Object
The default vocabulary.
Instance Method Summary collapse
-
#initialize {|ec| ... } ⇒ EvaluationContext
constructor
Create new evaluation context.
- #inspect ⇒ Object
Constructor Details
#initialize {|ec| ... } ⇒ EvaluationContext
Create new evaluation context
69 70 71 72 73 74 75 |
# File 'lib/json/ld/reader.rb', line 69 def initialize @base = nil @mappings = {} @vocab = nil @coerce = {} yield(self) if block_given? end |
Instance Attribute Details
#base ⇒ Object
The base.
The ‘@base` string is a special keyword that states that any relative IRI MUST be appended to the string specified by `@base`.
35 36 37 |
# File 'lib/json/ld/reader.rb', line 35 def base @base end |
#coerce ⇒ Object
Type coersion
The @coerce keyword is used to specify type coersion rules for the data. For each key in the map, the key is the type to be coerced to and the value is the vocabulary term to be coerced. Type coersion for the key ‘xsd:anyURI` asserts that all vocabulary terms listed should undergo coercion to an IRI, including `@base` processing for relative IRIs and CURIE processing for compact URI Expressions like `foaf:homepage`.
As the value may be an array, this is maintained as a reverse mapping of ‘property` => `type`.
62 63 64 |
# File 'lib/json/ld/reader.rb', line 62 def coerce @coerce end |
#mappings ⇒ Object
A list of current, in-scope URI mappings.
40 41 42 |
# File 'lib/json/ld/reader.rb', line 40 def mappings @mappings end |
#vocab ⇒ Object
The default vocabulary
A value to use as the prefix URI when a term is used. This specification does not define an initial setting for the default vocabulary. Host Languages may define an initial setting.
49 50 51 |
# File 'lib/json/ld/reader.rb', line 49 def vocab @vocab end |
Instance Method Details
#inspect ⇒ Object
77 78 79 80 81 82 |
# File 'lib/json/ld/reader.rb', line 77 def inspect v = %w([EvaluationContext) + %w(base vocab).map {|a| "#{a}='#{self.send(a).inspect}'"} v << "mappings[#{mappings.keys.length}]" v << "coerce[#{coerce.keys.length}]" v.join(", ") + "]" end |