rdf 3.2.3 → 3.2.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,6 +7,7 @@ module RDF
7
7
  # # Vocabulary for <http://www.w3.org/2000/01/rdf-schema#>
8
8
  # #
9
9
  # # The RDF Schema vocabulary (RDFS)
10
+ # # @see http://www.w3.org/2000/01/rdf-schema-more
10
11
  # class RDFS < RDF::StrictVocabulary
11
12
  # # The class of classes.
12
13
  # # @return [RDF::Vocabulary::Term]
@@ -16,7 +17,7 @@ module RDF
16
17
  # # @return [RDF::Vocabulary::Term]
17
18
  # attr_reader :Container
18
19
  #
19
- # # The class of container membership properties, rdf:_1, rdf:_2, ..., all of which are sub-properties of 'member'.
20
+ # # The class of container membership properties, rdf:_1, rdf:_2, ..., all of which are sub-properties of 'member'.
20
21
  # # @return [RDF::Vocabulary::Term]
21
22
  # attr_reader :ContainerMembershipProperty
22
23
  #
@@ -73,111 +74,111 @@ module RDF
73
74
 
74
75
  # Ontology definition
75
76
  ontology :"http://www.w3.org/2000/01/rdf-schema#",
76
- "http://purl.org/dc/elements/1.1/title": "The RDF Schema vocabulary (RDFS)".freeze,
77
- "http://www.w3.org/2000/01/rdf-schema#seeAlso": "http://www.w3.org/2000/01/rdf-schema-more".freeze,
78
- type: "http://www.w3.org/2002/07/owl#Ontology".freeze
77
+ "http://purl.org/dc/elements/1.1/title": "The RDF Schema vocabulary (RDFS)",
78
+ "http://www.w3.org/2000/01/rdf-schema#seeAlso": "http://www.w3.org/2000/01/rdf-schema-more",
79
+ type: "http://www.w3.org/2002/07/owl#Ontology"
79
80
 
80
81
  # Class definitions
81
82
  term :Class,
82
- comment: "The class of classes.".freeze,
83
- isDefinedBy: "http://www.w3.org/2000/01/rdf-schema#".freeze,
84
- label: "Class".freeze,
85
- subClassOf: "http://www.w3.org/2000/01/rdf-schema#Resource".freeze,
86
- type: "http://www.w3.org/2000/01/rdf-schema#Class".freeze
83
+ comment: "The class of classes.",
84
+ isDefinedBy: "http://www.w3.org/2000/01/rdf-schema#",
85
+ label: "Class",
86
+ subClassOf: "http://www.w3.org/2000/01/rdf-schema#Resource",
87
+ type: "http://www.w3.org/2000/01/rdf-schema#Class"
87
88
  term :Container,
88
- comment: "The class of RDF containers.".freeze,
89
- isDefinedBy: "http://www.w3.org/2000/01/rdf-schema#".freeze,
90
- label: "Container".freeze,
91
- subClassOf: "http://www.w3.org/2000/01/rdf-schema#Resource".freeze,
92
- type: "http://www.w3.org/2000/01/rdf-schema#Class".freeze
89
+ comment: "The class of RDF containers.",
90
+ isDefinedBy: "http://www.w3.org/2000/01/rdf-schema#",
91
+ label: "Container",
92
+ subClassOf: "http://www.w3.org/2000/01/rdf-schema#Resource",
93
+ type: "http://www.w3.org/2000/01/rdf-schema#Class"
93
94
  term :ContainerMembershipProperty,
94
- comment: "The class of container membership properties, rdf:_1, rdf:_2, ...,\n all of which are sub-properties of 'member'.".freeze,
95
- isDefinedBy: "http://www.w3.org/2000/01/rdf-schema#".freeze,
96
- label: "ContainerMembershipProperty".freeze,
97
- subClassOf: "http://www.w3.org/1999/02/22-rdf-syntax-ns#Property".freeze,
98
- type: "http://www.w3.org/2000/01/rdf-schema#Class".freeze
95
+ comment: "The class of container membership properties, rdf:_1, rdf:_2, ...,\n all of which are sub-properties of 'member'.",
96
+ isDefinedBy: "http://www.w3.org/2000/01/rdf-schema#",
97
+ label: "ContainerMembershipProperty",
98
+ subClassOf: "http://www.w3.org/1999/02/22-rdf-syntax-ns#Property",
99
+ type: "http://www.w3.org/2000/01/rdf-schema#Class"
99
100
  term :Datatype,
100
- comment: "The class of RDF datatypes.".freeze,
101
- isDefinedBy: "http://www.w3.org/2000/01/rdf-schema#".freeze,
102
- label: "Datatype".freeze,
103
- subClassOf: "http://www.w3.org/2000/01/rdf-schema#Class".freeze,
104
- type: "http://www.w3.org/2000/01/rdf-schema#Class".freeze
101
+ comment: "The class of RDF datatypes.",
102
+ isDefinedBy: "http://www.w3.org/2000/01/rdf-schema#",
103
+ label: "Datatype",
104
+ subClassOf: "http://www.w3.org/2000/01/rdf-schema#Class",
105
+ type: "http://www.w3.org/2000/01/rdf-schema#Class"
105
106
  term :Literal,
106
- comment: "The class of literal values, eg. textual strings and integers.".freeze,
107
- isDefinedBy: "http://www.w3.org/2000/01/rdf-schema#".freeze,
108
- label: "Literal".freeze,
109
- subClassOf: "http://www.w3.org/2000/01/rdf-schema#Resource".freeze,
110
- type: "http://www.w3.org/2000/01/rdf-schema#Class".freeze
107
+ comment: "The class of literal values, eg. textual strings and integers.",
108
+ isDefinedBy: "http://www.w3.org/2000/01/rdf-schema#",
109
+ label: "Literal",
110
+ subClassOf: "http://www.w3.org/2000/01/rdf-schema#Resource",
111
+ type: "http://www.w3.org/2000/01/rdf-schema#Class"
111
112
  term :Resource,
112
- comment: "The class resource, everything.".freeze,
113
- isDefinedBy: "http://www.w3.org/2000/01/rdf-schema#".freeze,
114
- label: "Resource".freeze,
115
- type: "http://www.w3.org/2000/01/rdf-schema#Class".freeze
113
+ comment: "The class resource, everything.",
114
+ isDefinedBy: "http://www.w3.org/2000/01/rdf-schema#",
115
+ label: "Resource",
116
+ type: "http://www.w3.org/2000/01/rdf-schema#Class"
116
117
 
117
118
  # Property definitions
118
119
  property :comment,
119
- comment: "A description of the subject resource.".freeze,
120
- domain: "http://www.w3.org/2000/01/rdf-schema#Resource".freeze,
121
- isDefinedBy: "http://www.w3.org/2000/01/rdf-schema#".freeze,
122
- label: "comment".freeze,
123
- range: "http://www.w3.org/2000/01/rdf-schema#Literal".freeze,
124
- type: "http://www.w3.org/1999/02/22-rdf-syntax-ns#Property".freeze
120
+ comment: "A description of the subject resource.",
121
+ domain: "http://www.w3.org/2000/01/rdf-schema#Resource",
122
+ isDefinedBy: "http://www.w3.org/2000/01/rdf-schema#",
123
+ label: "comment",
124
+ range: "http://www.w3.org/2000/01/rdf-schema#Literal",
125
+ type: "http://www.w3.org/1999/02/22-rdf-syntax-ns#Property"
125
126
  property :domain,
126
- comment: "A domain of the subject property.".freeze,
127
- domain: "http://www.w3.org/1999/02/22-rdf-syntax-ns#Property".freeze,
128
- isDefinedBy: "http://www.w3.org/2000/01/rdf-schema#".freeze,
129
- label: "domain".freeze,
130
- range: "http://www.w3.org/2000/01/rdf-schema#Class".freeze,
131
- type: "http://www.w3.org/1999/02/22-rdf-syntax-ns#Property".freeze
127
+ comment: "A domain of the subject property.",
128
+ domain: "http://www.w3.org/1999/02/22-rdf-syntax-ns#Property",
129
+ isDefinedBy: "http://www.w3.org/2000/01/rdf-schema#",
130
+ label: "domain",
131
+ range: "http://www.w3.org/2000/01/rdf-schema#Class",
132
+ type: "http://www.w3.org/1999/02/22-rdf-syntax-ns#Property"
132
133
  property :isDefinedBy,
133
- comment: "The defininition of the subject resource.".freeze,
134
- domain: "http://www.w3.org/2000/01/rdf-schema#Resource".freeze,
135
- isDefinedBy: "http://www.w3.org/2000/01/rdf-schema#".freeze,
136
- label: "isDefinedBy".freeze,
137
- range: "http://www.w3.org/2000/01/rdf-schema#Resource".freeze,
138
- subPropertyOf: "http://www.w3.org/2000/01/rdf-schema#seeAlso".freeze,
139
- type: "http://www.w3.org/1999/02/22-rdf-syntax-ns#Property".freeze
134
+ comment: "The defininition of the subject resource.",
135
+ domain: "http://www.w3.org/2000/01/rdf-schema#Resource",
136
+ isDefinedBy: "http://www.w3.org/2000/01/rdf-schema#",
137
+ label: "isDefinedBy",
138
+ range: "http://www.w3.org/2000/01/rdf-schema#Resource",
139
+ subPropertyOf: "http://www.w3.org/2000/01/rdf-schema#seeAlso",
140
+ type: "http://www.w3.org/1999/02/22-rdf-syntax-ns#Property"
140
141
  property :label,
141
- comment: "A human-readable name for the subject.".freeze,
142
- domain: "http://www.w3.org/2000/01/rdf-schema#Resource".freeze,
143
- isDefinedBy: "http://www.w3.org/2000/01/rdf-schema#".freeze,
144
- label: "label".freeze,
145
- range: "http://www.w3.org/2000/01/rdf-schema#Literal".freeze,
146
- type: "http://www.w3.org/1999/02/22-rdf-syntax-ns#Property".freeze
142
+ comment: "A human-readable name for the subject.",
143
+ domain: "http://www.w3.org/2000/01/rdf-schema#Resource",
144
+ isDefinedBy: "http://www.w3.org/2000/01/rdf-schema#",
145
+ label: "label",
146
+ range: "http://www.w3.org/2000/01/rdf-schema#Literal",
147
+ type: "http://www.w3.org/1999/02/22-rdf-syntax-ns#Property"
147
148
  property :member,
148
- comment: "A member of the subject resource.".freeze,
149
- domain: "http://www.w3.org/2000/01/rdf-schema#Resource".freeze,
150
- isDefinedBy: "http://www.w3.org/2000/01/rdf-schema#".freeze,
151
- label: "member".freeze,
152
- range: "http://www.w3.org/2000/01/rdf-schema#Resource".freeze,
153
- type: "http://www.w3.org/1999/02/22-rdf-syntax-ns#Property".freeze
149
+ comment: "A member of the subject resource.",
150
+ domain: "http://www.w3.org/2000/01/rdf-schema#Resource",
151
+ isDefinedBy: "http://www.w3.org/2000/01/rdf-schema#",
152
+ label: "member",
153
+ range: "http://www.w3.org/2000/01/rdf-schema#Resource",
154
+ type: "http://www.w3.org/1999/02/22-rdf-syntax-ns#Property"
154
155
  property :range,
155
- comment: "A range of the subject property.".freeze,
156
- domain: "http://www.w3.org/1999/02/22-rdf-syntax-ns#Property".freeze,
157
- isDefinedBy: "http://www.w3.org/2000/01/rdf-schema#".freeze,
158
- label: "range".freeze,
159
- range: "http://www.w3.org/2000/01/rdf-schema#Class".freeze,
160
- type: "http://www.w3.org/1999/02/22-rdf-syntax-ns#Property".freeze
156
+ comment: "A range of the subject property.",
157
+ domain: "http://www.w3.org/1999/02/22-rdf-syntax-ns#Property",
158
+ isDefinedBy: "http://www.w3.org/2000/01/rdf-schema#",
159
+ label: "range",
160
+ range: "http://www.w3.org/2000/01/rdf-schema#Class",
161
+ type: "http://www.w3.org/1999/02/22-rdf-syntax-ns#Property"
161
162
  property :seeAlso,
162
- comment: "Further information about the subject resource.".freeze,
163
- domain: "http://www.w3.org/2000/01/rdf-schema#Resource".freeze,
164
- isDefinedBy: "http://www.w3.org/2000/01/rdf-schema#".freeze,
165
- label: "seeAlso".freeze,
166
- range: "http://www.w3.org/2000/01/rdf-schema#Resource".freeze,
167
- type: "http://www.w3.org/1999/02/22-rdf-syntax-ns#Property".freeze
163
+ comment: "Further information about the subject resource.",
164
+ domain: "http://www.w3.org/2000/01/rdf-schema#Resource",
165
+ isDefinedBy: "http://www.w3.org/2000/01/rdf-schema#",
166
+ label: "seeAlso",
167
+ range: "http://www.w3.org/2000/01/rdf-schema#Resource",
168
+ type: "http://www.w3.org/1999/02/22-rdf-syntax-ns#Property"
168
169
  property :subClassOf,
169
- comment: "The subject is a subclass of a class.".freeze,
170
- domain: "http://www.w3.org/2000/01/rdf-schema#Class".freeze,
171
- isDefinedBy: "http://www.w3.org/2000/01/rdf-schema#".freeze,
172
- label: "subClassOf".freeze,
173
- range: "http://www.w3.org/2000/01/rdf-schema#Class".freeze,
174
- type: "http://www.w3.org/1999/02/22-rdf-syntax-ns#Property".freeze
170
+ comment: "The subject is a subclass of a class.",
171
+ domain: "http://www.w3.org/2000/01/rdf-schema#Class",
172
+ isDefinedBy: "http://www.w3.org/2000/01/rdf-schema#",
173
+ label: "subClassOf",
174
+ range: "http://www.w3.org/2000/01/rdf-schema#Class",
175
+ type: "http://www.w3.org/1999/02/22-rdf-syntax-ns#Property"
175
176
  property :subPropertyOf,
176
- comment: "The subject is a subproperty of a property.".freeze,
177
- domain: "http://www.w3.org/1999/02/22-rdf-syntax-ns#Property".freeze,
178
- isDefinedBy: "http://www.w3.org/2000/01/rdf-schema#".freeze,
179
- label: "subPropertyOf".freeze,
180
- range: "http://www.w3.org/1999/02/22-rdf-syntax-ns#Property".freeze,
181
- type: "http://www.w3.org/1999/02/22-rdf-syntax-ns#Property".freeze
177
+ comment: "The subject is a subproperty of a property.",
178
+ domain: "http://www.w3.org/1999/02/22-rdf-syntax-ns#Property",
179
+ isDefinedBy: "http://www.w3.org/2000/01/rdf-schema#",
180
+ label: "subPropertyOf",
181
+ range: "http://www.w3.org/1999/02/22-rdf-syntax-ns#Property",
182
+ type: "http://www.w3.org/1999/02/22-rdf-syntax-ns#Property"
182
183
  end
183
184
  end
@@ -3,53 +3,65 @@ require 'rdf/vocabulary'
3
3
  require 'cgi'
4
4
 
5
5
  module RDF
6
- ##
7
- # Vocabulary format specification. This can be used to generate a Ruby class definition from a loaded vocabulary.
8
- #
9
- # Definitions can include recursive term definitions, when the value of a property is a blank-node term. They can also include list definitions, to provide a reasonable way to represent `owl:unionOf`-type relationships.
10
- #
11
- # @example a simple term definition
12
- # property :comment,
13
- # comment: %(A description of the subject resource.).freeze,
14
- # domain: "rdfs:Resource".freeze,
15
- # label: "comment".freeze,
16
- # range: "rdfs:Literal".freeze,
17
- # isDefinedBy: %(rdfs:).freeze,
18
- # type: "rdf:Property".freeze
19
- #
20
- # @example an embedded skos:Concept
21
- # term :ad,
22
- # exactMatch: [term(
23
- # type: "skos:Concept".freeze,
24
- # inScheme: "country:iso3166-1-alpha-2".freeze,
25
- # notation: %(ad).freeze
26
- # ), term(
27
- # type: "skos:Concept".freeze,
28
- # inScheme: "country:iso3166-1-alpha-3".freeze,
29
- # notation: %(and).freeze
30
- # )],
31
- # "foaf:name": "Andorra".freeze,
32
- # isDefinedBy: "country:".freeze,
33
- # type: "http://sweet.jpl.nasa.gov/2.3/humanJurisdiction.owl#Country".freeze
34
- #
35
- # @example owl:unionOf
36
- # property :duration,
37
- # comment: %(The duration of a track or a signal in ms).freeze,
38
- # domain: term(
39
- # "owl:unionOf": list("mo:Track".freeze, "mo:Signal".freeze),
40
- # type: "owl:Class".freeze
41
- # ),
42
- # isDefinedBy: "mo:".freeze,
43
- # "mo:level": "1".freeze,
44
- # range: "xsd:float".freeze,
45
- # type: "owl:DatatypeProperty".freeze,
46
- # "vs:term_status": "testing".freeze
47
6
  class Vocabulary
48
7
  class Format < RDF::Format
49
8
  content_encoding 'utf-8'
50
9
  writer { RDF::Vocabulary::Writer }
51
10
  end
52
11
 
12
+ ##
13
+ # Vocabulary format specification. This can be used to generate a Ruby class definition from a loaded vocabulary.
14
+ #
15
+ # Definitions can include recursive term definitions, when the value of a property is a blank-node term. They can also include list definitions, to provide a reasonable way to represent `owl:unionOf`-type relationships.
16
+ #
17
+ # @example a simple term definition
18
+ # property :comment,
19
+ # comment: %(A description of the subject resource.),
20
+ # domain: "rdfs:Resource",
21
+ # label: "comment",
22
+ # range: "rdfs:Literal",
23
+ # isDefinedBy: %(rdfs:),
24
+ # type: "rdf:Property"
25
+ #
26
+ # @example an embedded skos:Concept
27
+ # term :ad,
28
+ # exactMatch: [term(
29
+ # type: "skos:Concept",
30
+ # inScheme: "country:iso3166-1-alpha-2",
31
+ # notation: %(ad)
32
+ # ), term(
33
+ # type: "skos:Concept",
34
+ # inScheme: "country:iso3166-1-alpha-3",
35
+ # notation: %(and)
36
+ # )],
37
+ # "foaf:name": "Andorra",
38
+ # isDefinedBy: "country:",
39
+ # type: "http://sweet.jpl.nasa.gov/2.3/humanJurisdiction.owl#Country"
40
+ #
41
+ # @example owl:unionOf
42
+ # property :duration,
43
+ # comment: %(The duration of a track or a signal in ms),
44
+ # domain: term(
45
+ # "owl:unionOf": list("mo:Track", "mo:Signal"),
46
+ # type: "owl:Class"
47
+ # ),
48
+ # isDefinedBy: "mo:",
49
+ # "mo:level": "1",
50
+ # range: "xsd:float",
51
+ # type: "owl:DatatypeProperty",
52
+ # "vs:term_status": "testing"
53
+ #
54
+ # @example term definition with language-tagged strings
55
+ # property :actor,
56
+ # comment: {en: "Subproperty of as:attributedTo that identifies the primary actor"},
57
+ # domain: "https://www.w3.org/ns/activitystreams#Activity",
58
+ # label: {en: "actor"},
59
+ # range: term(
60
+ # type: "http://www.w3.org/2002/07/owl#Class",
61
+ # unionOf: list("https://www.w3.org/ns/activitystreams#Object", "https://www.w3.org/ns/activitystreams#Link")
62
+ # ),
63
+ # subPropertyOf: "https://www.w3.org/ns/activitystreams#attributedTo",
64
+ # type: "http://www.w3.org/2002/07/owl#ObjectProperty"
53
65
  class Writer < RDF::Writer
54
66
  include RDF::Util::Logger
55
67
  format RDF::Vocabulary::Format
@@ -152,10 +164,16 @@ module RDF
152
164
  module #{module_name}
153
165
  ).gsub(/^ /, '')
154
166
 
167
+ if @options[:noDoc]
168
+ @output.print %( # Vocabulary for <#{base_uri}>
169
+ # @!visibility private
170
+ ).gsub(/^ /, '')
171
+ else
155
172
  @output.print %( # @!parse
156
173
  # # Vocabulary for <#{base_uri}>
157
174
  # #
158
- ).gsub(/^ /, '') unless @options[:noDoc]
175
+ ).gsub(/^ /, '')
176
+ end
159
177
 
160
178
  if vocab.ontology && !@options[:noDoc]
161
179
  ont_doc = []
@@ -266,9 +284,17 @@ module RDF
266
284
  attributes.keys.sort_by(&:to_s).map(&:to_sym).each do |key|
267
285
  value = Array(attributes[key])
268
286
  component = key.inspect.start_with?(':"') ? "#{key.to_s.inspect}: " : "#{key}: "
269
- value = value.first if value.length == 1
287
+ value = value.first if value.length == 1 && value.none? {|v| v.is_a?(RDF::Literal) && v.language?}
270
288
  component << if value.is_a?(Array)
271
- '[' + value.map {|v| serialize_value(v, key, indent: " ")}.sort.join(", ") + "]"
289
+ # Represent language-tagged literals as a hash
290
+ lang_vals, vals = value.partition {|v| v.literal? && v.language?}
291
+ hash_val = lang_vals.inject({}) {|memo, obj| memo.merge(obj.language => obj.to_s)}
292
+ vals << hash_val unless hash_val.empty?
293
+ if vals.length > 1
294
+ '[' + vals.map {|v| serialize_value(v, key, indent: " ")}.sort.join(", ") + "]"
295
+ else
296
+ serialize_value(vals.first, key, indent: " ")
297
+ end
272
298
  else
273
299
  serialize_value(value, key, indent: " ")
274
300
  end
@@ -278,27 +304,34 @@ module RDF
278
304
  end
279
305
 
280
306
  def serialize_value(value, key, indent: "")
281
- if value.is_a?(Literal) && %w(: comment definition notation note editorialNote).include?(key.to_s)
282
- "#{value.to_s.inspect}.freeze"
307
+ if value.is_a?(Hash)
308
+ # Favor English
309
+ keys = value.keys
310
+ keys = keys.include?(:en) ? (keys - [:en]).sort.unshift(:en) : keys.sort
311
+ '{' + keys.map do |k|
312
+ "#{k.inspect[1..-1]}: #{value[k].inspect}"
313
+ end.join(', ') + '}'
314
+ elsif value.is_a?(Literal) && %w(: comment definition notation note editorialNote).include?(key.to_s)
315
+ "#{value.to_s.inspect}"
283
316
  elsif value.is_a?(RDF::URI)
284
- "#{value.to_s.inspect}.freeze"
317
+ "#{value.to_s.inspect}"
285
318
  elsif value.is_a?(RDF::Vocabulary::Term)
286
319
  value.to_ruby(indent: indent + " ")
287
320
  elsif value.is_a?(RDF::Term)
288
- "#{value.to_s.inspect}.freeze"
321
+ "#{value.to_s.inspect}"
289
322
  elsif value.is_a?(RDF::List)
290
323
  list_elements = value.map do |u|
291
324
  if u.uri?
292
- "#{u.to_s.inspect}.freeze"
325
+ "#{u.to_s.inspect}"
293
326
  elsif u.respond_to?(:to_ruby)
294
327
  u.to_ruby(indent: indent + " ")
295
328
  else
296
- "#{u.to_s.inspect}.freeze"
329
+ "#{u.to_s.inspect}"
297
330
  end
298
331
  end
299
332
  "list(#{list_elements.join(', ')})"
300
333
  else
301
- "#{value.inspect}.freeze"
334
+ "#{value.inspect}"
302
335
  end
303
336
  end
304
337
  end