rdf-vocab 3.1.4 → 3.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/README.md +69 -45
  4. data/VERSION +1 -1
  5. data/lib/rdf/vocab.rb +14 -28
  6. data/lib/rdf/vocab/acl.rb +84 -1
  7. data/lib/rdf/vocab/as.rb +466 -1
  8. data/lib/rdf/vocab/bf2.rb +1317 -1
  9. data/lib/rdf/vocab/bibframe.rb +1 -2
  10. data/lib/rdf/vocab/bibo.rb +496 -1
  11. data/lib/rdf/vocab/cc.rb +107 -1
  12. data/lib/rdf/vocab/cert.rb +68 -1
  13. data/lib/rdf/vocab/cnt.rb +79 -1
  14. data/lib/rdf/vocab/crm.rb +1303 -1
  15. data/lib/rdf/vocab/datacite.rb +1 -1
  16. data/lib/rdf/vocab/dbo.rb +10463 -1
  17. data/lib/rdf/vocab/dc.rb +1 -1
  18. data/lib/rdf/vocab/dc11.rb +63 -1
  19. data/lib/rdf/vocab/dcat.rb +152 -4
  20. data/lib/rdf/vocab/dcmitype.rb +1 -1
  21. data/lib/rdf/vocab/disco.rb +228 -1
  22. data/lib/rdf/vocab/doap.rb +175 -1
  23. data/lib/rdf/vocab/dwc.rb +753 -1
  24. data/lib/rdf/vocab/earl.rb +135 -1
  25. data/lib/rdf/vocab/ebucore.rb +7335 -1974
  26. data/lib/rdf/vocab/edm.rb +150 -1
  27. data/lib/rdf/vocab/exif.rb +650 -1
  28. data/lib/rdf/vocab/extensions.rb +253 -203
  29. data/lib/rdf/vocab/fcrepo4.rb +377 -1
  30. data/lib/rdf/vocab/foaf.rb +305 -1
  31. data/lib/rdf/vocab/geo.rb +39 -1
  32. data/lib/rdf/vocab/geojson.rb +66 -1
  33. data/lib/rdf/vocab/geonames.rb +166 -1
  34. data/lib/rdf/vocab/gr.rb +684 -1
  35. data/lib/rdf/vocab/gs1.rb +1597 -1
  36. data/lib/rdf/vocab/ht.rb +164 -1
  37. data/lib/rdf/vocab/hydra.rb +236 -2
  38. data/lib/rdf/vocab/iana.rb +230 -1
  39. data/lib/rdf/vocab/ical.rb +462 -1
  40. data/lib/rdf/vocab/identifiers.rb +462 -1
  41. data/lib/rdf/vocab/iiif.rb +136 -1
  42. data/lib/rdf/vocab/jsonld.rb +135 -1
  43. data/lib/rdf/vocab/ldp.rb +130 -1
  44. data/lib/rdf/vocab/lrmi.rb +1 -1
  45. data/lib/rdf/vocab/ma.rb +381 -1
  46. data/lib/rdf/vocab/mads.rb +600 -22
  47. data/lib/rdf/vocab/{marc_relators.rb → marcrelators.rb} +809 -1
  48. data/lib/rdf/vocab/mo.rb +919 -1
  49. data/lib/rdf/vocab/mods.rb +516 -1
  50. data/lib/rdf/vocab/nfo.rb +1 -1
  51. data/lib/rdf/vocab/oa.rb +275 -1
  52. data/lib/rdf/vocab/og.rb +78 -1
  53. data/lib/rdf/vocab/ogc.rb +34 -1
  54. data/lib/rdf/vocab/ore.rb +56 -1
  55. data/lib/rdf/vocab/org.rb +189 -1
  56. data/lib/rdf/vocab/pcdm.rb +47 -1
  57. data/lib/rdf/vocab/pplan.rb +64 -1
  58. data/lib/rdf/vocab/premis.rb +1266 -779
  59. data/lib/rdf/vocab/{premis_event_type.rb → premiseventtype.rb} +155 -1
  60. data/lib/rdf/vocab/prov.rb +619 -1
  61. data/lib/rdf/vocab/ptr.rb +138 -1
  62. data/lib/rdf/vocab/rightsstatements.rb +5 -1
  63. data/lib/rdf/vocab/rsa.rb +30 -1
  64. data/lib/rdf/vocab/rss.rb +1 -1
  65. data/lib/rdf/vocab/schema.rb +10032 -12
  66. data/lib/rdf/vocab/sd.rb +372 -0
  67. data/lib/rdf/vocab/sh.rb +736 -1
  68. data/lib/rdf/vocab/sioc.rb +401 -1
  69. data/lib/rdf/vocab/{sioc_services.rb → siocservices.rb} +38 -1
  70. data/lib/rdf/vocab/{sioct.rb → sioctypes.rb} +158 -1
  71. data/lib/rdf/vocab/skos.rb +119 -1
  72. data/lib/rdf/vocab/skosxl.rb +30 -1
  73. data/lib/rdf/vocab/v.rb +291 -1
  74. data/lib/rdf/vocab/vcard.rb +508 -1
  75. data/lib/rdf/vocab/vmd.rb +291 -1
  76. data/lib/rdf/vocab/void.rb +121 -1
  77. data/lib/rdf/vocab/vs.rb +19 -1
  78. data/lib/rdf/vocab/wdrs.rb +90 -1
  79. data/lib/rdf/vocab/wot.rb +78 -1
  80. data/lib/rdf/vocab/xhtml.rb +2 -1
  81. data/lib/rdf/vocab/xhv.rb +338 -1
  82. data/lib/rdf/vocab/xkos.rb +150 -1
  83. data/spec/extensions_spec.rb +68 -0
  84. data/spec/vocab_spec.rb +10 -0
  85. metadata +15 -8
@@ -21,7 +21,7 @@ module RDF
21
21
  # Ruby's autoloading facility, meaning that `@@subclasses` will be
22
22
  # empty until each subclass has been touched or require'd.
23
23
  RDF::Vocab::VOCABS.each do |n, params|
24
- clsname = params.fetch(:class_name, n.to_s.upcase).to_sym
24
+ clsname = params[:class_name].to_sym
25
25
  RDF::Vocab.const_get(clsname) # Forces class to load
26
26
  end unless @classes_loaded
27
27
  @classes_loaded = true
@@ -29,236 +29,286 @@ module RDF
29
29
  _orig_each(&block)
30
30
  end
31
31
 
32
- begin
32
+ ##
33
+ # A hash of all vocabularies by prefix showing relevant URI and associated vocabulary Class Name
34
+ # @return [Hash{Symbol => Hash{Symbol => String}}]
35
+ #alias_method :_orig_vocab_map, :vocab_map
36
+ def vocab_map
37
+ @vocab_map ||= RDF::VOCABS.merge(RDF::Vocab::VOCABS)
38
+ end
39
+
40
+ ##
41
+ # Return the vocabulary based on it's class_name symbol
42
+ #
43
+ # @param [Symbol] sym
44
+ # @return [RDF::Vocabulary]
45
+ alias_method :_orig_from_sym, :from_sym
46
+ def from_sym(sym)
47
+ RDF::Vocab.const_defined?(sym.to_sym) ? RDF::Vocab.const_get(sym.to_sym) : _orig_from_sym(sym)
48
+ end
49
+
50
+ ##
51
+ # Limits iteration over vocabularies to just those selected
52
+ #
53
+ # @example limit to set of vocabularies by symbol
54
+ # RDF::Vocabulary.limit_vocabs(:rdf, :rdfs, :schema)
55
+ # RDF::Vocabulary.find_term('http://schema.org/CreativeWork').pname
56
+ # # => 'schema:CreativeWork'
57
+ #
58
+ # @example limit to set of vocabularies by class name
59
+ # RDF::Vocabulary.limit_vocabs(RDF::RDFV, RDF::RDFS, RDF::Vocab::SCHEMA)
60
+ # RDF::Vocabulary.find_term('http://schema.org/CreativeWork').pname
61
+ # # => 'schema:CreativeWork'
62
+ #
63
+ # @param [Array<symbol, RDF::Vocabulary>] vocabs
64
+ # A list of vocabularies (symbols or classes) which may
65
+ # be returned by {Vocabulary.each}. Also limits
66
+ # vocabularies that will be inspeced for other methods.
67
+ # Set to nil, or an empty array to reset.
68
+ # @return [Array<RDF::Vocabulary>]
69
+ def limit_vocabs(*vocabs)
70
+ @vocabs = if Array(vocabs).empty?
71
+ nil
72
+ else
73
+ @classes_loaded = true
74
+ vocabs.map do |vocab|
75
+ if vocab == :rdf || vocab == :rdfv
76
+ RDF::RDFV
77
+ elsif vocab.is_a?(Symbol) && RDF::Vocab::VOCABS.key?(vocab)
78
+ RDF::Vocab.const_get(RDF::Vocab::VOCABS[vocab][:class_name].to_sym)
79
+ else
80
+ vocab
81
+ end
82
+ end.compact
83
+ end
84
+ end
85
+
86
+ ##
87
+ # Generate Turtle representation, specific to vocabularies
88
+ #
89
+ # @param [RDF::Queryable] :graph Optional graph, otherwise uses statements from vocabulary.
90
+ # @param [Hash{#to_sym => String}] Prefixes to add to output
91
+ # @return [String]
92
+ def to_ttl(graph: nil, prefixes: nil)
33
93
  require 'rdf/turtle'
34
- ##
35
- # Generate Turtle representation, specific to vocabularies
36
- #
37
- # @param [RDF::Queryable] :graph Optional graph, otherwise uses statements from vocabulary.
38
- # @param [Hash{#to_sym => String}] Prefixes to add to output
39
- # @return [String]
40
- def to_ttl(graph: nil, prefixes: nil)
41
- output = []
42
-
43
- # Find namespaces used in the vocabulary
44
- graph = RDF::Graph.new {|g| each_statement {|s| g << s}} if graph.nil? || graph.empty?
45
-
46
- prefixes = vocab_prefixes(graph).merge(prefixes || {})
47
- pfx_width = prefixes.keys.map(&:to_s).map(&:length).max
48
- prefixes.each do |pfx, uri|
49
- output << "@prefix %*s: <%s> .\n" % [pfx_width, pfx, uri]
50
- end
94
+ output = []
51
95
 
52
- # Determine the category for each subject in the vocabulary graph
53
- cats = subject_categories(graph)
54
-
55
- writer = RDF::Turtle::Writer.new(StringIO.new, prefixes: prefixes)
56
-
57
- {
58
- ont: {
59
- heading: "# #{__name__.split('::').last} Vocabulary definition\n"
60
- },
61
- classes: {
62
- heading: "# Class definitions\n"
63
- },
64
- properties: {
65
- heading: "# Property definitions\n"
66
- },
67
- datatypes: {
68
- heading: "# Datatype definitions\n"
69
- },
70
- other: {
71
- heading: "# Other definitions\n"
72
- }
73
- }.each do |key, hash|
74
- next unless cats[key]
75
-
76
- output << "\n\n#{hash[:heading]}"
77
-
78
- cats[key].each do |subject|
79
- po = {}
80
-
81
- # Group predicates with their values
82
- graph.query(subject: subject) do |statement|
83
- # Sanity check this, as these are set to an empty string if not defined.
84
- next if [RDF::RDFS.label, RDF::RDFS.comment].include?(statement.predicate) && statement.object.to_s.empty?
85
- po[statement.predicate] ||= []
86
- po[statement.predicate] << statement.object
87
- end
96
+ # Find namespaces used in the vocabulary
97
+ graph = RDF::Graph.new {|g| each_statement {|s| g << s}} if graph.nil? || graph.empty?
98
+
99
+ prefixes = vocab_prefixes(graph).merge(prefixes || {})
100
+ pfx_width = prefixes.keys.map(&:to_s).map(&:length).max
101
+ prefixes.each do |pfx, uri|
102
+ output << "@prefix %*s: <%s> .\n" % [pfx_width, pfx, uri]
103
+ end
88
104
 
89
- next if po.empty?
105
+ # Determine the category for each subject in the vocabulary graph
106
+ cats = subject_categories(graph)
107
+
108
+ writer = RDF::Turtle::Writer.new(StringIO.new, prefixes: prefixes)
109
+
110
+ {
111
+ ont: {
112
+ heading: "# #{__name__.split('::').last} Vocabulary definition\n"
113
+ },
114
+ classes: {
115
+ heading: "# Class definitions\n"
116
+ },
117
+ properties: {
118
+ heading: "# Property definitions\n"
119
+ },
120
+ datatypes: {
121
+ heading: "# Datatype definitions\n"
122
+ },
123
+ other: {
124
+ heading: "# Other definitions\n"
125
+ }
126
+ }.each do |key, hash|
127
+ next unless cats[key]
90
128
 
91
- po_list = []
92
- unless (types = po.delete(RDF.type)).empty?
93
- po_list << 'a ' + types.map {|o| writer.format_term(o)}.join(", ")
94
- end
129
+ output << "\n\n#{hash[:heading]}"
95
130
 
96
- # Serialize other predicate/objects
97
- po.each do |predicate, objects|
98
- resource = predicate.qname ? predicate.pname : "<#{predicate}>"
99
- po_list << resource + ' ' + objects.map {|o| writer.format_term(o)}.join(", ")
100
- end
131
+ cats[key].each do |subject|
132
+ po = {}
101
133
 
102
- # Output statements for this subject
103
- subj = subject.qname ? subject.pname : "<#{subject}>"
104
- output << "#{subj} " + po_list.join(";\n ") + "\n .\n"
134
+ # Group predicates with their values
135
+ graph.query(subject: subject) do |statement|
136
+ # Sanity check this, as these are set to an empty string if not defined.
137
+ next if [RDF::RDFS.label, RDF::RDFS.comment].include?(statement.predicate) && statement.object.to_s.empty?
138
+ po[statement.predicate] ||= []
139
+ po[statement.predicate] << statement.object
140
+ end
141
+
142
+ next if po.empty?
143
+
144
+ po_list = []
145
+ unless (types = po.delete(RDF.type)).empty?
146
+ po_list << 'a ' + types.map {|o| writer.format_term(o)}.join(", ")
105
147
  end
106
- end
107
148
 
108
- output.join("")
149
+ # Serialize other predicate/objects
150
+ po.each do |predicate, objects|
151
+ resource = predicate.qname ? predicate.pname : "<#{predicate}>"
152
+ po_list << resource + ' ' + objects.map {|o| writer.format_term(o)}.join(", ")
153
+ end
154
+
155
+ # Output statements for this subject
156
+ subj = subject.qname ? subject.pname : "<#{subject}>"
157
+ output << "#{subj} " + po_list.join(";\n ") + "\n .\n"
158
+ end
109
159
  end
160
+
161
+ output.join("")
110
162
  rescue LoadError
111
163
  # No Turtle serialization unless gem loaded
112
164
  end
113
165
 
114
- begin
166
+ ##
167
+ # Generate JSON-LD representation, specific to vocabularies
168
+ #
169
+ # @param [RDF::Queryable] :graph Optional graph, otherwise uses statements from vocabulary.
170
+ # @param [Hash{#to_sym => String}] Prefixes to add to output
171
+ # @return [String]
172
+ def to_jsonld(graph: nil, prefixes: nil)
115
173
  require 'json/ld'
116
174
 
117
- ##
118
- # Generate JSON-LD representation, specific to vocabularies
119
- #
120
- # @param [RDF::Queryable] :graph Optional graph, otherwise uses statements from vocabulary.
121
- # @param [Hash{#to_sym => String}] Prefixes to add to output
122
- # @return [String]
123
- def to_jsonld(graph: nil, prefixes: nil)
124
- context = {}
125
- rdfs_context = ::JSON.parse %({
126
- "dc:title": {"@container": "@language"},
127
- "dc:description": {"@container": "@language"},
128
- "dc:date": {"@type": "xsd:date"},
129
- "rdfs:comment": {"@container": "@language"},
130
- "rdfs:domain": {"@type": "@vocab"},
131
- "rdfs:label": {"@container": "@language"},
132
- "rdfs:range": {"@type": "@vocab"},
133
- "rdfs:seeAlso": {"@type": "@id"},
134
- "rdfs:subClassOf": {"@type": "@vocab"},
135
- "rdfs:subPropertyOf": {"@type": "@vocab"},
136
- "schema:domainIncludes": {"@type": "@vocab"},
137
- "schema:rangeIncludes": {"@type": "@vocab"},
138
- "owl:equivalentClass": {"@type": "@vocab"},
139
- "owl:equivalentProperty": {"@type": "@vocab"},
140
- "owl:oneOf": {"@container": "@list", "@type": "@vocab"},
141
- "owl:imports": {"@type": "@id"},
142
- "owl:versionInfo": {"@type": "@id"},
143
- "owl:inverseOf": {"@type": "@vocab"},
144
- "owl:unionOf": {"@type": "@vocab", "@container": "@list"},
145
- "rdfs_classes": {"@reverse": "rdfs:isDefinedBy", "@type": "@id"},
146
- "rdfs_properties": {"@reverse": "rdfs:isDefinedBy", "@type": "@id"},
147
- "rdfs_datatypes": {"@reverse": "rdfs:isDefinedBy", "@type": "@id"},
148
- "rdfs_instances": {"@reverse": "rdfs:isDefinedBy", "@type": "@id"}
149
- })
150
- rdfs_classes, rdfs_properties, rdfs_datatypes, rdfs_instances = [], [], [], [], []
151
-
152
- ontology = {
153
- "@context" => rdfs_context,
154
- "@id" => to_uri.to_s
155
- }
175
+ context = {}
176
+ rdfs_context = ::JSON.parse %({
177
+ "dc:title": {"@container": "@language"},
178
+ "dc:description": {"@container": "@language"},
179
+ "dc:date": {"@type": "xsd:date"},
180
+ "rdfs:comment": {"@container": "@language"},
181
+ "rdfs:domain": {"@type": "@vocab"},
182
+ "rdfs:label": {"@container": "@language"},
183
+ "rdfs:range": {"@type": "@vocab"},
184
+ "rdfs:seeAlso": {"@type": "@id"},
185
+ "rdfs:subClassOf": {"@type": "@vocab"},
186
+ "rdfs:subPropertyOf": {"@type": "@vocab"},
187
+ "schema:domainIncludes": {"@type": "@vocab"},
188
+ "schema:rangeIncludes": {"@type": "@vocab"},
189
+ "owl:equivalentClass": {"@type": "@vocab"},
190
+ "owl:equivalentProperty": {"@type": "@vocab"},
191
+ "owl:oneOf": {"@container": "@list", "@type": "@vocab"},
192
+ "owl:imports": {"@type": "@id"},
193
+ "owl:versionInfo": {"@type": "@id"},
194
+ "owl:inverseOf": {"@type": "@vocab"},
195
+ "owl:unionOf": {"@type": "@vocab", "@container": "@list"},
196
+ "rdfs_classes": {"@reverse": "rdfs:isDefinedBy", "@type": "@id"},
197
+ "rdfs_properties": {"@reverse": "rdfs:isDefinedBy", "@type": "@id"},
198
+ "rdfs_datatypes": {"@reverse": "rdfs:isDefinedBy", "@type": "@id"},
199
+ "rdfs_instances": {"@reverse": "rdfs:isDefinedBy", "@type": "@id"}
200
+ })
201
+ rdfs_classes, rdfs_properties, rdfs_datatypes, rdfs_instances = [], [], [], [], []
156
202
 
157
- # Find namespaces used in the vocabulary
158
- graph = RDF::Graph.new {|g| each_statement {|s| g << s}} if graph.nil? || graph.empty?
203
+ ontology = {
204
+ "@context" => rdfs_context,
205
+ "@id" => to_uri.to_s
206
+ }
159
207
 
160
- prefixes = vocab_prefixes(graph).merge(prefixes || {})
161
- prefixes.each do |pfx, uri|
162
- context[pfx.to_s] = uri.to_s unless pfx.to_s.empty?
163
- end
208
+ # Find namespaces used in the vocabulary
209
+ graph = RDF::Graph.new {|g| each_statement {|s| g << s}} if graph.nil? || graph.empty?
164
210
 
165
- # Determine the category for each subject in the vocabulary graph
166
- cats = subject_categories(graph)
211
+ prefixes = vocab_prefixes(graph).merge(prefixes || {})
212
+ prefixes.each do |pfx, uri|
213
+ context[pfx.to_s] = uri.to_s unless pfx.to_s.empty?
214
+ end
167
215
 
168
- # Generate term definitions from graph subjects
169
- cats.values.flatten.each do |term|
170
- next unless Array(term.qname).length == 2
171
- context[term.qname.last.to_s] = term.to_uri.to_s
172
- end
216
+ # Determine the category for each subject in the vocabulary graph
217
+ cats = subject_categories(graph)
173
218
 
174
- # Parse the two contexts so we know what terms are in scope
175
- jld_context = ::JSON::LD::Context.new.parse([context, rdfs_context])
176
-
177
- {
178
- ont: {
179
- heading: "# #{__name__.split('::').last} Vocabulary definition\n",
180
- bucket: ontology,
181
- },
182
- classes: {
183
- heading: "# Class definitions\n",
184
- bucket: rdfs_classes,
185
- rev_prop: "rdfs_classes"
186
- },
187
- properties: {
188
- heading: "# Property definitions\n",
189
- bucket: rdfs_properties,
190
- rev_prop: "rdfs_properties"
191
- },
192
- datatypes: {
193
- heading: "# Datatype definitions\n",
194
- bucket: rdfs_datatypes,
195
- rev_prop: "rdfs_datatypes"
196
- },
197
- other: {
198
- heading: "# Other definitions\n",
199
- bucket: rdfs_instances,
200
- rev_prop: "rdfs_instances"
201
- }
202
- }.each do |key, hash|
203
- next unless cats[key]
204
-
205
- cats[key].each do |subject|
206
- node = {"@id" => subject.pname}
207
- po = {}
208
-
209
- # Group predicates with their values
210
- graph.query(subject: subject) do |statement|
211
- # Sanity check this, as these are set to an empty string if not defined.
212
- next if [RDF::RDFS.label, RDF::RDFS.comment].include?(statement.predicate) && statement.object.to_s.empty?
213
- po[statement.predicate] ||= []
214
- po[statement.predicate] << statement.object
215
- end
219
+ # Generate term definitions from graph subjects
220
+ cats.values.flatten.each do |term|
221
+ next unless Array(term.qname).length == 2
222
+ context[term.qname.last.to_s] = term.to_uri.to_s
223
+ end
216
224
 
217
- next if po.empty?
225
+ # Parse the two contexts so we know what terms are in scope
226
+ jld_context = ::JSON::LD::Context.new.parse([context, rdfs_context])
227
+
228
+ {
229
+ ont: {
230
+ heading: "# #{__name__.split('::').last} Vocabulary definition\n",
231
+ bucket: ontology,
232
+ },
233
+ classes: {
234
+ heading: "# Class definitions\n",
235
+ bucket: rdfs_classes,
236
+ rev_prop: "rdfs_classes"
237
+ },
238
+ properties: {
239
+ heading: "# Property definitions\n",
240
+ bucket: rdfs_properties,
241
+ rev_prop: "rdfs_properties"
242
+ },
243
+ datatypes: {
244
+ heading: "# Datatype definitions\n",
245
+ bucket: rdfs_datatypes,
246
+ rev_prop: "rdfs_datatypes"
247
+ },
248
+ other: {
249
+ heading: "# Other definitions\n",
250
+ bucket: rdfs_instances,
251
+ rev_prop: "rdfs_instances"
252
+ }
253
+ }.each do |key, hash|
254
+ next unless cats[key]
255
+
256
+ cats[key].each do |subject|
257
+ node = {"@id" => subject.pname}
258
+ po = {}
259
+
260
+ # Group predicates with their values
261
+ graph.query(subject: subject) do |statement|
262
+ # Sanity check this, as these are set to an empty string if not defined.
263
+ next if [RDF::RDFS.label, RDF::RDFS.comment].include?(statement.predicate) && statement.object.to_s.empty?
264
+ po[statement.predicate] ||= []
265
+ po[statement.predicate] << statement.object
266
+ end
218
267
 
219
- node['@type'] = po.delete(RDF.type).map {|t| jld_context.compact_iri(t, vocab: true)}
268
+ next if po.empty?
220
269
 
221
- po.each do |predicate, objects|
222
- term = jld_context.compact_iri(predicate, vocab: true)
223
- node[term] = if jld_context.container(term) == '@language'
224
- lang_map = objects.inject({}) do |memo, o|
225
- raise "Language-mapped term #{term} with non plain-literal #{o.inspect}" unless o.literal? && o.plain?
226
- memo.merge(o.language.to_s => o.value)
227
- end
228
- # Don't use language map if there's only one entry with no language
229
- lang_map = lang_map[""] if lang_map.keys == [""]
230
- [lang_map]
231
- else
232
- objects.map do |o|
233
- expanded_value = jld_context.expand_value(term, o)
234
- jld_context.compact_value(term, expanded_value)
235
- end
236
- end
237
- end
270
+ node['@type'] = po.delete(RDF.type).map {|t| jld_context.compact_iri(t, vocab: true)}
238
271
 
239
- node.each do |property, values|
240
- case values.length
241
- when 0 then node.delete(property)
242
- when 1 then node[property] = values.first
272
+ po.each do |predicate, objects|
273
+ term = jld_context.compact_iri(predicate, vocab: true)
274
+ node[term] = if jld_context.container(term) == '@language'
275
+ lang_map = objects.inject({}) do |memo, o|
276
+ raise "Language-mapped term #{term} with non plain-literal #{o.inspect}" unless o.literal? && o.plain?
277
+ memo.merge(o.language.to_s => o.value)
278
+ end
279
+ # Don't use language map if there's only one entry with no language
280
+ lang_map = lang_map[""] if lang_map.keys == [""]
281
+ [lang_map]
282
+ else
283
+ objects.map do |o|
284
+ expanded_value = jld_context.expand_value(term, o)
285
+ jld_context.compact_value(term, expanded_value)
243
286
  end
244
287
  end
288
+ end
245
289
 
246
- # Either set bucket from node, or append node to bucket
247
- if hash[:bucket].is_a?(Hash)
248
- hash[:bucket].merge!(node)
249
- else
250
- ontology[hash[:rev_prop]] ||= hash[:bucket]
251
- hash[:bucket] << node
290
+ node.each do |property, values|
291
+ case values.length
292
+ when 0 then node.delete(property)
293
+ when 1 then node[property] = values.first
252
294
  end
253
295
  end
254
- end
255
296
 
256
- # Serialize result
257
- {
258
- "@context" => context,
259
- "@graph" => ontology
260
- }.to_json(::JSON::LD::JSON_STATE)
297
+ # Either set bucket from node, or append node to bucket
298
+ if hash[:bucket].is_a?(Hash)
299
+ hash[:bucket].merge!(node)
300
+ else
301
+ ontology[hash[:rev_prop]] ||= hash[:bucket]
302
+ hash[:bucket] << node
303
+ end
304
+ end
261
305
  end
306
+
307
+ # Serialize result
308
+ {
309
+ "@context" => context,
310
+ "@graph" => ontology
311
+ }.to_json(::JSON::LD::JSON_STATE)
262
312
  rescue LoadError
263
313
  # No JSON-LD serialization unless gem loaded
264
314
  end
@@ -266,8 +316,8 @@ module RDF
266
316
  ##
267
317
  # Generate HTML+RDFa representation, specific to vocabularies. This uses generated JSON-LD and a Haml template.
268
318
  #
269
- # @param [RDF::Queryable] :graph Optional graph, otherwise uses statements from vocabulary.
270
- # @param [Hash{#to_sym => String}] Prefixes to add to output
319
+ # @param [RDF::Queryable] graph Optional graph, otherwise uses statements from vocabulary.
320
+ # @param [Hash{#to_sym => String}] prefixes to add to output
271
321
  # @param [String, Hash] jsonld
272
322
  # If not provided, the `to_jsonld` method is used to generate it.
273
323
  # @param [String] template The path to a Haml or ERB template used to generate the output using the JSON-LD serialization
@@ -342,7 +392,7 @@ module RDF
342
392
  when /.erb$/
343
393
  require 'erubis'
344
394
  eruby = Erubis::FastEruby.new(File.read(template))
345
- result = eruby.evaluate(binding: self, ont: expanded, context: json['@context'], prefixes: prefixes)
395
+ eruby.evaluate(binding: self, ont: expanded, context: json['@context'], prefixes: prefixes)
346
396
  else
347
397
  raise "Unknown template type #{template}. Should have '.erb' or '.haml' extension"
348
398
  end