rdf 3.2.2 → 3.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +37 -37
- data/VERSION +1 -1
- data/lib/rdf/mixin/countable.rb +5 -1
- data/lib/rdf/mixin/enumerable.rb +13 -1
- data/lib/rdf/mixin/queryable.rb +13 -1
- data/lib/rdf/model/list.rb +1 -1
- data/lib/rdf/model/literal/date.rb +27 -82
- data/lib/rdf/model/literal/datetime.rb +22 -122
- data/lib/rdf/model/literal/decimal.rb +12 -0
- data/lib/rdf/model/literal/double.rb +20 -0
- data/lib/rdf/model/literal/integer.rb +6 -0
- data/lib/rdf/model/literal/numeric.rb +154 -4
- data/lib/rdf/model/literal/temporal.rb +310 -0
- data/lib/rdf/model/literal/time.rb +26 -98
- data/lib/rdf/model/literal.rb +2 -1
- data/lib/rdf/model/statement.rb +3 -1
- data/lib/rdf/model/uri.rb +24 -3
- data/lib/rdf/ntriples/reader.rb +1 -1
- data/lib/rdf/vocab/owl.rb +450 -445
- data/lib/rdf/vocab/rdfs.rb +89 -88
- data/lib/rdf/vocab/writer.rb +84 -51
- data/lib/rdf/vocab/xsd.rb +249 -249
- data/lib/rdf/vocabulary.rb +142 -132
- data/lib/rdf.rb +0 -3
- metadata +11 -5
- data/lib/rdf/mixin/enumerator.rb +0 -40
data/lib/rdf/vocab/rdfs.rb
CHANGED
@@ -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, ...,
|
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)"
|
77
|
-
"http://www.w3.org/2000/01/rdf-schema#seeAlso": "http://www.w3.org/2000/01/rdf-schema-more"
|
78
|
-
type: "http://www.w3.org/2002/07/owl#Ontology"
|
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."
|
83
|
-
isDefinedBy: "http://www.w3.org/2000/01/rdf-schema#"
|
84
|
-
label: "Class"
|
85
|
-
subClassOf: "http://www.w3.org/2000/01/rdf-schema#Resource"
|
86
|
-
type: "http://www.w3.org/2000/01/rdf-schema#Class"
|
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."
|
89
|
-
isDefinedBy: "http://www.w3.org/2000/01/rdf-schema#"
|
90
|
-
label: "Container"
|
91
|
-
subClassOf: "http://www.w3.org/2000/01/rdf-schema#Resource"
|
92
|
-
type: "http://www.w3.org/2000/01/rdf-schema#Class"
|
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'."
|
95
|
-
isDefinedBy: "http://www.w3.org/2000/01/rdf-schema#"
|
96
|
-
label: "ContainerMembershipProperty"
|
97
|
-
subClassOf: "http://www.w3.org/1999/02/22-rdf-syntax-ns#Property"
|
98
|
-
type: "http://www.w3.org/2000/01/rdf-schema#Class"
|
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."
|
101
|
-
isDefinedBy: "http://www.w3.org/2000/01/rdf-schema#"
|
102
|
-
label: "Datatype"
|
103
|
-
subClassOf: "http://www.w3.org/2000/01/rdf-schema#Class"
|
104
|
-
type: "http://www.w3.org/2000/01/rdf-schema#Class"
|
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."
|
107
|
-
isDefinedBy: "http://www.w3.org/2000/01/rdf-schema#"
|
108
|
-
label: "Literal"
|
109
|
-
subClassOf: "http://www.w3.org/2000/01/rdf-schema#Resource"
|
110
|
-
type: "http://www.w3.org/2000/01/rdf-schema#Class"
|
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."
|
113
|
-
isDefinedBy: "http://www.w3.org/2000/01/rdf-schema#"
|
114
|
-
label: "Resource"
|
115
|
-
type: "http://www.w3.org/2000/01/rdf-schema#Class"
|
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."
|
120
|
-
domain: "http://www.w3.org/2000/01/rdf-schema#Resource"
|
121
|
-
isDefinedBy: "http://www.w3.org/2000/01/rdf-schema#"
|
122
|
-
label: "comment"
|
123
|
-
range: "http://www.w3.org/2000/01/rdf-schema#Literal"
|
124
|
-
type: "http://www.w3.org/1999/02/22-rdf-syntax-ns#Property"
|
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."
|
127
|
-
domain: "http://www.w3.org/1999/02/22-rdf-syntax-ns#Property"
|
128
|
-
isDefinedBy: "http://www.w3.org/2000/01/rdf-schema#"
|
129
|
-
label: "domain"
|
130
|
-
range: "http://www.w3.org/2000/01/rdf-schema#Class"
|
131
|
-
type: "http://www.w3.org/1999/02/22-rdf-syntax-ns#Property"
|
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."
|
134
|
-
domain: "http://www.w3.org/2000/01/rdf-schema#Resource"
|
135
|
-
isDefinedBy: "http://www.w3.org/2000/01/rdf-schema#"
|
136
|
-
label: "isDefinedBy"
|
137
|
-
range: "http://www.w3.org/2000/01/rdf-schema#Resource"
|
138
|
-
subPropertyOf: "http://www.w3.org/2000/01/rdf-schema#seeAlso"
|
139
|
-
type: "http://www.w3.org/1999/02/22-rdf-syntax-ns#Property"
|
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."
|
142
|
-
domain: "http://www.w3.org/2000/01/rdf-schema#Resource"
|
143
|
-
isDefinedBy: "http://www.w3.org/2000/01/rdf-schema#"
|
144
|
-
label: "label"
|
145
|
-
range: "http://www.w3.org/2000/01/rdf-schema#Literal"
|
146
|
-
type: "http://www.w3.org/1999/02/22-rdf-syntax-ns#Property"
|
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."
|
149
|
-
domain: "http://www.w3.org/2000/01/rdf-schema#Resource"
|
150
|
-
isDefinedBy: "http://www.w3.org/2000/01/rdf-schema#"
|
151
|
-
label: "member"
|
152
|
-
range: "http://www.w3.org/2000/01/rdf-schema#Resource"
|
153
|
-
type: "http://www.w3.org/1999/02/22-rdf-syntax-ns#Property"
|
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."
|
156
|
-
domain: "http://www.w3.org/1999/02/22-rdf-syntax-ns#Property"
|
157
|
-
isDefinedBy: "http://www.w3.org/2000/01/rdf-schema#"
|
158
|
-
label: "range"
|
159
|
-
range: "http://www.w3.org/2000/01/rdf-schema#Class"
|
160
|
-
type: "http://www.w3.org/1999/02/22-rdf-syntax-ns#Property"
|
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."
|
163
|
-
domain: "http://www.w3.org/2000/01/rdf-schema#Resource"
|
164
|
-
isDefinedBy: "http://www.w3.org/2000/01/rdf-schema#"
|
165
|
-
label: "seeAlso"
|
166
|
-
range: "http://www.w3.org/2000/01/rdf-schema#Resource"
|
167
|
-
type: "http://www.w3.org/1999/02/22-rdf-syntax-ns#Property"
|
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."
|
170
|
-
domain: "http://www.w3.org/2000/01/rdf-schema#Class"
|
171
|
-
isDefinedBy: "http://www.w3.org/2000/01/rdf-schema#"
|
172
|
-
label: "subClassOf"
|
173
|
-
range: "http://www.w3.org/2000/01/rdf-schema#Class"
|
174
|
-
type: "http://www.w3.org/1999/02/22-rdf-syntax-ns#Property"
|
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."
|
177
|
-
domain: "http://www.w3.org/1999/02/22-rdf-syntax-ns#Property"
|
178
|
-
isDefinedBy: "http://www.w3.org/2000/01/rdf-schema#"
|
179
|
-
label: "subPropertyOf"
|
180
|
-
range: "http://www.w3.org/1999/02/22-rdf-syntax-ns#Property"
|
181
|
-
type: "http://www.w3.org/1999/02/22-rdf-syntax-ns#Property"
|
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
|
data/lib/rdf/vocab/writer.rb
CHANGED
@@ -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(/^ /, '')
|
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
|
-
|
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?(
|
282
|
-
|
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}
|
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}
|
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}
|
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}
|
329
|
+
"#{u.to_s.inspect}"
|
297
330
|
end
|
298
331
|
end
|
299
332
|
"list(#{list_elements.join(', ')})"
|
300
333
|
else
|
301
|
-
"#{value.inspect}
|
334
|
+
"#{value.inspect}"
|
302
335
|
end
|
303
336
|
end
|
304
337
|
end
|