Class: RDF::Vocabulary::Term
Overview
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.
Constant Summary
Constants inherited from URI
URI::CACHE_SIZE, URI::GEN_DELIMS, URI::IAUTHORITY, URI::IFRAGMENT, URI::IHIER_PART, URI::IHOST, URI::IPATH_ABEMPTY, URI::IPATH_ABSOLUTE, URI::IPATH_EMPTY, URI::IPATH_NOSCHEME, URI::IPATH_ROOTLESS, URI::IPCHAR, URI::IPRIVATE, URI::IP_literal, URI::IQUERY, URI::IREG_NAME, URI::IRELATIVE_PART, URI::IRELATIVE_REF, URI::IRI, URI::IRI_PARTS, URI::ISEGMENT, URI::ISEGMENT_NZ, URI::ISEGMENT_NZ_NC, URI::IUNRESERVED, URI::IUSERINFO, URI::NON_HIER_SCHEMES, URI::PCT_ENCODED, URI::PORT, URI::PORT_MAPPING, URI::RDS_2A, URI::RDS_2B1, URI::RDS_2B2, URI::RDS_2C1, URI::RDS_2C2, URI::RDS_2D, URI::RDS_2E, URI::RESERVED, URI::SCHEME, URI::SUB_DELIMS, URI::UCSCHAR, URI::UNRESERVED
Instance Attribute Summary collapse
-
#attributes ⇒ Hash{Symbol,Resource => Term, #to_s}
Attributes of this vocabulary term, used for finding ‘label` and `comment` and to serialize the term back to RDF.
Instance Method Summary collapse
-
#class? ⇒ Boolean
Is this a class term?.
-
#comment ⇒ String
‘rdfs:comment` accessor.
-
#datatype? ⇒ Boolean
Is this a class term?.
-
#domain ⇒ RDF::URI
‘rdfs:domain` accessor.
-
#domain_includes ⇒ RDF::URI
Accessor for ‘schema:domainIncludes`.
-
#domainIncludes ⇒ RDF::URI
‘schema:domainIncludes` accessor.
-
#dup ⇒ RDF::URI
Returns a duplicate copy of ‘self`.
-
#each_statement {|| ... } ⇒ Object
Enumerate each statement constructed from the defined vocabulary terms.
-
#enum_for(method = :each_statement, *args) ⇒ RDF::Enumerable::Enumerator
(also: #to_enum)
Return an enumerator over Statement defined for this vocabulary.
-
#initialize(*args, **options) ⇒ Term
constructor
A new instance of Term.
-
#inspect ⇒ String
Returns a
Stringrepresentation of the URI object’s state. -
#inverseOf ⇒ RDF::URI
‘owl:inverseOf` accessor.
-
#label ⇒ String
‘rdfs:label` accessor.
-
#other? ⇒ Boolean
Is this neither a class, property or datatype term?.
-
#property? ⇒ Boolean
Is this a class term?.
-
#range ⇒ RDF::URI
‘rdfs:range` accessor.
-
#range_includes ⇒ RDF::URI
Accessor for ‘schema:rangeIncludes`.
-
#rangeIncludes ⇒ RDF::URI
‘schema:rangeIncludes` accoessor.
-
#respond_to?(method, include_all = false) ⇒ Boolean
Implement accessor to symbol attributes.
-
#subClassOf ⇒ RDF::URI
‘rdfs:subClassOf` accessor.
-
#subPropertyOf ⇒ RDF::URI
‘rdfs:subPropertyOf` accessor.
-
#type ⇒ RDF::URI
‘rdf:type` accessor.
-
#valid? ⇒ Boolean
Determine if the URI is a valid according to RFC3987.
-
#vocab ⇒ RDF::Vocabulary
Vocabulary of this term.
Methods inherited from URI
#+, #/, #==, #===, #=~, #absolute?, #authority, #authority=, cache, #canonicalize, #canonicalize!, #end_with?, #eql?, #fragment, #fragment=, #freeze, #has_parent?, #hash, #hier?, #host, #host=, intern, #join, #length, normalize_path, #normalized_authority, #normalized_fragment, #normalized_host, #normalized_password, #normalized_path, #normalized_port, #normalized_query, #normalized_scheme, #normalized_user, #normalized_userinfo, #object, #parent, parse, #parse, #password, #password=, #path, #path=, #pname, #port, #port=, #qname, #query, #query=, #query_values, #query_values=, #relative?, #relativize, #request_uri, #root, #root?, #scheme, #scheme=, #start_with?, #to_str, #to_uri, #uri?, #url?, #urn?, #user, #user=, #userinfo, #userinfo=, #validate!, #value
Methods included from Resource
Methods included from Term
#<=>, #==, #compatible?, #eql?, #term?, #to_base, #to_term
Methods included from RDF::Value
#anonymous?, #canonicalize, #canonicalize!, #constant?, #graph?, #inspect!, #invalid?, #iri?, #list?, #literal?, #node?, #resource?, #statement?, #term?, #to_nquads, #to_ntriples, #to_rdf, #to_term, #type_error, #uri?, #validate!, #variable?
Constructor Details
#URI(uri, options = {}) ⇒ Term #URI(options = {}) ⇒ Term
Returns a new instance of Term.
528 529 530 531 532 533 534 535 536 537 |
# File 'lib/rdf/vocabulary.rb', line 528 def initialize(*args, **) @attributes = .fetch(:attributes) if RUBY_ENGINE == "rbx" # FIXME: Somehow, this gets messed up in Rubinius args << super(*args) else super end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object (protected)
Implement accessor to symbol attributes
701 702 703 704 705 706 707 708 709 710 711 712 |
# 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.(v)} else super end end |
Instance Attribute Details
Instance Method Details
#class? ⇒ Boolean
Is this a class term?
566 567 568 |
# File 'lib/rdf/vocabulary.rb', line 566 def class? !!(self.type.to_s =~ /Class/) end |
#comment ⇒ String
‘rdfs:comment` accessor
496 |
# File 'lib/rdf/vocabulary.rb', line 496 attr_accessor :attributes |
#datatype? ⇒ Boolean
Is this a class term?
580 581 582 |
# File 'lib/rdf/vocabulary.rb', line 580 def datatype? !!(self.type.to_s =~ /Datatype/) end |
#domain ⇒ RDF::URI
‘rdfs:domain` accessor
496 |
# File 'lib/rdf/vocabulary.rb', line 496 attr_accessor :attributes |
#domain_includes ⇒ RDF::URI
Accessor for ‘schema:domainIncludes`
689 690 691 |
# File 'lib/rdf/vocabulary.rb', line 689 def domain_includes Array(@attributes[:domainIncludes]).map {|v| RDF::Vocabulary.(v)} end |
#domainIncludes ⇒ RDF::URI
‘schema:domainIncludes` accessor
496 |
# File 'lib/rdf/vocabulary.rb', line 496 attr_accessor :attributes |
#dup ⇒ RDF::URI
Returns a duplicate copy of ‘self`.
549 550 551 |
# File 'lib/rdf/vocabulary.rb', line 549 def dup self.class.new((@value || @object).dup, attributes: @attributes) end |
#each_statement {|| ... } ⇒ Object
598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 |
# 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.(value) when :subClassOf prop = RDFS.subClassOf value = RDF::Vocabulary.(value) when :subPropertyOf prop = RDFS.subPropertyOf value = RDF::Vocabulary.(value) when :domain prop = RDFS.domain value = RDF::Vocabulary.(value) when :range prop = RDFS.range value = RDF::Vocabulary.(value) when :inverseOf prop = RDF::URI("http://schema.org/inverseOf") value = RDF::Vocabulary.(value) when :domainIncludes prop = RDF::URI("http://schema.org/domainIncludes") value = RDF::Vocabulary.(value) when :rangeIncludes prop = RDF::URI("http://schema.org/rangeIncludes") value = RDF::Vocabulary.(value) when :label prop = RDF::RDFS.label when :comment prop = RDF::RDFS.comment else prop = RDF::Vocabulary.(prop.to_s) next unless prop v = value.to_s value = RDF::Vocabulary.(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 |
#enum_for(method = :each_statement, *args) ⇒ RDF::Enumerable::Enumerator Also known as: to_enum
Return an enumerator over Statement defined for this vocabulary.
665 666 667 668 669 670 671 |
# 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 |
#inspect ⇒ String
Returns a String representation of the URI object’s state.
678 679 680 |
# File 'lib/rdf/vocabulary.rb', line 678 def inspect sprintf("#<%s:%#0x URI:%s>", Term.to_s, self.object_id, self.to_s) end |
#inverseOf ⇒ RDF::URI
‘owl:inverseOf` accessor
496 |
# File 'lib/rdf/vocabulary.rb', line 496 attr_accessor :attributes |
#label ⇒ String
‘rdfs:label` accessor
496 |
# File 'lib/rdf/vocabulary.rb', line 496 attr_accessor :attributes |
#other? ⇒ Boolean
Is this neither a class, property or datatype term?
587 588 589 |
# File 'lib/rdf/vocabulary.rb', line 587 def other? !!(self.type.to_s !~ /(Class|Property|Datatype)/) end |
#property? ⇒ Boolean
Is this a class term?
573 574 575 |
# File 'lib/rdf/vocabulary.rb', line 573 def property? !!(self.type.to_s =~ /Property/) end |
#range ⇒ RDF::URI
‘rdfs:range` accessor
496 |
# File 'lib/rdf/vocabulary.rb', line 496 attr_accessor :attributes |
#range_includes ⇒ RDF::URI
Accessor for ‘schema:rangeIncludes`
695 696 697 |
# File 'lib/rdf/vocabulary.rb', line 695 def range_includes Array(@attributes[:rangeIncludes]).map {|v| RDF::Vocabulary.(v)} end |
#rangeIncludes ⇒ RDF::URI
‘schema:rangeIncludes` accoessor
496 |
# File 'lib/rdf/vocabulary.rb', line 496 attr_accessor :attributes |
#respond_to?(method, include_all = false) ⇒ Boolean
Implement accessor to symbol attributes
683 684 685 |
# File 'lib/rdf/vocabulary.rb', line 683 def respond_to?(method, include_all = false) @attributes.has_key?(method) || super end |
#subClassOf ⇒ RDF::URI
‘rdfs:subClassOf` accessor
496 |
# File 'lib/rdf/vocabulary.rb', line 496 attr_accessor :attributes |
#subPropertyOf ⇒ RDF::URI
‘rdfs:subPropertyOf` accessor
496 |
# File 'lib/rdf/vocabulary.rb', line 496 attr_accessor :attributes |
#type ⇒ RDF::URI
‘rdf:type` accessor
496 |
# File 'lib/rdf/vocabulary.rb', line 496 attr_accessor :attributes |
#valid? ⇒ Boolean
Determine if the URI is a valid according to RFC3987
558 559 560 561 |
# File 'lib/rdf/vocabulary.rb', line 558 def valid? # Validate relative to RFC3987 to_s.match(RDF::URI::IRI) || false end |
#vocab ⇒ RDF::Vocabulary
Vocabulary of this term.
543 |
# File 'lib/rdf/vocabulary.rb', line 543 def vocab; @attributes.fetch(:vocab); end |