Class: JSON::LD::Reader::EvaluationContext

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize {|ec| ... } ⇒ EvaluationContext

Create new evaluation context

Yields:

  • (ec)

Yield Parameters:



96
97
98
99
100
101
102
# File 'lib/json/ld/reader.rb', line 96

def initialize
  @base = nil
  @mappings =  {}
  @vocab = nil
  @coerce = {}
  yield(self) if block_given?
end

Instance Attribute Details

#baseObject

The base.

The ‘@base` string is a special keyword that states that any relative IRI MUST be appended to the string specified by `@base`.



62
63
64
# File 'lib/json/ld/reader.rb', line 62

def base
  @base
end

#coerceObject

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`.



89
90
91
# File 'lib/json/ld/reader.rb', line 89

def coerce
  @coerce
end

#mappingsObject

A list of current, in-scope URI mappings.



67
68
69
# File 'lib/json/ld/reader.rb', line 67

def mappings
  @mappings
end

#vocabObject

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.



76
77
78
# File 'lib/json/ld/reader.rb', line 76

def vocab
  @vocab
end

Instance Method Details

#inspectObject



104
105
106
107
108
109
# File 'lib/json/ld/reader.rb', line 104

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