rdf-rdfa 2.2.4 → 3.1.2
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 +5 -5
- data/AUTHORS +1 -1
- data/README.md +40 -51
- data/UNLICENSE +1 -1
- data/VERSION +1 -1
- data/lib/rdf/rdfa.rb +6 -6
- data/lib/rdf/rdfa/context.rb +2 -2
- data/lib/rdf/rdfa/context/html.rb +2 -2
- data/lib/rdf/rdfa/context/xhtml.rb +2 -2
- data/lib/rdf/rdfa/context/xml.rb +12 -2
- data/lib/rdf/rdfa/expansion.rb +3 -3
- data/lib/rdf/rdfa/format.rb +1 -1
- data/lib/rdf/rdfa/reader.rb +63 -64
- data/lib/rdf/rdfa/reader/nokogiri.rb +15 -17
- data/lib/rdf/rdfa/reader/rexml.rb +12 -12
- data/lib/rdf/rdfa/vocab.rb +147 -123
- data/lib/rdf/rdfa/writer.rb +18 -18
- data/lib/rdf/rdfa/writer/haml_templates.rb +3 -3
- metadata +85 -126
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 417ba955ce570c72bfe1754246a214b35597c0c8ab65df29457f28b21f0e89ef
|
4
|
+
data.tar.gz: a266a47e8d0548e57f4033d183235139c658d0663b3983080af492555d52150d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d5103efb22006992f5e8f63d27cecd868563a6352a0432e112a19ff9a531f7e2eeeb1fa8ccaef3f3d7db381942065bb931957f97fcd539d6c4b35c8a0998db0b
|
7
|
+
data.tar.gz: b5edc843e6b115cce6a5ccb9207e53beb3590c5007465336953b11fced26fffe955602cbd62b28352eddadc2aea3d651ec98aeb6318d0556b4c6783568430dda
|
data/AUTHORS
CHANGED
@@ -1 +1 @@
|
|
1
|
-
* Gregg Kellogg <gregg@
|
1
|
+
* Gregg Kellogg <gregg@greggkellogg.net>
|
data/README.md
CHANGED
@@ -3,8 +3,8 @@ This repository uses [Git Flow](https://github.com/nvie/gitflow) to mange develo
|
|
3
3
|
|
4
4
|
[RDFa][RDFa 1.1 Core] parser for RDF.rb.
|
5
5
|
|
6
|
-
[](
|
7
|
-
[](
|
6
|
+
[](https://badge.fury.io/rb/rdf-rdfa)
|
7
|
+
[](https://travis-ci.org/ruby-rdf/rdf-rdfa)
|
8
8
|
[](https://coveralls.io/r/ruby-rdf/rdf-rdfa)
|
9
9
|
|
10
10
|
## DESCRIPTION
|
@@ -15,8 +15,8 @@ RDF::RDFa parses [RDFa][RDFa 1.1 Core] into statements or triples.
|
|
15
15
|
|
16
16
|
* Fully compliant RDFa 1.1 parser.
|
17
17
|
* Template-based Writer to generate XHTML+RDFa.
|
18
|
-
* Writer uses user-
|
19
|
-
* If available, uses [Nokogiri][] for parsing HTML/SVG, falls back to REXML otherwise. For HTML5, include the [Nokogumbo][] gem for
|
18
|
+
* Writer uses user-replaceable [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 a pure-HTML5 parser with better error detection.
|
20
20
|
|
21
21
|
Install with `gem install rdf-rdfa`
|
22
22
|
|
@@ -37,7 +37,7 @@ This version fully supports the limited syntax of [RDFa Lite 1.1][]. This includ
|
|
37
37
|
One of the issues with vocabularies was that they discourage re-use of existing vocabularies when terms from several vocabularies are used at the same time. As it is common (encouraged) for RDF vocabularies to form sub-class and/or sub-property relationships with well defined vocabularies, the RDFa vocabulary expansion mechanism takes advantage of this.
|
38
38
|
|
39
39
|
As an optional part of RDFa processing, an RDFa processor will perform limited
|
40
|
-
[OWL 2 RL Profile entailment](
|
40
|
+
[OWL 2 RL Profile entailment](https://www.w3.org/TR/2009/REC-owl2-profiles-20091027/#Reasoning_in_OWL_2_RL_and_RDF_Graphs_using_Rules),
|
41
41
|
specifically rules prp-eqp1, prp-eqp2, cax-sco, cax-eqc1, and
|
42
42
|
cax-eqc2. This causes sub-classes and sub-properties of type and property IRIs to be added
|
43
43
|
to the output graph.
|
@@ -123,24 +123,24 @@ The @typeof attribute has changed; previously, it always created a new subject,
|
|
123
123
|
|
124
124
|
For example:
|
125
125
|
|
126
|
-
<div typeof="foaf:Person" about="
|
126
|
+
<div typeof="foaf:Person" about="https://greggkellogg.net/foaf#me">
|
127
127
|
<p property="name">Gregg Kellogg</span>
|
128
|
-
<a rel="knows" typeof="foaf:Person" href="
|
128
|
+
<a rel="knows" typeof="foaf:Person" href="https://manu.sporny.org/#this">
|
129
129
|
<span property="name">Manu Sporny</span>
|
130
130
|
</a>
|
131
131
|
</div>
|
132
132
|
|
133
133
|
results in
|
134
134
|
|
135
|
-
<
|
135
|
+
<https://greggkellogg.net/foaf#me> a foaf:Person;
|
136
136
|
foaf:name "Gregg Kellogg";
|
137
|
-
foaf:knows <
|
138
|
-
<
|
137
|
+
foaf:knows <https://manu.sporny.org/#this> .
|
138
|
+
<https://manu.sporny.org/#this> a foaf:Person;
|
139
139
|
foaf:name "Manu Sporny" .
|
140
140
|
|
141
141
|
Note that if the explicit @href is not present, i.e.,
|
142
142
|
|
143
|
-
<div typeof="foaf:Person" about="
|
143
|
+
<div typeof="foaf:Person" about="https://greggkellogg.net/foaf#me">
|
144
144
|
<p property="name">Gregg Kellogg</span>
|
145
145
|
<a href="knows" typeof="foaf:Person">
|
146
146
|
<span property="name">Manu Sporny</span>
|
@@ -149,7 +149,7 @@ Note that if the explicit @href is not present, i.e.,
|
|
149
149
|
|
150
150
|
this results in
|
151
151
|
|
152
|
-
<
|
152
|
+
<https://greggkellogg.net/foaf#me> a foaf:Person;
|
153
153
|
foaf:name "Gregg Kellogg";
|
154
154
|
foaf:knows [
|
155
155
|
a foaf:Person;
|
@@ -397,24 +397,18 @@ The template hash defines four Haml templates:
|
|
397
397
|
}
|
398
398
|
|
399
399
|
## Dependencies
|
400
|
-
* [Ruby](
|
401
|
-
* [RDF.rb](
|
402
|
-
* [Haml](https://rubygems.org/gems/haml) (
|
403
|
-
* [HTMLEntities](https://rubygems.org/gems/htmlentities) (>= 4.3
|
404
|
-
* Soft dependency on [Nokogiri](
|
405
|
-
* Soft dependency on [Nokogumbo](https://github.com/rubys/nokogumbo) (>=
|
400
|
+
* [Ruby](https://ruby-lang.org/) (>= 2.4)
|
401
|
+
* [RDF.rb](https://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](https://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]
|
409
409
|
|
410
410
|
### Principle Classes
|
411
411
|
* {RDF::RDFa::Format}
|
412
|
-
* {RDF::RDFa::HTML}
|
413
|
-
Asserts :html format, text/html mime-type and .html file extension.
|
414
|
-
* {RDF::RDFa::XHTML}
|
415
|
-
Asserts :html format, application/xhtml+xml mime-type and .xhtml file extension.
|
416
|
-
* {RDF::RDFa::SVG}
|
417
|
-
Asserts :svg format, image/svg+xml mime-type and .svg file extension.
|
418
412
|
* {RDF::RDFa::Reader}
|
419
413
|
* {RDF::RDFa::Reader::Nokogiri}
|
420
414
|
* {RDF::RDFa::Reader::REXML}
|
@@ -422,11 +416,6 @@ Full documentation available on [Rubydoc.info][RDFa doc]
|
|
422
416
|
* {RDF::RDFa::Expansion}
|
423
417
|
* {RDF::RDFa::Writer}
|
424
418
|
|
425
|
-
### Additional vocabularies
|
426
|
-
* {RDF::RDFA}
|
427
|
-
* {RDF::XML}
|
428
|
-
* {RDF::XSI}
|
429
|
-
|
430
419
|
## TODO
|
431
420
|
* Add support for LibXML and REXML bindings, and use the best available
|
432
421
|
* Consider a SAX-based parser for improved performance
|
@@ -438,13 +427,13 @@ Full documentation available on [Rubydoc.info][RDFa doc]
|
|
438
427
|
* [History](file:History.md)
|
439
428
|
* [RDFa 1.1 Core][RDFa 1.1 Core]
|
440
429
|
* [XHTML+RDFa 1.1][XHTML+RDFa 1.1]
|
441
|
-
* [RDFa-test-suite](
|
430
|
+
* [RDFa-test-suite](https://rdfa.info/test-suite/ "RDFa test suite")
|
442
431
|
|
443
432
|
## Author
|
444
|
-
* [Gregg Kellogg](
|
433
|
+
* [Gregg Kellogg](https://github.com/gkellogg) - <https://greggkellogg.net/>
|
445
434
|
|
446
435
|
## Contributors
|
447
|
-
* [Nicholas Humfrey](
|
436
|
+
* [Nicholas Humfrey](https://github.com/njh) - <https://njh.me/>
|
448
437
|
|
449
438
|
## Contributing
|
450
439
|
This repository uses [Git Flow](https://github.com/nvie/gitflow) to mange development and release activity. All submissions _must_ be on a feature branch based on the _develop_ branch to ease staging and integration.
|
@@ -464,27 +453,27 @@ This repository uses [Git Flow](https://github.com/nvie/gitflow) to mange develo
|
|
464
453
|
## License
|
465
454
|
|
466
455
|
This is free and unencumbered public domain software. For more information,
|
467
|
-
see <
|
456
|
+
see <https://unlicense.org/> or the accompanying [UNLICENSE](UNLICENSE) file.
|
468
457
|
|
469
458
|
## FEEDBACK
|
470
459
|
|
471
460
|
* gregg@greggkellogg.net
|
472
|
-
* <
|
473
|
-
* <
|
474
|
-
* <
|
475
|
-
|
476
|
-
[RDF.rb]:
|
477
|
-
[YARD]:
|
478
|
-
[YARD-GS]:
|
479
|
-
[PDD]:
|
480
|
-
[RDFa 1.1 Core]:
|
481
|
-
[RDFa Lite 1.1]:
|
482
|
-
[XHTML+RDFa 1.1]:
|
483
|
-
[HTML+RDFa 1.1]:
|
484
|
-
[RDFa-test-suite]:
|
485
|
-
[Role Attr]:
|
486
|
-
[RDFa doc]:
|
487
|
-
[Haml]:
|
488
|
-
[Turtle]:
|
489
|
-
[Nokogiri]:
|
461
|
+
* <https://rubygems.org/rdf-rdfa>
|
462
|
+
* <https://github.com/ruby-rdf/rdf-rdfa>
|
463
|
+
* <https://lists.w3.org/Archives/Public/public-rdf-ruby/>
|
464
|
+
|
465
|
+
[RDF.rb]: https://rubygems.org/gems/rdf
|
466
|
+
[YARD]: https://yardoc.org/
|
467
|
+
[YARD-GS]: https://rubydoc.info/docs/yard/file/docs/GettingStarted.md
|
468
|
+
[PDD]: https://lists.w3.org/Archives/Public/public-rdf-ruby/2010May/0013.html
|
469
|
+
[RDFa 1.1 Core]: https://www.w3.org/TR/2012/REC-rdfa-core-20120607/ "RDFa 1.1 Core"
|
470
|
+
[RDFa Lite 1.1]: https://www.w3.org/TR/2012/REC-rdfa-lite-20120607/ "RDFa Lite 1.1"
|
471
|
+
[XHTML+RDFa 1.1]: https://www.w3.org/TR/2012/REC-xhtml-rdfa-20120607/ "XHTML+RDFa 1.1"
|
472
|
+
[HTML+RDFa 1.1]: https://www.w3.org/TR/rdfa-in-html/ "HTML+RDFa 1.1"
|
473
|
+
[RDFa-test-suite]: https://rdfa.info/test-suite/ "RDFa test suite"
|
474
|
+
[Role Attr]: https://www.w3.org/TR/role-attribute/ "Role Attribute"
|
475
|
+
[RDFa doc]: https://rubydoc.info/github/ruby-rdf/rdf-rdfa/frames
|
476
|
+
[Haml]: https://haml-lang.com/
|
477
|
+
[Turtle]: https://www.w3.org/TR/2011/WD-turtle-20110809/
|
478
|
+
[Nokogiri]: https://www.nokogiri.org
|
490
479
|
[Nokogumbo]: https://github.com/rubys/nokogumbo/#readme
|
data/UNLICENSE
CHANGED
@@ -21,4 +21,4 @@ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
21
21
|
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
22
|
OTHER DEALINGS IN THE SOFTWARE.
|
23
23
|
|
24
|
-
For more information, please refer to <
|
24
|
+
For more information, please refer to <https://unlicense.org/>
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
3.1.2
|
data/lib/rdf/rdfa.rb
CHANGED
@@ -15,13 +15,13 @@ module RDF
|
|
15
15
|
# end
|
16
16
|
# end
|
17
17
|
#
|
18
|
-
# @see
|
19
|
-
# @see
|
20
|
-
# @see
|
21
|
-
# @see
|
22
|
-
# @see
|
18
|
+
# @see https://rubygems.org/gems/rdf
|
19
|
+
# @see https://www.w3.org/TR/rdfa-syntax/#s_model RDFa 1.0
|
20
|
+
# @see https://www.w3.org/TR/2012/REC-rdfa-core-20120607/
|
21
|
+
# @see https://www.w3.org/TR/2012/CR-xhtml-rdfa-20120313/
|
22
|
+
# @see https://dev.w3.org/html5/rdfa/
|
23
23
|
#
|
24
|
-
# @author [Gregg Kellogg](
|
24
|
+
# @author [Gregg Kellogg](https://greggkellogg.net/)
|
25
25
|
module RDFa
|
26
26
|
require 'rdf/rdfa/format'
|
27
27
|
require 'rdf/rdfa/vocab'
|
data/lib/rdf/rdfa/context.rb
CHANGED
@@ -40,7 +40,7 @@ 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
|
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, {})
|
@@ -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)
|
@@ -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
|
data/lib/rdf/rdfa/context/xml.rb
CHANGED
@@ -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,17 @@ 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
|
+
jsonld: "http://www.w3.org/ns/json-ld#",
|
24
|
+
ldp: "http://www.w3.org/ns/ldp#",
|
20
25
|
ma: "http://www.w3.org/ns/ma-ont#",
|
26
|
+
oa: "http://www.w3.org/ns/oa#",
|
27
|
+
odrl: "http://www.w3.org/ns/odrl/2/",
|
21
28
|
og: "http://ogp.me/ns#",
|
22
29
|
org: "http://www.w3.org/ns/org#",
|
23
30
|
owl: "http://www.w3.org/2002/07/owl#",
|
@@ -34,6 +41,9 @@ class RDF::RDFa::Context
|
|
34
41
|
sioc: "http://rdfs.org/sioc/ns#",
|
35
42
|
skos: "http://www.w3.org/2004/02/skos/core#",
|
36
43
|
skosxl: "http://www.w3.org/2008/05/skos-xl#",
|
44
|
+
sosa: "http://www.w3.org/ns/sosa/",
|
45
|
+
ssn: "http://www.w3.org/ns/ssn/",
|
46
|
+
time: "http://www.w3.org/2006/time#",
|
37
47
|
v: "http://rdf.data-vocabulary.org/#",
|
38
48
|
vcard: "http://www.w3.org/2006/vcard/ns#",
|
39
49
|
void: "http://rdfs.org/ns/void#",
|
@@ -48,7 +58,7 @@ class RDF::RDFa::Context
|
|
48
58
|
license: "http://www.w3.org/1999/xhtml/vocab#license",
|
49
59
|
role: "http://www.w3.org/1999/xhtml/vocab#role",
|
50
60
|
},
|
51
|
-
|
61
|
+
)
|
52
62
|
else
|
53
63
|
find_without_rdfa_1_1(uri)
|
54
64
|
end
|
data/lib/rdf/rdfa/expansion.rb
CHANGED
@@ -12,12 +12,12 @@ module RDF::RDFa
|
|
12
12
|
# Vocabulary expansion uses the built-in reasoner using included vocabularies from RDF.rb.
|
13
13
|
#
|
14
14
|
# @param [RDF::Repository] repository
|
15
|
-
# @see [OWL2 PROFILES](
|
15
|
+
# @see [OWL2 PROFILES](https://www.w3.org/TR/2009/REC-owl2-profiles-20091027/#Reasoning_in_OWL_2_RL_and_RDF_Graphs_using_Rules)
|
16
16
|
def expand(repository)
|
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
|
@@ -45,7 +45,7 @@ module RDF::RDFa
|
|
45
45
|
# Subsequently, remove reference rdfa:Pattern objects.
|
46
46
|
#
|
47
47
|
# @param [RDF::Repository] repository
|
48
|
-
# @see [HTML+RDFa](
|
48
|
+
# @see [HTML+RDFa](https://www.w3.org/TR/rdfa-in-html/#rdfa-reference-folding)
|
49
49
|
def copy_properties(repository)
|
50
50
|
add_debug("expand") {"Repository has #{repository.size} statements"}
|
51
51
|
fold(repository)
|
data/lib/rdf/rdfa/format.rb
CHANGED
@@ -16,7 +16,7 @@ module RDF::RDFa
|
|
16
16
|
# @example Obtaining serialization format file extension mappings
|
17
17
|
# RDF::Format.file_extensions #=> {xhtml: "application/xhtml+xml"}
|
18
18
|
#
|
19
|
-
# @see
|
19
|
+
# @see https://www.w3.org/TR/rdf-testcases/#ntriples
|
20
20
|
class Format < RDF::Format
|
21
21
|
content_encoding 'utf-8'
|
22
22
|
content_type 'text/html;q=0.5',
|
data/lib/rdf/rdfa/reader.rb
CHANGED
@@ -16,15 +16,15 @@ module RDF::RDFa
|
|
16
16
|
# can explicitly override the used implementation by passing in a
|
17
17
|
# `:library` option to `Reader.new` or `Reader.open`.
|
18
18
|
#
|
19
|
-
# [Nokogiri]:
|
19
|
+
# [Nokogiri]: https://nokogiri.org/
|
20
20
|
#
|
21
21
|
# Based on processing rules described here:
|
22
|
-
# @see
|
23
|
-
# @see
|
24
|
-
# @see
|
25
|
-
# @see
|
22
|
+
# @see https://www.w3.org/TR/rdfa-syntax/#s_model RDFa 1.0
|
23
|
+
# @see https://www.w3.org/TR/2012/REC-rdfa-core-20120607/
|
24
|
+
# @see https://www.w3.org/TR/2012/CR-xhtml-rdfa-20120313/
|
25
|
+
# @see https://dev.w3.org/html5/rdfa/
|
26
26
|
#
|
27
|
-
# @author [Gregg Kellogg](
|
27
|
+
# @author [Gregg Kellogg](https://greggkellogg.net/)
|
28
28
|
class Reader < RDF::Reader
|
29
29
|
format Format
|
30
30
|
include Expansion
|
@@ -46,9 +46,9 @@ module RDF::RDFa
|
|
46
46
|
}
|
47
47
|
|
48
48
|
# This expression matches an NCName as defined in
|
49
|
-
# [XML-NAMES](
|
49
|
+
# [XML-NAMES](https://www.w3.org/TR/2009/REC-xml-names-20091208/#NT-NCName)
|
50
50
|
#
|
51
|
-
# @see
|
51
|
+
# @see https://www.w3.org/TR/2009/REC-xml-names-20091208/#NT-NCName
|
52
52
|
NC_REGEXP = Regexp.new(
|
53
53
|
%{^
|
54
54
|
( [a-zA-Z_]
|
@@ -61,11 +61,11 @@ module RDF::RDFa
|
|
61
61
|
Regexp::EXTENDED)
|
62
62
|
|
63
63
|
# This expression matches an term as defined in
|
64
|
-
# [RDFA-CORE](
|
64
|
+
# [RDFA-CORE](https://www.w3.org/TR/2012/REC-rdfa-core-20120607/#s_terms)
|
65
65
|
#
|
66
66
|
# For the avoidance of doubt, this definition means a 'term'
|
67
67
|
# in RDFa is an XML NCName that also permits slash as a non-leading character.
|
68
|
-
# @see
|
68
|
+
# @see https://www.w3.org/TR/2012/REC-rdfa-core-20120607/#s_terms
|
69
69
|
TERM_REGEXP = Regexp.new(
|
70
70
|
%{^
|
71
71
|
(?!\\\\u0301) # ́ is a non-spacing acute accent.
|
@@ -245,7 +245,7 @@ module RDF::RDFa
|
|
245
245
|
|
246
246
|
##
|
247
247
|
# RDFa Reader options
|
248
|
-
# @see
|
248
|
+
# @see https://www.rubydoc.info/github/ruby-rdf/rdf/RDF/Reader#options-class_method
|
249
249
|
def self.options
|
250
250
|
super + [
|
251
251
|
RDF::CLI::Option.new(
|
@@ -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
|
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,7 +327,7 @@ 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
332
|
parse_lib = if @library == :nokogiri && @host_language == :html5
|
333
333
|
begin
|
@@ -344,7 +344,7 @@ module RDF::RDFa
|
|
344
344
|
add_info(@doc, "version = #{@version}, host_language = #{@host_language}, library = #{parse_lib}, rdfagraph = #{@options[:rdfagraph].inspect}, expand = #{@options[:vocab_expansion]}")
|
345
345
|
|
346
346
|
begin
|
347
|
-
initialize_xml(input, options)
|
347
|
+
initialize_xml(input, **options)
|
348
348
|
rescue
|
349
349
|
add_error(nil, "Malformed document: #{$!.message}")
|
350
350
|
end
|
@@ -381,6 +381,38 @@ module RDF::RDFa
|
|
381
381
|
end
|
382
382
|
end
|
383
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
|
+
|
384
416
|
##
|
385
417
|
# Iterates the given block for each RDF statement in the input.
|
386
418
|
#
|
@@ -400,52 +432,9 @@ module RDF::RDFa
|
|
400
432
|
# parse
|
401
433
|
parse_whole_document(@doc, RDF::URI(base_uri))
|
402
434
|
|
403
|
-
def extract_script(el, input, type, options, &block)
|
404
|
-
add_debug(el, "script element of type #{type}")
|
405
|
-
begin
|
406
|
-
# Formats don't exist unless they've been required
|
407
|
-
case type.to_s
|
408
|
-
when 'application/csvm+json' then require 'rdf/tabular'
|
409
|
-
when 'application/ld+json' then require 'json/ld'
|
410
|
-
when 'application/rdf+xml' then require 'rdf/rdfxml'
|
411
|
-
when 'text/ntriples' then require 'rdf/ntriples'
|
412
|
-
when 'text/turtle' then require 'rdf/turtle'
|
413
|
-
end
|
414
|
-
rescue LoadError
|
415
|
-
end
|
416
|
-
|
417
|
-
if reader = RDF::Reader.for(content_type: type.to_s)
|
418
|
-
add_debug(el, "=> reader #{reader.to_sym}")
|
419
|
-
# Wrap input in a RemoteDocument with appropriate content-type and base
|
420
|
-
doc = if input.is_a?(String)
|
421
|
-
RDF::Util::File::RemoteDocument.new(input,
|
422
|
-
options.merge(
|
423
|
-
content_type: type.to_s,
|
424
|
-
base_uri: base_uri
|
425
|
-
))
|
426
|
-
else
|
427
|
-
input
|
428
|
-
end
|
429
|
-
reader.new(doc, options).each(&block)
|
430
|
-
else
|
431
|
-
add_debug(el, "=> no reader found")
|
432
|
-
end
|
433
|
-
end
|
434
|
-
|
435
435
|
# Look for Embedded RDF/XML
|
436
436
|
unless @root.xpath("//rdf:RDF", "rdf" => "http://www.w3.org/1999/02/22-rdf-syntax-ns#").empty?
|
437
|
-
extract_script(@root, @doc, "application/rdf+xml",
|
438
|
-
@repository << statement
|
439
|
-
end
|
440
|
-
end
|
441
|
-
|
442
|
-
# Look for Embedded scripts
|
443
|
-
@root.css("script[type]").each do |el|
|
444
|
-
type = el.attribute("type")
|
445
|
-
|
446
|
-
text = el.inner_html.sub(%r(\A\s*\<!\[CDATA\[)m, '').sub(%r(\]\]>\s*\Z)m, '')
|
447
|
-
|
448
|
-
extract_script(el, text, type, @options) do |statement|
|
437
|
+
extract_script(@root, @doc, "application/rdf+xml", **@options.merge(base_uri: base_uri)) do |statement|
|
449
438
|
@repository << statement
|
450
439
|
end
|
451
440
|
end
|
@@ -455,7 +444,7 @@ module RDF::RDFa
|
|
455
444
|
begin
|
456
445
|
require 'rdf/microdata'
|
457
446
|
add_debug(@doc, "process microdata")
|
458
|
-
@repository << RDF::Microdata::Reader.new(@doc, options)
|
447
|
+
@repository << RDF::Microdata::Reader.new(@doc, **options)
|
459
448
|
rescue LoadError
|
460
449
|
add_debug(@doc, "microdata detected, not processed")
|
461
450
|
end
|
@@ -775,6 +764,7 @@ module RDF::RDFa
|
|
775
764
|
rev
|
776
765
|
role
|
777
766
|
src
|
767
|
+
type
|
778
768
|
typeof
|
779
769
|
value
|
780
770
|
vocab
|
@@ -830,6 +820,15 @@ module RDF::RDFa
|
|
830
820
|
language = nil if language.to_s.empty?
|
831
821
|
add_debug(element) {"HTML5 [3.2.3.3] lang: #{language.inspect}"} if language
|
832
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
|
+
|
833
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.
|
834
833
|
if [:html5, :xhtml5].include?(@host_language) && attrs[:property] && (attrs[:rel] || attrs[:rev])
|
835
834
|
old_rel, old_rev = attrs[:rel], attrs[:rev]
|
@@ -1392,13 +1391,13 @@ module RDF::RDFa
|
|
1392
1391
|
end
|
1393
1392
|
|
1394
1393
|
# space-separated TERMorCURIEorAbsIRI or SafeCURIEorCURIEorIRI
|
1395
|
-
def process_uris(element, value, evaluation_context, base, options)
|
1394
|
+
def process_uris(element, value, evaluation_context, base, **options)
|
1396
1395
|
return [] if value.to_s.empty?
|
1397
1396
|
add_debug(element) {"process_uris: #{value}"}
|
1398
|
-
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
|
1399
1398
|
end
|
1400
1399
|
|
1401
|
-
def process_uri(element, value, evaluation_context, base, options
|
1400
|
+
def process_uri(element, value, evaluation_context, base, **options)
|
1402
1401
|
return if value.nil?
|
1403
1402
|
restrictions = options[:restrictions]
|
1404
1403
|
add_debug(element) {"process_uri: #{value}, restrictions = #{restrictions.inspect}"}
|
@@ -1419,7 +1418,7 @@ module RDF::RDFa
|
|
1419
1418
|
# TERMorCURIEorAbsIRI
|
1420
1419
|
# If the value is an NCName, then it is evaluated as a term according to General Use of Terms in
|
1421
1420
|
# Attributes. Note that this step may mean that the value is to be ignored.
|
1422
|
-
uri = process_term(element, value.to_s, options)
|
1421
|
+
uri = process_term(element, value.to_s, **options)
|
1423
1422
|
add_debug(element) {"process_uri: #{value} => term => #{uri ? uri.to_base : 'nil'}"}
|
1424
1423
|
uri
|
1425
1424
|
else
|
@@ -1458,7 +1457,7 @@ module RDF::RDFa
|
|
1458
1457
|
end
|
1459
1458
|
|
1460
1459
|
# [7.4.3] General Use of Terms in Attributes
|
1461
|
-
def process_term(element, value, options)
|
1460
|
+
def process_term(element, value, **options)
|
1462
1461
|
if options[:vocab]
|
1463
1462
|
# If there is a local default vocabulary, the IRI is obtained by concatenating that value and the term
|
1464
1463
|
return uri(options[:vocab] + value)
|