rdf-rdfa 2.2.2 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 01d81ec1f8d8b64791be947449c08434ed7c6114
4
- data.tar.gz: 0ff8146b753c38d5cedc50774d2bf28c445489d7
2
+ SHA256:
3
+ metadata.gz: 41a438683b553f9eaa31a244a4fbbeeb2413b999f040b4a46980fe939d1891d2
4
+ data.tar.gz: a191ff7cf36e120aa52491c8eea5b4cab05b48d5595c0486a6e9ed774093b39e
5
5
  SHA512:
6
- metadata.gz: 0c3a56592cb54716af54e48aae735a03301cd160a05e32e183b4a467ae8d57496d6653970e17cef280df52e076e5fa8325acf6ffac45125976d262c40d1a1c70
7
- data.tar.gz: 2f366a57af1e44246482fa5ad810ac5983b8b6a69bbc9e50b08d79d56f8147611d40d4767568a01d07493e5f5a8d93263c892d304fd107b752e8d90091971443
6
+ metadata.gz: 4e95a2ef75396bfead46f171d2366bf4019c7a6ffd9be70e1ae24614671d7f20719eb00476906ef17047bbf9ef9ed1ac7f711b5905e42c64094ac85134a48469
7
+ data.tar.gz: b1cd79507874df6cb7f516a6ad87450b9d0e14e63784fe90191c862cd38c35a5520b33c315b287483aadc14800de677b200d7e94dcdb5ae6c54ae9fbf0c282d1
data/README.md CHANGED
@@ -16,7 +16,7 @@ RDF::RDFa parses [RDFa][RDFa 1.1 Core] into statements or triples.
16
16
  * Fully compliant RDFa 1.1 parser.
17
17
  * Template-based Writer to generate XHTML+RDFa.
18
18
  * Writer uses user-replacable [Haml][Haml]-based templates to generate RDFa.
19
- * If available, uses [Nokogiri][] for parsing HTML/SVG, falls back to REXML otherwise. For HTML5, include the [Nokogumbo][] gem for are pure-HTML5 parser with better error detection.
19
+ * If available, uses [Nokogiri][] for parsing HTML/SVG, falls back to REXML otherwise. For HTML5, include the [Nokogumbo][] gem for a pure-HTML5 parser with better error detection.
20
20
 
21
21
  Install with `gem install rdf-rdfa`
22
22
 
@@ -397,12 +397,12 @@ The template hash defines four Haml templates:
397
397
  }
398
398
 
399
399
  ## Dependencies
400
- * [Ruby](http://ruby-lang.org/) (>= 2.2)
401
- * [RDF.rb](http://rubygems.org/gems/rdf) (>= 2.2)
402
- * [Haml](https://rubygems.org/gems/haml) (>= 4.0)
403
- * [HTMLEntities](https://rubygems.org/gems/htmlentities) (>= 4.3.1)
404
- * Soft dependency on [Nokogiri](http://rubygems.org/gems/nokogiri) (>= 1.7.1)
405
- * Soft dependency on [Nokogumbo](https://github.com/rubys/nokogumbo) (>= 1.4.10)
400
+ * [Ruby](http://ruby-lang.org/) (>= 2.4)
401
+ * [RDF.rb](http://rubygems.org/gems/rdf) (~> 3.1)
402
+ * [Haml](https://rubygems.org/gems/haml) (~> 5.1)
403
+ * [HTMLEntities](https://rubygems.org/gems/htmlentities) (>= 4.3)
404
+ * Soft dependency on [Nokogiri](http://rubygems.org/gems/nokogiri) (>= 1.10)
405
+ * Soft dependency on [Nokogumbo](https://github.com/rubys/nokogumbo) (>= 2.0)
406
406
 
407
407
  ## Documentation
408
408
  Full documentation available on [Rubydoc.info][RDFa doc]
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.2.2
1
+ 3.1.0
@@ -31,9 +31,9 @@ module RDF
31
31
  autoload :Reader, 'rdf/rdfa/reader'
32
32
  autoload :Writer, 'rdf/rdfa/writer'
33
33
  autoload :VERSION, 'rdf/rdfa/version'
34
-
34
+
35
35
  HTML_RDFA_CONTEXT = "http://www.w3.org/2011/rdfa-context/html-rdfa-1.1"
36
36
  XHTML_RDFA_CONTEXT = "http://www.w3.org/2011/rdfa-context/xhtml-rdfa-1.1"
37
37
  XML_RDFA_CONTEXT = "http://www.w3.org/2011/rdfa-context/rdfa-1.1"
38
38
  end
39
- end
39
+ end
@@ -19,7 +19,7 @@ module RDF::RDFa
19
19
  # @!attribute [r] terms
20
20
  # @return [Hash{Symbol => RDF::URI}]
21
21
  attr_reader :terms
22
-
22
+
23
23
  # Default URI defined for this vocabulary
24
24
  # @!attribute [r] vocabulary
25
25
  # @return [RDF::URI]
@@ -29,7 +29,7 @@ module RDF::RDFa
29
29
  # @!attribute [r] uri
30
30
  # @return [RDF::URI]
31
31
  attr_reader :uri
32
-
32
+
33
33
  ##
34
34
  # Initialize a new context from the given URI.
35
35
  #
@@ -40,17 +40,17 @@ module RDF::RDFa
40
40
  # @yieldparam [RDF::RDFa::Context] context
41
41
  # @yieldreturn [void] ignored
42
42
  # @return [RDF::RDFa::Context]
43
- def initialize(uri, options = {}, &block)
43
+ def initialize(uri, **options, &block)
44
44
  @uri = RDF::URI.intern(uri)
45
45
  @prefixes = options.fetch(:prefixes, {})
46
46
  @terms = options.fetch(:terms, {})
47
47
  @vocabulary = options[:vocabulary]
48
48
  @options = options.dup
49
-
49
+
50
50
  yield(self) if block_given?
51
51
  self
52
52
  end
53
-
53
+
54
54
  ##
55
55
  # @return [RDF::Util::Cache]
56
56
  # @private
@@ -67,7 +67,7 @@ module RDF::RDFa
67
67
  def self.repository
68
68
  @repository ||= RDF::Repository.new(title: "RDFa Contexts")
69
69
  end
70
-
70
+
71
71
  ##
72
72
  # Set repository used for saving contexts
73
73
  # @param [RDF::Repository] repo
@@ -82,14 +82,14 @@ module RDF::RDFa
82
82
  end
83
83
  @repository = repo
84
84
  end
85
-
85
+
86
86
  # Return a context faulting through the cache
87
87
  # @return [RDF::RDFa::Context]
88
88
  def self.find(uri)
89
89
  uri = RDF::URI.intern(uri)
90
-
90
+
91
91
  return cache[uri] unless cache[uri].nil?
92
-
92
+
93
93
  # Two part creation to prevent re-entrancy problems if p1 => p2 and p2 => p1
94
94
  # Return something to make the caller happy if we're re-entered
95
95
  cache[uri] = Struct.new(:prefixes, :terms, :vocabulary).new({}, {}, nil)
@@ -97,7 +97,7 @@ module RDF::RDFa
97
97
  cache[uri] = new(uri) do |context|
98
98
  log_debug("process_context: retrieve context <#{uri}>") if respond_to?(:log_debug)
99
99
  Context.load(uri)
100
- context.parse(repository.query(graph_name: uri))
100
+ context.parse(repository.query({graph_name: uri}))
101
101
  end
102
102
  rescue Exception => e
103
103
  if respond_to?(:log_fatal)
@@ -112,12 +112,12 @@ module RDF::RDFa
112
112
  uri = RDF::URI.intern(uri)
113
113
  repository.load(uri.to_s, base_uri: uri, graph_name: uri) unless repository.has_graph?(uri)
114
114
  end
115
-
115
+
116
116
  # @return [RDF::Repository]
117
117
  def repository
118
118
  Context.repository
119
119
  end
120
-
120
+
121
121
  ##
122
122
  # Defines the given named URI prefix for this context.
123
123
  #
@@ -151,7 +151,7 @@ module RDF::RDFa
151
151
  name = name.to_s.empty? ? nil : (name.respond_to?(:to_sym) ? name.to_sym : name.to_s.to_sym)
152
152
  uri.nil? ? terms[name] : terms[name] = uri
153
153
  end
154
-
154
+
155
155
  ##
156
156
  # Extract vocabulary, prefix mappings and terms from a enumerable object into an instance
157
157
  #
@@ -179,14 +179,14 @@ module RDF::RDFa
179
179
  log_debug("process_context: uri=#{uri.inspect}, term=#{term.inspect}, prefix=#{prefix.inspect}, vocabulary=#{vocab.inspect}") if respond_to?(:log_debug)
180
180
 
181
181
  @vocabulary = vocab if vocab
182
-
182
+
183
183
  # For every extracted triple that is the common subject of an rdfa:prefix and an rdfa:uri
184
184
  # predicate, create a mapping from the object literal of the rdfa:prefix predicate to the
185
185
  # object literal of the rdfa:uri predicate. Add or update this mapping in the local list of
186
186
  # URI mappings after transforming the 'prefix' component to lower-case.
187
187
  # For every extracted
188
188
  prefix(prefix.downcase, uri) if uri && prefix && prefix != "_"
189
-
189
+
190
190
  # triple that is the common subject of an rdfa:term and an rdfa:uri predicate, create a
191
191
  # mapping from the object literal of the rdfa:term predicate to the object literal of the
192
192
  # rdfa:uri predicate. Add or update this mapping in the local term mappings.
@@ -4,8 +4,8 @@
4
4
  class RDF::RDFa::Context
5
5
  def self.find_with_html_rdfa_1_1(uri)
6
6
  if uri.to_s == "http://www.w3.org/2011/rdfa-context/html-rdfa-1.1"
7
- @_html_rdfa_1_1_prof ||= RDF::RDFa::Context.new(RDF::URI("http://www.w3.org/2011/rdfa-context/html-rdfa-1.1"), {
8
- })
7
+ @_html_rdfa_1_1_prof ||= RDF::RDFa::Context.new(RDF::URI("http://www.w3.org/2011/rdfa-context/html-rdfa-1.1"),
8
+ )
9
9
  else
10
10
  find_without_html_rdfa_1_1(uri)
11
11
  end
@@ -4,7 +4,7 @@
4
4
  class RDF::RDFa::Context
5
5
  def self.find_with_xhtml_rdfa_1_1(uri)
6
6
  if uri.to_s == "http://www.w3.org/2011/rdfa-context/xhtml-rdfa-1.1"
7
- @_xhtml_rdfa_1_1_prof ||= RDF::RDFa::Context.new(RDF::URI("http://www.w3.org/2011/rdfa-context/xhtml-rdfa-1.1"), {
7
+ @_xhtml_rdfa_1_1_prof ||= RDF::RDFa::Context.new(RDF::URI("http://www.w3.org/2011/rdfa-context/xhtml-rdfa-1.1"),
8
8
  terms: {
9
9
  alternate: "http://www.w3.org/1999/xhtml/vocab#alternate",
10
10
  appendix: "http://www.w3.org/1999/xhtml/vocab#appendix",
@@ -32,7 +32,7 @@ class RDF::RDFa::Context
32
32
  top: "http://www.w3.org/1999/xhtml/vocab#top",
33
33
  up: "http://www.w3.org/1999/xhtml/vocab#up",
34
34
  },
35
- })
35
+ )
36
36
  else
37
37
  find_without_xhtml_rdfa_1_1(uri)
38
38
  end
@@ -4,8 +4,9 @@
4
4
  class RDF::RDFa::Context
5
5
  def self.find_with_rdfa_1_1(uri)
6
6
  if uri.to_s == "http://www.w3.org/2011/rdfa-context/rdfa-1.1"
7
- @_rdfa_1_1_prof ||= RDF::RDFa::Context.new(RDF::URI("http://www.w3.org/2011/rdfa-context/rdfa-1.1"), {
7
+ @_rdfa_1_1_prof ||= RDF::RDFa::Context.new(RDF::URI("http://www.w3.org/2011/rdfa-context/rdfa-1.1"),
8
8
  prefixes: {
9
+ as: "https://www.w3.org/ns/activitystreams#",
9
10
  cc: "http://creativecommons.org/ns#",
10
11
  csvw: "http://www.w3.org/ns/csvw#",
11
12
  ctag: "http://commontag.org/ns#",
@@ -13,11 +14,16 @@ class RDF::RDFa::Context
13
14
  dc11: "http://purl.org/dc/elements/1.1/",
14
15
  dcat: "http://www.w3.org/ns/dcat#",
15
16
  dcterms: "http://purl.org/dc/terms/",
17
+ dqv: "http://www.w3.org/ns/dqv#",
18
+ duv: "https://www.w3.org/ns/duv#",
16
19
  foaf: "http://xmlns.com/foaf/0.1/",
17
20
  gr: "http://purl.org/goodrelations/v1#",
18
21
  grddl: "http://www.w3.org/2003/g/data-view#",
19
22
  ical: "http://www.w3.org/2002/12/cal/icaltzd#",
23
+ ldp: "http://www.w3.org/ns/ldp#",
20
24
  ma: "http://www.w3.org/ns/ma-ont#",
25
+ oa: "http://www.w3.org/ns/oa#",
26
+ odrl: "http://www.w3.org/ns/odrl/2/",
21
27
  og: "http://ogp.me/ns#",
22
28
  org: "http://www.w3.org/ns/org#",
23
29
  owl: "http://www.w3.org/2002/07/owl#",
@@ -34,6 +40,9 @@ class RDF::RDFa::Context
34
40
  sioc: "http://rdfs.org/sioc/ns#",
35
41
  skos: "http://www.w3.org/2004/02/skos/core#",
36
42
  skosxl: "http://www.w3.org/2008/05/skos-xl#",
43
+ sosa: "http://www.w3.org/ns/sosa/",
44
+ ssn: "http://www.w3.org/ns/ssn/",
45
+ time: "http://www.w3.org/2006/time#",
37
46
  v: "http://rdf.data-vocabulary.org/#",
38
47
  vcard: "http://www.w3.org/2006/vcard/ns#",
39
48
  void: "http://rdfs.org/ns/void#",
@@ -48,7 +57,7 @@ class RDF::RDFa::Context
48
57
  license: "http://www.w3.org/1999/xhtml/vocab#license",
49
58
  role: "http://www.w3.org/1999/xhtml/vocab#role",
50
59
  },
51
- })
60
+ )
52
61
  else
53
62
  find_without_rdfa_1_1(uri)
54
63
  end
@@ -17,7 +17,7 @@ module RDF::RDFa
17
17
  add_debug("expand") {"Repository has #{repository.count} statements"}
18
18
 
19
19
  # Load missing vocabularies
20
- vocabs = repository.query(predicate: RDF::RDFA.usesVocabulary).to_a.map(&:object)
20
+ vocabs = repository.query({predicate: RDF::RDFA.usesVocabulary}).to_a.map(&:object)
21
21
  vocabs.map! do |vocab|
22
22
  begin
23
23
  # Create the name with a predictable name so that it is enumerated and can be found
@@ -108,7 +108,7 @@ module RDF::RDFa
108
108
  def consequent(subject, prediate, object)
109
109
  consequents << RDF::Query::Pattern.new(subject, prediate, object)
110
110
  end
111
-
111
+
112
112
  ##
113
113
  # Execute the rule against queryable, yielding each consequent with bindings
114
114
  #
@@ -227,7 +227,7 @@ module RDF::RDFa
227
227
  to_add << statement
228
228
  end
229
229
  end
230
-
230
+
231
231
  repository.insert(*to_add)
232
232
  end
233
233
  end
@@ -250,7 +250,7 @@ module RDF::RDFa
250
250
  to_add << statement
251
251
  end
252
252
  end
253
-
253
+
254
254
  repository.insert(*to_add)
255
255
  end
256
256
 
@@ -6,4 +6,4 @@ class ::String
6
6
  ws = str.match(/^(\s*)\S/m) ? $1 : ''
7
7
  str.gsub(/^#{ws}/m, '')
8
8
  end
9
- end
9
+ end
@@ -31,7 +31,7 @@ module RDF::RDFa
31
31
  include RDF::Util::Logger
32
32
 
33
33
  XHTML = "http://www.w3.org/1999/xhtml"
34
-
34
+
35
35
  # Content model for @about and @resource. In RDFa 1.0, this was URIorSafeCURIE
36
36
  SafeCURIEorCURIEorIRI = {
37
37
  :"rdfa1.0" => [:safe_curie, :uri, :bnode],
@@ -83,17 +83,17 @@ module RDF::RDFa
83
83
  # @!attribute [r] host_language
84
84
  # @return [:xml, :xhtml1, :xhtml5, :html4, :html5, :svg]
85
85
  attr_reader :host_language
86
-
86
+
87
87
  # Version
88
88
  # @!attribute [r] version
89
89
  # @return [:"rdfa1.0", :"rdfa1.1"]
90
90
  attr_reader :version
91
-
91
+
92
92
  # Repository used for collecting triples.
93
93
  # @!attribute [r] repository
94
94
  # @return [RDF::Repository]
95
95
  attr_reader :repository
96
-
96
+
97
97
  # Returns the XML implementation module for this reader instance.
98
98
  #
99
99
  # @!attribute [rw] implementation
@@ -124,7 +124,7 @@ module RDF::RDFa
124
124
  # @!attribute [rw] parent_subject
125
125
  # @return [RDF::URI]
126
126
  attr_accessor :parent_subject
127
-
127
+
128
128
  ##
129
129
  # The parent object.
130
130
  #
@@ -138,14 +138,14 @@ module RDF::RDFa
138
138
  # @!attribute [rw] parent_object
139
139
  # @return [RDF::URI]
140
140
  attr_accessor :parent_object
141
-
141
+
142
142
  ##
143
143
  # A list of current, in-scope URI mappings.
144
144
  #
145
145
  # @!attribute [rw] uri_mappings
146
146
  # @return [Hash{Symbol => String}]
147
147
  attr_accessor :uri_mappings
148
-
148
+
149
149
  ##
150
150
  # A list of current, in-scope Namespaces. This is the subset of uri_mappings
151
151
  # which are defined using xmlns.
@@ -153,7 +153,7 @@ module RDF::RDFa
153
153
  # @!attribute [rw] namespaces
154
154
  # @return [Hash{String => Namespace}]
155
155
  attr_accessor :namespaces
156
-
156
+
157
157
  ##
158
158
  # A list of incomplete triples.
159
159
  #
@@ -165,14 +165,14 @@ module RDF::RDFa
165
165
  # @!attribute [rw] incomplete_triples
166
166
  # @return [Array<Array<RDF::URI, RDF::Resource>>]
167
167
  attr_accessor :incomplete_triples
168
-
168
+
169
169
  ##
170
170
  # The language. Note that there is no default language.
171
171
  #
172
172
  # @!attribute [rw] language
173
173
  # @return [Symbol]
174
174
  attr_accessor :language
175
-
175
+
176
176
  ##
177
177
  # The term mappings, a list of terms and their associated URIs.
178
178
  #
@@ -183,7 +183,7 @@ module RDF::RDFa
183
183
  # @!attribute [rw] term_mappings
184
184
  # @return [Hash{Symbol => RDF::URI}]
185
185
  attr_accessor :term_mappings
186
-
186
+
187
187
  ##
188
188
  # The default vocabulary
189
189
  #
@@ -230,7 +230,7 @@ module RDF::RDFa
230
230
  @namespaces = from.namespaces.clone
231
231
  @list_mapping = from.list_mapping # Don't clone
232
232
  end
233
-
233
+
234
234
  def inspect
235
235
  v = ['base', 'parent_subject', 'parent_object', 'language', 'default_vocabulary'].map do |a|
236
236
  "#{a}=#{o = self.send(a); o.respond_to?(:to_ntriples) ? o.to_ntriples : o.inspect}"
@@ -297,7 +297,7 @@ module RDF::RDFa
297
297
  # @yieldparam [RDF::Reader] reader
298
298
  # @yieldreturn [void] ignored
299
299
  # @raise [RDF::ReaderError] if _validate_
300
- def initialize(input = $stdin, options = {}, &block)
300
+ def initialize(input = $stdin, **options, &block)
301
301
  super do
302
302
  @options = {reference_folding: true}.merge(@options)
303
303
  @repository = RDF::Repository.new
@@ -327,12 +327,24 @@ module RDF::RDFa
327
327
  end
328
328
  self.extend(@implementation)
329
329
 
330
- detect_host_language_version(input, options)
330
+ detect_host_language_version(input, **options)
331
331
 
332
- add_info(@doc, "version = #{@version}, host_language = #{@host_language}, library = #{@library}, rdfagraph = #{@options[:rdfagraph].inspect}, expand = #{@options[:vocab_expansion]}")
332
+ parse_lib = if @library == :nokogiri && @host_language == :html5
333
+ begin
334
+ require 'nokogumbo' unless defined?(::Nokogumbo)
335
+ :nokobumbo
336
+ rescue LoadError
337
+ :nokogiri
338
+ end
339
+ else
340
+ @library
341
+ end
342
+
343
+ parse_lib = @library == :nokogiri && defined?(::Nokogumbo) ? :nokogumbo : @library
344
+ add_info(@doc, "version = #{@version}, host_language = #{@host_language}, library = #{parse_lib}, rdfagraph = #{@options[:rdfagraph].inspect}, expand = #{@options[:vocab_expansion]}")
333
345
 
334
346
  begin
335
- initialize_xml(input, options)
347
+ initialize_xml(input, **options)
336
348
  rescue
337
349
  add_error(nil, "Malformed document: #{$!.message}")
338
350
  end
@@ -369,6 +381,38 @@ module RDF::RDFa
369
381
  end
370
382
  end
371
383
 
384
+ ##
385
+ # Extracts RDF from script element, or embeded RDF/XML
386
+ def extract_script(el, input, type, **options, &block)
387
+ add_debug(el, "script element of type #{type}")
388
+ begin
389
+ # Formats don't exist unless they've been required
390
+ case type.to_s
391
+ when 'application/csvm+json' then require 'rdf/tabular'
392
+ when 'application/ld+json' then require 'json/ld'
393
+ when 'application/rdf+xml' then require 'rdf/rdfxml'
394
+ when 'text/ntriples' then require 'rdf/ntriples'
395
+ when 'text/turtle' then require 'rdf/turtle'
396
+ end
397
+ rescue LoadError
398
+ end
399
+
400
+ @readers ||= {}
401
+ reader = @readers[type.to_s] = RDF::Reader.for(content_type: type.to_s) unless @readers.has_key?(type.to_s)
402
+ if reader = @readers[type.to_s]
403
+ add_debug(el, "=> reader #{reader.to_sym}")
404
+ # Wrap input in a RemoteDocument with appropriate content-type and base
405
+ doc = if input.is_a?(String)
406
+ RDF::Util::File::RemoteDocument.new(input, content_type: type.to_s, **options)
407
+ else
408
+ input
409
+ end
410
+ reader.new(doc, **options).each(&block)
411
+ else
412
+ add_debug(el, "=> no reader found")
413
+ end
414
+ end
415
+
372
416
  ##
373
417
  # Iterates the given block for each RDF statement in the input.
374
418
  #
@@ -388,62 +432,19 @@ module RDF::RDFa
388
432
  # parse
389
433
  parse_whole_document(@doc, RDF::URI(base_uri))
390
434
 
391
- def extract_script(el, input, type, options, &block)
392
- add_debug(el, "script element of type #{type}")
393
- begin
394
- # Formats don't exist unless they've been required
395
- case type.to_s
396
- when 'application/csvm+json' then require 'rdf/tabular'
397
- when 'application/ld+json' then require 'json/ld'
398
- when 'application/rdf+xml' then require 'rdf/rdfxml'
399
- when 'text/ntriples' then require 'rdf/ntriples'
400
- when 'text/turtle' then require 'rdf/turtle'
401
- end
402
- rescue LoadError
403
- end
404
-
405
- if reader = RDF::Reader.for(content_type: type.to_s)
406
- add_debug(el, "=> reader #{reader.to_sym}")
407
- # Wrap input in a RemoteDocument with appropriate content-type and base
408
- doc = if input.is_a?(String)
409
- RDF::Util::File::RemoteDocument.new(input,
410
- options.merge(
411
- content_type: type.to_s,
412
- base_uri: base_uri
413
- ))
414
- else
415
- input
416
- end
417
- reader.new(doc, options).each(&block)
418
- else
419
- add_debug(el, "=> no reader found")
420
- end
421
- end
422
-
423
435
  # Look for Embedded RDF/XML
424
436
  unless @root.xpath("//rdf:RDF", "rdf" => "http://www.w3.org/1999/02/22-rdf-syntax-ns#").empty?
425
- extract_script(@root, @doc, "application/rdf+xml", @options) do |statement|
437
+ extract_script(@root, @doc, "application/rdf+xml", **@options.merge(base_uri: base_uri)) do |statement|
426
438
  @repository << statement
427
439
  end
428
440
  end
429
441
 
430
- # Look for Embedded scripts
431
- @root.css("script[type]").each do |el|
432
- type = el.attribute("type")
433
-
434
- text = el.inner_html.sub(%r(\A\s*\<!\[CDATA\[)m, '').sub(%r(\]\]>\s*\Z)m, '')
435
-
436
- extract_script(el, text, type, @options) do |statement|
437
- @repository << statement
438
- end
439
- end
440
-
441
442
  # Look for Embedded microdata
442
443
  unless @root.xpath("//@itemscope").empty?
443
444
  begin
444
445
  require 'rdf/microdata'
445
446
  add_debug(@doc, "process microdata")
446
- @repository << RDF::Microdata::Reader.new(@doc, options)
447
+ @repository << RDF::Microdata::Reader.new(@doc, **options)
447
448
  rescue LoadError
448
449
  add_debug(@doc, "microdata detected, not processed")
449
450
  end
@@ -454,7 +455,7 @@ module RDF::RDFa
454
455
 
455
456
  # Perform vocabulary expansion
456
457
  expand(@repository) if @options[:vocab_expansion]
457
-
458
+
458
459
  @processed = true
459
460
  end
460
461
 
@@ -493,7 +494,7 @@ module RDF::RDFa
493
494
  end
494
495
  enum_for(:each_triple)
495
496
  end
496
-
497
+
497
498
  private
498
499
 
499
500
  # Keep track of allocated BNodes
@@ -501,12 +502,12 @@ module RDF::RDFa
501
502
  @bnode_cache ||= {}
502
503
  @bnode_cache[value.to_s] ||= RDF::Node.new(value)
503
504
  end
504
-
505
+
505
506
  # Figure out the document path, if it is an Element or Attribute
506
507
  def node_path(node)
507
508
  "<#{base_uri}>#{node.respond_to?(:display_path) ? node.display_path : node}"
508
509
  end
509
-
510
+
510
511
  # Add debug event to debug array, if specified
511
512
  #
512
513
  # @param [#display_path, #to_s] node XML Node or string for showing context
@@ -519,15 +520,15 @@ module RDF::RDFa
519
520
  def add_info(node, message, process_class = RDF::RDFA.Info, &block)
520
521
  add_processor_message(node, message, process_class, &block)
521
522
  end
522
-
523
+
523
524
  def add_warning(node, message, process_class = RDF::RDFA.Warning)
524
525
  add_processor_message(node, message, process_class)
525
526
  end
526
-
527
+
527
528
  def add_error(node, message, process_class = RDF::RDFA.Error)
528
529
  add_processor_message(node, message, process_class)
529
530
  end
530
-
531
+
531
532
  def add_processor_message(node, message, process_class, &block)
532
533
  case process_class
533
534
  when RDF::RDFA.Error then log_error(node_path(node), message, &block)
@@ -552,7 +553,7 @@ module RDF::RDFa
552
553
  RDF::Statement.new(nc, RDF::PTR.expression, node.path, graph_name: RDF::RDFA.ProcessorGraph)
553
554
  ]
554
555
  end
555
-
556
+
556
557
  @repository.insert(*processor_statements)
557
558
  if cb = @options[:processor_callback]
558
559
  processor_statements.each {|s| cb.call(s)}
@@ -591,7 +592,7 @@ module RDF::RDFa
591
592
 
592
593
  # initialize the evaluation context with the appropriate base
593
594
  evaluation_context = EvaluationContext.new(base, @host_defaults)
594
-
595
+
595
596
  if @version != :"rdfa1.0"
596
597
  # Process default vocabularies
597
598
  load_initial_contexts(@host_defaults[:initial_contexts]) do |which, value|
@@ -603,11 +604,11 @@ module RDF::RDFa
603
604
  end
604
605
  end
605
606
  end
606
-
607
+
607
608
  traverse(root, evaluation_context)
608
609
  add_debug("", "parse_whole_doc: traversal complete'")
609
610
  end
610
-
611
+
611
612
  # Parse and process URI mappings, Term mappings and a default vocabulary from @context
612
613
  #
613
614
  # Yields each mapping
@@ -725,7 +726,7 @@ module RDF::RDFa
725
726
  add_error(element, "Can't parse nil element")
726
727
  return nil
727
728
  end
728
-
729
+
729
730
  add_debug(element) { "ec: #{evaluation_context.inspect}" }
730
731
 
731
732
  # local variables [7.5 Step 1]
@@ -763,6 +764,7 @@ module RDF::RDFa
763
764
  rev
764
765
  role
765
766
  src
767
+ type
766
768
  typeof
767
769
  value
768
770
  vocab
@@ -807,17 +809,26 @@ module RDF::RDFa
807
809
  "[Step 2] default_vocaulary: #{default_vocabulary.inspect}"
808
810
  }
809
811
  end
810
-
812
+
811
813
  # Local term mappings [7.5 Step 3]
812
814
  # Next, the current element is then examined for URI mapping s and these are added to the local list of URI mappings.
813
815
  # Note that a URI mapping will simply overwrite any current mapping in the list that has the same name
814
816
  extract_mappings(element, uri_mappings, namespaces)
815
-
817
+
816
818
  # Language information [7.5 Step 4]
817
819
  language = element.language || language
818
820
  language = nil if language.to_s.empty?
819
821
  add_debug(element) {"HTML5 [3.2.3.3] lang: #{language.inspect}"} if language
820
822
 
823
+ # Embedded scripts
824
+ if element.name == 'script'
825
+ text = element.inner_html.sub(%r(\A\s*\<!\[CDATA\[)m, '').sub(%r(\]\]>\s*\Z)m, '')
826
+
827
+ extract_script(element, text, attrs[:type], **@options.merge(base_uri: base)) do |statement|
828
+ @repository << statement
829
+ end
830
+ end
831
+
821
832
  # From HTML5, if the property attribute and the rel and/or rev attribute exists on the same element, the non-CURIE and non-URI rel and rev values are ignored. If, after this, the value of rel and/or rev becomes empty, then the processor must act as if the respective attribute is not present.
822
833
  if [:html5, :xhtml5].include?(@host_language) && attrs[:property] && (attrs[:rel] || attrs[:rev])
823
834
  old_rel, old_rev = attrs[:rel], attrs[:rev]
@@ -844,14 +855,14 @@ module RDF::RDFa
844
855
  term_mappings: term_mappings,
845
856
  vocab: default_vocabulary,
846
857
  restrictions: TERMorCURIEorAbsIRI.fetch(@version, []))
847
-
858
+
848
859
  add_debug(element) do
849
860
  "rels: #{rels.join(" ")}, revs: #{revs.join(" ")}"
850
861
  end unless (rels + revs).empty?
851
862
 
852
863
  if !(attrs[:rel] || attrs[:rev])
853
864
  # Establishing a new subject if no rel/rev [7.5 Step 5]
854
-
865
+
855
866
  if @version == :"rdfa1.0"
856
867
  new_subject = if attrs[:about]
857
868
  process_uri(element, attrs[:about], evaluation_context, base,
@@ -989,7 +1000,7 @@ module RDF::RDFa
989
1000
  new_subject ||= process_uri(element, attrs[:src], evaluation_context, base,
990
1001
  uri_mappings: uri_mappings,
991
1002
  restrictions: [:uri]) if @version == :"rdfa1.0"
992
-
1003
+
993
1004
  # if the @typeof attribute is present, set typed resource to new subject
994
1005
  typed_resource = new_subject if attrs[:typeof]
995
1006
 
@@ -1008,7 +1019,7 @@ module RDF::RDFa
1008
1019
  evaluation_context.parent_object
1009
1020
  # no skip flag set this time
1010
1021
  end
1011
-
1022
+
1012
1023
  # Then the current object resource is set to the URI obtained from the first match from the following rules:
1013
1024
  current_object_resource = process_uri(element, attrs[:resource], evaluation_context, base,
1014
1025
  uri_mappings: uri_mappings,
@@ -1034,7 +1045,7 @@ module RDF::RDFa
1034
1045
  "typed_resource: #{typed_resource.to_ntriples rescue 'nil'}, "
1035
1046
  }
1036
1047
  end
1037
-
1048
+
1038
1049
  # [Step 7] If in any of the previous steps a typed resource was set to a non-null value, it is now used to provide a subject for type values;
1039
1050
  if typed_resource
1040
1051
  # Typeof is TERMorCURIEorAbsIRIs
@@ -1082,7 +1093,7 @@ module RDF::RDFa
1082
1093
  add_triple(element, new_subject, r, current_object_resource)
1083
1094
  end
1084
1095
  end
1085
-
1096
+
1086
1097
  revs.each do |r|
1087
1098
  add_triple(element, current_object_resource, r, new_subject)
1088
1099
  end
@@ -1090,7 +1101,7 @@ module RDF::RDFa
1090
1101
  # Incomplete triples and bnode creation [Step 10]
1091
1102
  add_debug(element) {"[Step 10] incompletes: rels: #{rels}, revs: #{revs}"}
1092
1103
  current_object_resource = RDF::Node.new
1093
-
1104
+
1094
1105
  # predicate: full IRI
1095
1106
  # direction: forward/reverse
1096
1107
  # lists: Save into list, don't generate triple
@@ -1108,12 +1119,12 @@ module RDF::RDFa
1108
1119
  incomplete_triples << {predicate: r, direction: :forward}
1109
1120
  end
1110
1121
  end
1111
-
1122
+
1112
1123
  revs.each do |r|
1113
1124
  incomplete_triples << {predicate: r, direction: :reverse}
1114
1125
  end
1115
1126
  end
1116
-
1127
+
1117
1128
  # Establish current object literal [Step 11]
1118
1129
  #
1119
1130
  # If the current element has a @inlist attribute, add the property to the
@@ -1267,11 +1278,11 @@ module RDF::RDFa
1267
1278
  add_debug(element) {"[Step 11] add #{current_property_value.to_ntriples} to #{p.to_ntriples} #{list_mapping[p].inspect}"}
1268
1279
  list_mapping[p] << current_property_value
1269
1280
  elsif new_subject
1270
- add_triple(element, new_subject, p, current_property_value)
1281
+ add_triple(element, new_subject, p, current_property_value)
1271
1282
  end
1272
1283
  end
1273
1284
  end
1274
-
1285
+
1275
1286
  if !skip and new_subject && !evaluation_context.incomplete_triples.empty?
1276
1287
  # Complete the incomplete triples from the evaluation context [Step 12]
1277
1288
  add_debug(element) do
@@ -1329,12 +1340,12 @@ module RDF::RDFa
1329
1340
  new_ec.list_mapping = list_mapping
1330
1341
  add_debug(element, "[Step 13] new ec")
1331
1342
  end
1332
-
1343
+
1333
1344
  element.children.each do |child|
1334
1345
  # recurse only if it's an element
1335
1346
  traverse(child, new_ec) if child.element?
1336
1347
  end
1337
-
1348
+
1338
1349
  # Step 14: after traversing through child elements, for each list associated with
1339
1350
  # a property
1340
1351
  (list_mapping || {}).each do |p, l|
@@ -1380,13 +1391,13 @@ module RDF::RDFa
1380
1391
  end
1381
1392
 
1382
1393
  # space-separated TERMorCURIEorAbsIRI or SafeCURIEorCURIEorIRI
1383
- def process_uris(element, value, evaluation_context, base, options)
1394
+ def process_uris(element, value, evaluation_context, base, **options)
1384
1395
  return [] if value.to_s.empty?
1385
1396
  add_debug(element) {"process_uris: #{value}"}
1386
- value.to_s.split(/\s+/).map {|v| process_uri(element, v, evaluation_context, base, options)}.compact
1397
+ value.to_s.split(/\s+/).map {|v| process_uri(element, v, evaluation_context, base, **options)}.compact
1387
1398
  end
1388
1399
 
1389
- def process_uri(element, value, evaluation_context, base, options = {})
1400
+ def process_uri(element, value, evaluation_context, base, **options)
1390
1401
  return if value.nil?
1391
1402
  restrictions = options[:restrictions]
1392
1403
  add_debug(element) {"process_uri: #{value}, restrictions = #{restrictions.inspect}"}
@@ -1407,7 +1418,7 @@ module RDF::RDFa
1407
1418
  # TERMorCURIEorAbsIRI
1408
1419
  # If the value is an NCName, then it is evaluated as a term according to General Use of Terms in
1409
1420
  # Attributes. Note that this step may mean that the value is to be ignored.
1410
- uri = process_term(element, value.to_s, options)
1421
+ uri = process_term(element, value.to_s, **options)
1411
1422
  add_debug(element) {"process_uri: #{value} => term => #{uri ? uri.to_base : 'nil'}"}
1412
1423
  uri
1413
1424
  else
@@ -1444,16 +1455,16 @@ module RDF::RDFa
1444
1455
  add_warning(element, "Relative URI #{value}")
1445
1456
  end
1446
1457
  end
1447
-
1458
+
1448
1459
  # [7.4.3] General Use of Terms in Attributes
1449
- def process_term(element, value, options)
1460
+ def process_term(element, value, **options)
1450
1461
  if options[:vocab]
1451
1462
  # If there is a local default vocabulary, the IRI is obtained by concatenating that value and the term
1452
1463
  return uri(options[:vocab] + value)
1453
1464
  elsif options[:term_mappings].is_a?(Hash)
1454
1465
  # If the term is in the local term mappings, use the associated URI (case sensitive).
1455
1466
  return uri(options[:term_mappings][value.to_s.to_sym]) if options[:term_mappings].has_key?(value.to_s.to_sym)
1456
-
1467
+
1457
1468
  # Otherwise, check for case-insensitive match
1458
1469
  options[:term_mappings].each_pair do |term, uri|
1459
1470
  return uri(uri) if term.to_s.downcase == value.to_s.downcase