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
readonly
Type coersion.
-
#list ⇒ Object
readonly
List coercion.
-
#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
78 79 80 81 82 83 84 85 |
# File 'lib/json/ld/reader.rb', line 78 def initialize @base = nil @mappings = {} @vocab = nil @coerce = {} @list = [] 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`.
37 38 39 |
# File 'lib/json/ld/reader.rb', line 37 def base @base end |
#coerce ⇒ Object (readonly)
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 ‘@iri` 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`.
64 65 66 |
# File 'lib/json/ld/reader.rb', line 64 def coerce @coerce end |
#list ⇒ Object (readonly)
List coercion
The @list keyword is used to specify that properties having an array value are to be treated as an ordered list, rather than a normal unordered list
71 72 73 |
# File 'lib/json/ld/reader.rb', line 71 def list @list end |
#mappings ⇒ Object
A list of current, in-scope URI mappings.
42 43 44 |
# File 'lib/json/ld/reader.rb', line 42 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.
51 52 53 |
# File 'lib/json/ld/reader.rb', line 51 def vocab @vocab end |
Instance Method Details
#inspect ⇒ Object
87 88 89 90 91 92 93 |
# File 'lib/json/ld/reader.rb', line 87 def inspect v = %w([EvaluationContext) + %w(base vocab).map {|a| "#{a}='#{self.send(a).inspect}'"} v << "mappings[#{mappings.keys.length}]=#{mappings}" v << "coerce[#{coerce.keys.length}]=#{coerce}" v << "list[#{list.length}]=#{list}" v.join(", ") + "]" end |