Skip to content

Commit 0b9904f

Browse files
committed
More corner-cases on Term propertie and some documentation.
1 parent 00429ae commit 0b9904f

3 files changed

Lines changed: 56 additions & 16 deletions

File tree

lib/rdf/vocab/xsd.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ module RDF
4747
# # @return [RDF::Vocabulary::Term]
4848
# attr_reader :Name
4949
#
50-
# # QName represents XML qualified names. The ·value space· of QName is the set of tuples {namespace name, local part}, where namespace name is an anyURI and local part is an NCName. The ·lexical space· of QName is the set of strings that ·match· the QName production of [Namespaces in XML].
50+
# # QName represents XML qualified names. The ·value space· of QName is the set of tuples `{namespace name, local part}`, where namespace name is an anyURI and local part is an NCName. The ·lexical space· of QName is the set of strings that ·match· the QName production of [Namespaces in XML].
5151
# # @return [RDF::Vocabulary::Term]
5252
# attr_reader :QName
5353
#
@@ -139,35 +139,35 @@ module RDF
139139
# # @return [RDF::Vocabulary::Term]
140140
# attr_reader :int
141141
#
142-
# # integer is ·derived· from decimal by fixing the value of ·fractionDigits· to be 0 and disallowing the trailing decimal point. This results in the standard mathematical concept of the integer numbers. The ·value space· of integer is the infinite set {...,-2,-1,0,1,2,...}. The ·base type· of integer is decimal.
142+
# # integer is ·derived· from decimal by fixing the value of ·fractionDigits· to be 0 and disallowing the trailing decimal point. This results in the standard mathematical concept of the integer numbers. The ·value space· of integer is the infinite set `{...,-2,-1,0,1,2,...}`. The ·base type· of integer is decimal.
143143
# # @return [RDF::Vocabulary::Term]
144144
# attr_reader :integer
145145
#
146-
# # language represents formal natural language identifiers, as defined by [BCP 47] (currently represented by [RFC 4646] and [RFC 4647]) or its successor(s). The ·value space· and ·lexical space· of language are the set of all strings that conform to the pattern [a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*
146+
# # language represents formal natural language identifiers, as defined by [BCP 47] (currently represented by [RFC 4646] and [RFC 4647]) or its successor(s). The ·value space· and ·lexical space· of language are the set of all strings that conform to the pattern `[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*`
147147
# # @return [RDF::Vocabulary::Term]
148148
# attr_reader :language
149149
#
150150
# # long is ·derived· from integer by setting the value of ·maxInclusive· to be 9223372036854775807 and ·minInclusive· to be -9223372036854775808. The ·base type· of long is integer.
151151
# # @return [RDF::Vocabulary::Term]
152152
# attr_reader :long
153153
#
154-
# # negativeInteger is ·derived· from nonPositiveInteger by setting the value of ·maxInclusive· to be -1. This results in the standard mathematical concept of the negative integers. The ·value space· of negativeInteger is the infinite set {...,-2,-1}. The ·base type· of negativeInteger is nonPositiveInteger.
154+
# # negativeInteger is ·derived· from nonPositiveInteger by setting the value of ·maxInclusive· to be -1. This results in the standard mathematical concept of the negative integers. The ·value space· of negativeInteger is the infinite set `{...,-2,-1}`. The ·base type· of negativeInteger is nonPositiveInteger.
155155
# # @return [RDF::Vocabulary::Term]
156156
# attr_reader :negativeInteger
157157
#
158-
# # nonNegativeInteger is ·derived· from integer by setting the value of ·minInclusive· to be 0. This results in the standard mathematical concept of the non-negative integers. The ·value space· of nonNegativeInteger is the infinite set {0,1,2,...}. The ·base type· of nonNegativeInteger is integer.
158+
# # nonNegativeInteger is ·derived· from integer by setting the value of ·minInclusive· to be 0. This results in the standard mathematical concept of the non-negative integers. The ·value space· of nonNegativeInteger is the infinite set `{0,1,2,...}`. The ·base type· of nonNegativeInteger is integer.
159159
# # @return [RDF::Vocabulary::Term]
160160
# attr_reader :nonNegativeInteger
161161
#
162-
# # nonPositiveInteger is ·derived· from integer by setting the value of ·maxInclusive· to be 0. This results in the standard mathematical concept of the non-positive integers. The ·value space· of nonPositiveInteger is the infinite set {...,-2,-1,0}. The ·base type· of nonPositiveInteger is integer.
162+
# # nonPositiveInteger is ·derived· from integer by setting the value of ·maxInclusive· to be 0. This results in the standard mathematical concept of the non-positive integers. The ·value space· of nonPositiveInteger is the infinite set `{...,-2,-1,0}`. The ·base type· of nonPositiveInteger is integer.
163163
# # @return [RDF::Vocabulary::Term]
164164
# attr_reader :nonPositiveInteger
165165
#
166166
# # normalizedString represents white space normalized strings. The ·value space· of normalizedString is the set of strings that do not contain the carriage return (#xD), line feed (#xA) nor tab (#x9) characters. The ·lexical space· of normalizedString is the set of strings that do not contain the carriage return (#xD), line feed (#xA) nor tab (#x9) characters. The ·base type· of normalizedString is string.
167167
# # @return [RDF::Vocabulary::Term]
168168
# attr_reader :normalizedString
169169
#
170-
# # positiveInteger is ·derived· from nonNegativeInteger by setting the value of ·minInclusive· to be 1. This results in the standard mathematical concept of the positive integer numbers. The ·value space· of positiveInteger is the infinite set {1,2,...}. The ·base type· of positiveInteger is nonNegativeInteger.
170+
# # positiveInteger is ·derived· from nonNegativeInteger by setting the value of ·minInclusive· to be 1. This results in the standard mathematical concept of the positive integer numbers. The ·value space· of positiveInteger is the infinite set `{1,2,...}`. The ·base type· of positiveInteger is nonNegativeInteger.
171171
# # @return [RDF::Vocabulary::Term]
172172
# attr_reader :positiveInteger
173173
#

lib/rdf/vocabulary.rb

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,9 @@ def self.camelize(str)
766766

767767
# A Vocabulary Term is a {RDF::Resource} that can also act as an {Enumerable} to generate the RDF definition of vocabulary terms as defined within the vocabulary definition.
768768
#
769-
# Terms include `attributes` where values a embedded resources, lists or other terms. This allows, for example, navigation of a concept heirarchy.
769+
# Terms include {Term#attributes} where values a embedded resources, lists or other terms. This allows, for example, navigation of a concept heirarchy.
770+
#
771+
# Term attributes can also be accessed using {Term#properties} where the attribute values are transformed into different types of {RDF::Value}. Properties can be indexed by key, where a key is defined (See {Term::ATTR_URIs}), absolute URI, or PName, where the prefix is associated with a loaded vocabulary.
770772
module Term
771773
include RDF::Resource
772774

@@ -1049,31 +1051,47 @@ def other?
10491051
# Enumerate attributes with values transformed into {RDF::Value} instances
10501052
# Uses an empty hash with a default_proc which looks up values in attributes.
10511053
#
1052-
# Properties are indexed by symbol. Symbols directly interpreted by a term are the accessors defined for the {RDF::Vocabulary::Term} class. Other keys are interpreted as absolute URIs or PNames for properties defined on this term.
1054+
# Properties are indexed by symbol. Symbols directly interpreted by a term are the accessors defined for the {RDF::Vocabulary::Term} class, also in {Term::ATTR_URIs}. Other keys are interpreted as absolute URIs or PNames for properties defined on this term.
10531055
#
10541056
# Symbols which are accessors may also be looked up by their associated URI.
10551057
#
10561058
# @note lookup by PName is DEPRECATED and will be removed in a future version.
10571059
#
1060+
# @example looking up term label
1061+
# RDF::RDFS.Literal.label #=> RDF::Literal("Literal")
1062+
# RDF::RDFS.Literal.properties[:label] #=> RDF::Literal("Literal")
1063+
# RDF::RDFS.Literal.properties[:"rdfs:label"] #=> RDF::Literal("Literal")
1064+
# RDF::RDFS.Literal.properties[RDF::RDFS.label] #=> RDF::Literal("Literal")
1065+
# RDF::RDFS.Literal.properties["http://www.w3.org/2000/01/rdf-schema#label"] #=> RDF::Literal("Literal")
1066+
# RDF::RDFS.Literal.properties[:"http://www.w3.org/2000/01/rdf-schema#label"] #=> RDF::Literal("Literal")
1067+
#
10581068
# @return [Hash{Symbol => Array<RDF::Value>}]
10591069
def properties
10601070
Hash.new do |hash, key|
10611071
case key
1062-
when RDF::URI, String then attribute_value(key.to_s.to_sym)
1072+
when RDF::URI
1073+
sym = URI_ATTRs.fetch(key, key.to_s.to_sym)
1074+
attribute_value(sym)
1075+
when String
1076+
sym = URI_ATTRs.fetch(RDF::URI(key), key.to_s.to_sym)
1077+
attribute_value(sym)
10631078
when Symbol
10641079
sym = case key.to_s
10651080
when /^https?:/
1066-
# FIXME: transitional code to look for pname attributes first
10671081
if attributes.key?(key)
10681082
key
1069-
elsif URI_ATTRs.key?(key)
1070-
URI_ATTRs[key]
10711083
else
1072-
RDF::URI(key).pname.to_sym
1084+
# Lookup by associated attribute, or pname
1085+
URI_ATTRs.fetch(RDF::URI(key.to_s), RDF::URI(key).pname.to_sym)
10731086
end
10741087
when /:/
1075-
# FIXME: transitional code to look for pname attributes first
1076-
attributes.key?(key) ? key : RDF::Vocabulary.expand_pname(key).to_s.to_sym
1088+
if attributes.key?(key)
1089+
key
1090+
else
1091+
uri = RDF::Vocabulary.expand_pname(key)
1092+
# Lookup by associated attribute or URI
1093+
URI_ATTRs.fetch(uri, uri.to_s.to_sym)
1094+
end
10771095
else
10781096
key
10791097
end

spec/vocabulary_spec.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,28 @@
584584
its(:vocab) {is_expected.to eql RDF::RDFS}
585585
end
586586

587+
context RDF::RDFS.Literal do
588+
subject {RDF::RDFS.Literal}
589+
specify {is_expected.not_to be_property}
590+
specify {is_expected.to be_class}
591+
592+
its(:label) {is_expected.to eq RDF::Literal("Literal")}
593+
594+
describe "#properties" do
595+
[
596+
:label,
597+
:'rdfs:label',
598+
"http://www.w3.org/2000/01/rdf-schema#label",
599+
:"http://www.w3.org/2000/01/rdf-schema#label",
600+
RDF::RDFS.label,
601+
].each do |key|
602+
it key.inspect do
603+
expect(subject.properties[key]).to eq RDF::Literal("Literal")
604+
end
605+
end
606+
end
607+
end
608+
587609
context RDF::RDFS.Class do
588610
subject {RDF::RDFS.Class}
589611
specify {is_expected.to respond_to(:vocab)}

0 commit comments

Comments
 (0)