Class: RDF::RDFa::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/rdf/rdfa/context.rb,
lib/rdf/rdfa/context/xml.rb,
lib/rdf/rdfa/context/html.rb,
lib/rdf/rdfa/context/xhtml.rb

Overview

This file is automatically generated by ./script/intern_context RDFa context for www.w3.org/2011/rdfa-context/xhtml-rdfa-1.1

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (RDF::RDFa::Context) initialize(uri, options = {}) {|context| ... }

Initialize a new context from the given URI.

Parses the context and places it in the repository and cache

Parameters:

  • uri (RDF::URI, #to_s)

    URI of context to be represented

Yields:

  • (context)

Yield Parameters:

Yield Returns:

  • (void)

    ignored



37
38
39
40
41
42
43
44
45
# File 'lib/rdf/rdfa/context.rb', line 37

def initialize(uri, options = {}, &block)
  @uri = RDF::URI.intern(uri)
  @prefixes = options.fetch(:prefixes, {})
  @terms = options.fetch(:terms, {})
  @vocabulary = options[:vocabulary]
  
  yield(self) if block_given?
  self
end

Instance Attribute Details

- (Hash{Symbol => RDF::URI}) prefixes (readonly)

Prefix mappings defined in this context

Returns:

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


13
14
15
# File 'lib/rdf/rdfa/context.rb', line 13

def prefixes
  @prefixes
end

- (Hash{Symbol => RDF::URI}) terms (readonly)

Term mappings defined in this context

Returns:

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


17
18
19
# File 'lib/rdf/rdfa/context.rb', line 17

def terms
  @terms
end

- (RDF::URI) uri (readonly)

URI defining this context

Returns:

  • (RDF::URI)


25
26
27
# File 'lib/rdf/rdfa/context.rb', line 25

def uri
  @uri
end

- (RDF::URI) vocabulary (readonly)

Default URI defined for this vocabulary

Returns:

  • (RDF::URI)


21
22
23
# File 'lib/rdf/rdfa/context.rb', line 21

def vocabulary
  @vocabulary
end

Class Method Details

+ (RDF::Util::Cache) cache

Returns:

  • (RDF::Util::Cache)


50
51
52
53
54
55
# File 'lib/rdf/rdfa/context.rb', line 50

def self.cache
  require 'rdf/util/cache' unless defined?(::RDF::Util::Cache)
  @cache ||= begin
    RDF::Util::Cache.new(-1)
  end
end

+ (Object) find_with_html_rdfa_1_1(uri)



5
6
7
8
9
10
11
12
# File 'lib/rdf/rdfa/context/html.rb', line 5

def self.find_with_html_rdfa_1_1(uri)
  if uri.to_s == "http://www.w3.org/2011/rdfa-context/html-rdfa-1.1"
    @_html_rdfa_1_1_prof ||= RDF::RDFa::Context.new(RDF::URI("http://www.w3.org/2011/rdfa-context/html-rdfa-1.1"), {
    })
  else
    find_without_html_rdfa_1_1(uri)
  end
end

+ (Object) find_with_rdfa_1_1(uri)



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/rdf/rdfa/context/xml.rb', line 5

def self.find_with_rdfa_1_1(uri)
  if uri.to_s == "http://www.w3.org/2011/rdfa-context/rdfa-1.1"
    @_rdfa_1_1_prof ||= RDF::RDFa::Context.new(RDF::URI("http://www.w3.org/2011/rdfa-context/rdfa-1.1"), {
      :prefixes => {
        :cc      => "http://creativecommons.org/ns#",
        :ctag    => "http://commontag.org/ns#",
        :dc      => "http://purl.org/dc/terms/",
        :dcterms => "http://purl.org/dc/terms/",
        :foaf    => "http://xmlns.com/foaf/0.1/",
        :gr      => "http://purl.org/goodrelations/v1#",
        :grddl   => "http://www.w3.org/2003/g/data-view#",
        :ical    => "http://www.w3.org/2002/12/cal/icaltzd#",
        :ma      => "http://www.w3.org/ns/ma-ont#",
        :og      => "http://ogp.me/ns#",
        :owl     => "http://www.w3.org/2002/07/owl#",
        :rdf     => "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
        :rdfa    => "http://www.w3.org/ns/rdfa#",
        :rdfs    => "http://www.w3.org/2000/01/rdf-schema#",
        :rev     => "http://purl.org/stuff/rev#",
        :rif     => "http://www.w3.org/2007/rif#",
        :schema  => "http://schema.org/",
        :sioc    => "http://rdfs.org/sioc/ns#",
        :skos    => "http://www.w3.org/2004/02/skos/core#",
        :skosxl  => "http://www.w3.org/2008/05/skos-xl#",
        :v       => "http://rdf.data-vocabulary.org/#",
        :vcard   => "http://www.w3.org/2006/vcard/ns#",
        :void    => "http://rdfs.org/ns/void#",
        :wdr     => "http://www.w3.org/2007/05/powder#",
        :wdrs    => "http://www.w3.org/2007/05/powder-s#",
        :xhv     => "http://www.w3.org/1999/xhtml/vocab#",
        :xml     => "http://www.w3.org/XML/1998/namespace",
        :xsd     => "http://www.w3.org/2001/XMLSchema#",
      },
      :terms => {
        :describedby => "http://www.w3.org/2007/05/powder-s#describedby",
        :license     => "http://www.w3.org/1999/xhtml/vocab#license",
        :role        => "http://www.w3.org/1999/xhtml/vocab#role",
      },
    })
  else
    find_without_rdfa_1_1(uri)
  end
end

+ (Object) find_with_xhtml_rdfa_1_1(uri) Also known as: find



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rdf/rdfa/context/xhtml.rb', line 5

def self.find_with_xhtml_rdfa_1_1(uri)
  if uri.to_s == "http://www.w3.org/2011/rdfa-context/xhtml-rdfa-1.1"
    @_xhtml_rdfa_1_1_prof ||= RDF::RDFa::Context.new(RDF::URI("http://www.w3.org/2011/rdfa-context/xhtml-rdfa-1.1"), {
      :terms => {
        :alternate  => "http://www.w3.org/1999/xhtml/vocab#alternate",
        :appendix   => "http://www.w3.org/1999/xhtml/vocab#appendix",
        :bookmark   => "http://www.w3.org/1999/xhtml/vocab#bookmark",
        :chapter    => "http://www.w3.org/1999/xhtml/vocab#chapter",
        :cite       => "http://www.w3.org/1999/xhtml/vocab#cite",
        :contents   => "http://www.w3.org/1999/xhtml/vocab#contents",
        :copyright  => "http://www.w3.org/1999/xhtml/vocab#copyright",
        :first      => "http://www.w3.org/1999/xhtml/vocab#first",
        :glossary   => "http://www.w3.org/1999/xhtml/vocab#glossary",
        :help       => "http://www.w3.org/1999/xhtml/vocab#help",
        :icon       => "http://www.w3.org/1999/xhtml/vocab#icon",
        :index      => "http://www.w3.org/1999/xhtml/vocab#index",
        :last       => "http://www.w3.org/1999/xhtml/vocab#last",
        :license    => "http://www.w3.org/1999/xhtml/vocab#license",
        :meta       => "http://www.w3.org/1999/xhtml/vocab#meta",
        :next       => "http://www.w3.org/1999/xhtml/vocab#next",
        :p3pv1      => "http://www.w3.org/1999/xhtml/vocab#p3pv1",
        :prev       => "http://www.w3.org/1999/xhtml/vocab#prev",
        :previous   => "http://www.w3.org/1999/xhtml/vocab#previous",
        :section    => "http://www.w3.org/1999/xhtml/vocab#section",
        :start      => "http://www.w3.org/1999/xhtml/vocab#start",
        :stylesheet => "http://www.w3.org/1999/xhtml/vocab#stylesheet",
        :subsection => "http://www.w3.org/1999/xhtml/vocab#subsection",
        :top        => "http://www.w3.org/1999/xhtml/vocab#top",
        :up         => "http://www.w3.org/1999/xhtml/vocab#up",
      },
    })
  else
    find_without_xhtml_rdfa_1_1(uri)
  end
end

+ (Object) load(uri)

Load context into repository



95
96
97
98
# File 'lib/rdf/rdfa/context.rb', line 95

def self.load(uri)
  uri = RDF::URI.intern(uri)
  repository.load(uri.to_s, :base_uri => uri, :context => uri) unless repository.has_context?(uri)
end

+ (RDF::Repository) repository

Repository used for saving contexts

Returns:

  • (RDF::Repository)

Raises:



61
62
63
# File 'lib/rdf/rdfa/context.rb', line 61

def self.repository
  @repository ||= RDF::Repository.new(:title => "RDFa Contexts")
end

+ (RDF::Repository) repository=(repo)

Set repository used for saving contexts

Parameters:

  • repo (RDF::Repository)

Returns:

  • (RDF::Repository)

Raises:



69
70
71
72
# File 'lib/rdf/rdfa/context.rb', line 69

def self.repository=(repo)
  raise ContextError, "Context Repository must support context" unless repo.supports?(:context)
  @repository = repo
end

Instance Method Details

- (void) parse(enumerable)

This method returns an undefined value.

Extract vocabulary, prefix mappings and terms from a enumerable object into an instance

Parameters:

  • queryable (RDF::Enumerable, Enumerator)


154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/rdf/rdfa/context.rb', line 154

def parse(enumerable)
  STDERR.puts("process_context: parse context <#{uri}>") if RDF::RDFa.debug?
  resource_info = {}
  enumerable.each do |statement|
    res = resource_info[statement.subject] ||= {}
    next unless statement.object.is_a?(RDF::Literal)
    STDERR.puts("process_context: statement=#{statement.inspect}") if RDF::RDFa.debug?
    %w(uri term prefix vocabulary).each do |term|
      res[term] ||= statement.object.value if statement.predicate == RDF::RDFA[term]
    end
  end

  resource_info.values.each do |res|
    # If one of the objects is not a Literal or if there are additional rdfa:uri or rdfa:term
    # predicates sharing the same subject, no mapping is created.
    uri = res["uri"]
    term = res["term"]
    prefix = res["prefix"]
    vocab = res["vocabulary"]
    STDERR.puts("process_context: uri=#{uri.inspect}, term=#{term.inspect}, prefix=#{prefix.inspect}, vocabulary=#{vocab.inspect}") if RDF::RDFa.debug?

    @vocabulary = vocab if vocab
    
    # For every extracted triple that is the common subject of an rdfa:prefix and an rdfa:uri
    # predicate, create a mapping from the object literal of the rdfa:prefix predicate to the
    # object literal of the rdfa:uri predicate. Add or update this mapping in the local list of
    # URI mappings after transforming the 'prefix' component to lower-case.
    # For every extracted
    prefix(prefix.downcase, uri) if uri && prefix && prefix != "_"
  
    # triple that is the common subject of an rdfa:term and an rdfa:uri predicate, create a
    # mapping from the object literal of the rdfa:term predicate to the object literal of the
    # rdfa:uri predicate. Add or update this mapping in the local term mappings.
    term(term, uri) if term && uri
  end
end

- (RDF::URI) prefix(name, uri) - (RDF::URI) prefix(name)

Defines the given named URI prefix for this context.

Examples:

Defining a URI prefix

context.prefix :dc, RDF::URI('http://purl.org/dc/terms/')

Returning a URI prefix

context.prefix(:dc)    #=> RDF::URI('http://purl.org/dc/terms/')

Overloads:

  • - (RDF::URI) prefix(name, uri)

    Parameters:

    • name (Symbol, #to_s)
    • uri (RDF::URI, #to_s)
  • - (RDF::URI) prefix(name)

    Parameters:

    • name (Symbol, #to_s)

Returns:

  • (RDF::URI)


122
123
124
125
# File 'lib/rdf/rdfa/context.rb', line 122

def prefix(name, uri = nil)
  name = name.to_s.empty? ? nil : (name.respond_to?(:to_sym) ? name.to_sym : name.to_s.to_sym)
  uri.nil? ? prefixes[name] : prefixes[name] = uri
end

- (RDF::Repository) repository

Returns:

  • (RDF::Repository)


101
102
103
# File 'lib/rdf/rdfa/context.rb', line 101

def repository
  Context.repository
end

- (RDF::URI) term(name, uri) - (RDF::URI) term(name)

Defines the given named URI term for this context.

Examples:

Defining a URI term

context.term :title, RDF::URI('http://purl.org/dc/terms/title')

Returning a URI context

context.term(:title)    #=> RDF::URI('http://purl.org/dc/terms/TITLE')

Overloads:

  • - (RDF::URI) term(name, uri)

    Parameters:

    • name (Symbol, #to_s)
    • uri (RDF::URI, #to_s)
  • - (RDF::URI) term(name)

    Parameters:

    • name (Symbol, #to_s)

Returns:

  • (RDF::URI)


144
145
146
147
# File 'lib/rdf/rdfa/context.rb', line 144

def term(name, uri = nil)
  name = name.to_s.empty? ? nil : (name.respond_to?(:to_sym) ? name.to_sym : name.to_s.to_sym)
  uri.nil? ? terms[name] : terms[name] = uri
end