Class: RDF::RDFa::Reader::EvaluationContext

Inherits:
Object
  • Object
show all
Defined in:
lib/rdf/rdfa/reader.rb

Overview

The Recursive Baggage

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base, host_defaults) ⇒ EvaluationContext

Returns a new instance of EvaluationContext

Parameters:

  • base (RDF::URI)
  • host_defaults (Hash)

Options Hash (host_defaults):

  • :term_mappings (Hash{String => RDF::URI})

    Hash of NCName => URI

  • :vocabulary (Hash{String => RDF::URI})

    Hash of prefix => URI


210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/rdf/rdfa/reader.rb', line 210

def initialize(base, host_defaults)
  # Initialize the evaluation context, [5.1]
  @base = base
  @parent_subject = @base
  @parent_object = nil
  @namespaces = {}
  @incomplete_triples = []
  @language = nil
  @uri_mappings = host_defaults.fetch(:uri_mappings, {})
  @term_mappings = host_defaults.fetch(:term_mappings, {})
  @default_vocabulary = host_defaults.fetch(:vocabulary, nil)
end

Instance Attribute Details

#baseRDF::URI

The base.

This will usually be the URL of the document being processed, but it could be some other URL, set by some other mechanism, such as the (X)HTML base element. The important thing is that it establishes a URL against which relative paths can be resolved.

Returns:

  • (RDF::URI)

116
117
118
# File 'lib/rdf/rdfa/reader.rb', line 116

def base
  @base
end

#default_vocabularyRDF::URI

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.

Returns:

  • (RDF::URI)

196
197
198
# File 'lib/rdf/rdfa/reader.rb', line 196

def default_vocabulary
  @default_vocabulary
end

#incomplete_triplesArray<Array<RDF::URI, RDF::Resource>>

A list of incomplete triples.

A triple can be incomplete when no object resource is provided alongside a predicate that requires a resource (i.e., @rel or @rev). The triples can be completed when a resource becomes available, which will be when the next subject is specified (part of the process called chaining).

Returns:

  • (Array<Array<RDF::URI, RDF::Resource>>)

167
168
169
# File 'lib/rdf/rdfa/reader.rb', line 167

def incomplete_triples
  @incomplete_triples
end

#languageSymbol

The language. Note that there is no default language.

Returns:

  • (Symbol)

174
175
176
# File 'lib/rdf/rdfa/reader.rb', line 174

def language
  @language
end

#list_mappingHash{RDF:URI: Array<RDF::Resource>}

lists

A hash associating lists with properties.

Returns:

  • (Hash{RDF:URI: Array<RDF::Resource>})

204
205
206
# File 'lib/rdf/rdfa/reader.rb', line 204

def list_mapping
  @list_mapping
end

#namespacesHash{String => Namespace}

A list of current, in-scope Namespaces. This is the subset of uri_mappings which are defined using xmlns.

Returns:


155
156
157
# File 'lib/rdf/rdfa/reader.rb', line 155

def namespaces
  @namespaces
end

#parent_objectRDF::URI

The parent object.

In some situations the object of a statement becomes the subject of any nested statements, and this property is used to convey this value. Note that this value may be a bnode, since in some situations a number of nested statements are grouped together on one bnode. This means that the bnode must be set in the containing statement and passed down, and this property is used to convey this value.

Returns:

  • (RDF::URI)

140
141
142
# File 'lib/rdf/rdfa/reader.rb', line 140

def parent_object
  @parent_object
end

#parent_subjectRDF::URI

The parent subject.

The initial value will be the same as the initial value of base, but it will usually change during the course of processing.

Returns:

  • (RDF::URI)

126
127
128
# File 'lib/rdf/rdfa/reader.rb', line 126

def parent_subject
  @parent_subject
end

#term_mappingsHash{Symbol => RDF::URI}

The term mappings, a list of terms and their associated URIs.

This specification does not define an initial list. Host Languages may define an initial list. If a Host Language provides an initial list, it should do so via an RDFa Context document.

Returns:

  • (Hash{Symbol => RDF::URI})

185
186
187
# File 'lib/rdf/rdfa/reader.rb', line 185

def term_mappings
  @term_mappings
end

#uri_mappingsHash{Symbol => String}

A list of current, in-scope URI mappings.

Returns:


147
148
149
# File 'lib/rdf/rdfa/reader.rb', line 147

def uri_mappings
  @uri_mappings
end

Instance Method Details

#initialize_copy(from) ⇒ Object

Copy this Evaluation Context

Parameters:


226
227
228
229
230
231
232
# File 'lib/rdf/rdfa/reader.rb', line 226

def initialize_copy(from)
  # clone the evaluation context correctly
  @uri_mappings = from.uri_mappings.clone
  @incomplete_triples = from.incomplete_triples.clone
  @namespaces = from.namespaces.clone
  @list_mapping = from.list_mapping # Don't clone
end

#inspectObject


234
235
236
237
238
239
240
241
242
243
# File 'lib/rdf/rdfa/reader.rb', line 234

def inspect
  v = ['base', 'parent_subject', 'parent_object', 'language', 'default_vocabulary'].map do |a|
    "#{a}=#{o = self.send(a); o.respond_to?(:to_ntriples) ? o.to_ntriples : o.inspect}"
  end
  v << "uri_mappings[#{uri_mappings.keys.length}]"
  v << "incomplete_triples[#{incomplete_triples.length}]"
  v << "term_mappings[#{term_mappings.keys.length}]"
  v << "lists[#{list_mapping.keys.length}]" if list_mapping
  v.join(", ")
end