class RDF::Vocabulary::Term
A Vocabulary Term is a URI that can also act as an {Enumerable} to generate the RDF definition of vocabulary terms as defined within the vocabulary definition.
Attributes
@!method comment
`rdfs:comment` accessor @return [String]
@!method label
`rdfs:label` accessor @return [String]
@!method type
`rdf:type` accessor @return [RDF::URI]
@!method subClassOf
`rdfs:subClassOf` accessor @return [RDF::URI]
@!method subPropertyOf
`rdfs:subPropertyOf` accessor @return [RDF::URI]
@!method domain
`rdfs:domain` accessor @return [RDF::URI]
@!method range
`rdfs:range` accessor @return [RDF::URI]
@!method inverseOf
`owl:inverseOf` accessor @return [RDF::URI]
@!method domainIncludes
`schema:domainIncludes` accessor @return [RDF::URI]
@!method rangeIncludes
`schema:rangeIncludes` accoessor @return [RDF::URI]
@!attribute [rw] attributes
Attributes of this vocabulary term, used for finding `label` and `comment` and to serialize the term back to RDF. @return [Hash{Symbol,Resource => Term, #to_s}]
Public Class Methods
@overload URI(uri, options = {})
@param [URI, String, #to_s] uri @param [Hash{Symbol => Object}] options @option options [Boolean] :validate (false) @option options [Boolean] :canonicalize (false) @option options [Hash{Symbol,Resource => Term, #to_s}] :attributes Attributes of this vocabulary term, used for finding `label` and `comment` and to serialize the term back to RDF
@overload URI(options = {})
@param [Hash{Symbol => Object}] options @option options options [Boolean] :validate (false) @option options options [Boolean] :canonicalize (false) @option options [Vocabulary] :vocab The {Vocabulary} associated with this term. @option options [String, #to_s] :scheme The scheme component. @option options [String, #to_s] :user The user component. @option options [String, #to_s] :password The password component. @option options [String, #to_s] :userinfo The u optionsserinfo component. If this is supplied, the user and password compo optionsnents must be omitted. @option options [String, #to_s] :host The host component. @option options [String, #to_s] :port The port component. @option options [String, #to_s] :authority The a optionsuthority component. If this is supplied, the user, password, useri optionsnfo, host, and port components must be omitted. @option options [String, #to_s] :path The path component. @option options [String, #to_s] :query The query component. @option options [String, #to_s] :fragment The fragment component. @option options [Hash{Symbol,Resource => Term, #to_s}] :attributes Attributes of this vocabulary term, used for finding `label` and `comment` and to serialize the term back to RDF
# File lib/rdf/vocabulary.rb, line 528 def initialize(*args, **options) @attributes = options.fetch(:attributes) if RUBY_ENGINE == "rbx" # FIXME: Somehow, this gets messed up in Rubinius args << options super(*args) else super end end
Public Instance Methods
Is this a class term? @return [Boolean]
# File lib/rdf/vocabulary.rb, line 566 def class? !!(self.type.to_s =~ /Class/) end
Is this a class term? @return [Boolean]
# File lib/rdf/vocabulary.rb, line 580 def datatype? !!(self.type.to_s =~ /Datatype/) end
Accessor for `schema:domainIncludes` @return [RDF::URI]
# File lib/rdf/vocabulary.rb, line 689 def domain_includes Array(@attributes[:domainIncludes]).map {|v| RDF::Vocabulary.expand_pname(v)} end
Returns a duplicate copy of `self`.
@return [RDF::URI]
# File lib/rdf/vocabulary.rb, line 549 def dup self.class.new((@value || @object).dup, attributes: @attributes) end
Enumerate each statement constructed from the defined vocabulary terms
If a property value is known to be a {URI}, or expands to a {URI}, the `object` is a URI, otherwise, it will be a {Literal}.
@yield statement @yieldparam [RDF::Statement]
# File lib/rdf/vocabulary.rb, line 598 def each_statement attributes.reject {|p| p == :vocab}.each do |prop, values| Array(values).each do |value| begin case prop when :type prop = RDF.type value = RDF::Vocabulary.expand_pname(value) when :subClassOf prop = RDFS.subClassOf value = RDF::Vocabulary.expand_pname(value) when :subPropertyOf prop = RDFS.subPropertyOf value = RDF::Vocabulary.expand_pname(value) when :domain prop = RDFS.domain value = RDF::Vocabulary.expand_pname(value) when :range prop = RDFS.range value = RDF::Vocabulary.expand_pname(value) when :inverseOf prop = RDF::URI("http://schema.org/inverseOf") value = RDF::Vocabulary.expand_pname(value) when :domainIncludes prop = RDF::URI("http://schema.org/domainIncludes") value = RDF::Vocabulary.expand_pname(value) when :rangeIncludes prop = RDF::URI("http://schema.org/rangeIncludes") value = RDF::Vocabulary.expand_pname(value) when :label prop = RDF::RDFS.label when :comment prop = RDF::RDFS.comment else prop = RDF::Vocabulary.expand_pname(prop.to_s) next unless prop v = value.to_s value = RDF::Vocabulary.expand_pname(v) unless value && value.valid? # Use as most appropriate literal value = [ RDF::Literal::Date, RDF::Literal::DateTime, RDF::Literal::Integer, RDF::Literal::Decimal, RDF::Literal::Double, RDF::Literal::Boolean, RDF::Literal ].inject(nil) do |memo, klass| l = klass.new(v) memo || (l if l.valid?) end end end yield RDF::Statement(self, prop, value) rescue KeyError # Skip things eroneously defined in the vocabulary end end end end
Return an enumerator over {RDF::Statement} defined for this vocabulary. @return [RDF::Enumerable::Enumerator] @see Object#enum_for
# File lib/rdf/vocabulary.rb, line 665 def enum_for(method = :each_statement, *args) # Ensure that enumerators are, themselves, queryable this = self Enumerable::Enumerator.new do |yielder| this.send(method, *args) {|*y| yielder << (y.length > 1 ? y : y.first)} end end
Is this neither a class, property or datatype term? @return [Boolean]
# File lib/rdf/vocabulary.rb, line 587 def other? !!(self.type.to_s !~ /(Class|Property|Datatype)/) end
Is this a class term? @return [Boolean]
# File lib/rdf/vocabulary.rb, line 573 def property? !!(self.type.to_s =~ /Property/) end
Accessor for `schema:rangeIncludes` @return [RDF::URI]
# File lib/rdf/vocabulary.rb, line 695 def range_includes Array(@attributes[:rangeIncludes]).map {|v| RDF::Vocabulary.expand_pname(v)} end
Implement accessor to symbol attributes
# File lib/rdf/vocabulary.rb, line 683 def respond_to?(method, include_all = false) @attributes.has_key?(method) || super end
Determine if the URI is a valid according to RFC3987
@return [Boolean] `true` or `false` @since 0.3.9
# File lib/rdf/vocabulary.rb, line 558 def valid? # Validate relative to RFC3987 to_s.match(RDF::URI::IRI) || false end
Vocabulary of this term.
@return [RDF::Vocabulary]
# File lib/rdf/vocabulary.rb, line 543 def vocab; @attributes.fetch(:vocab); end
Protected Instance Methods
Implement accessor to symbol attributes
# File lib/rdf/vocabulary.rb, line 701 def method_missing(method, *args, &block) case method when :comment @attributes.fetch(method, "") when :label @attributes.fetch(method, to_s.split(/[\/\#]/).last) when :type, :subClassOf, :subPropertyOf, :domain, :range, :inverseOf, :domainIncludes, :rangeIncludes Array(@attributes[method]).map {|v| RDF::Vocabulary.expand_pname(v)} else super end end