rdf-trix 2.0.0.beta → 3.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/AUTHORS +1 -0
- data/README.md +116 -33
- data/UNLICENSE +1 -1
- data/VERSION +1 -1
- data/etc/doap.xml +36 -41
- data/lib/rdf/trix.rb +6 -6
- data/lib/rdf/trix/format.rb +1 -1
- data/lib/rdf/trix/reader.rb +95 -12
- data/lib/rdf/trix/reader/libxml.rb +27 -34
- data/lib/rdf/trix/reader/nokogiri.rb +24 -31
- data/lib/rdf/trix/reader/rexml.rb +24 -31
- data/lib/rdf/trix/writer.rb +56 -21
- data/lib/rdf/trix/writer/nokogiri.rb +8 -3
- data/lib/rdf/trix/writer/rexml.rb +8 -3
- metadata +67 -39
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5af9119669a69395e1a032d9c55189e0abd15c819db757fe0cd6847a8fb4ad08
|
4
|
+
data.tar.gz: 3037f0c3d071d241ee0cf76f3326287788f26db1227f7ff501eed2d037477d7a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a506c535c9013cb7618b19d3ea5c4b159afe1bba68605da231d7a75a3c66e14fd4b03f9a6e9195747a502f8a55bef1877e629dbbc878b5e1c7525418f3b5ef0
|
7
|
+
data.tar.gz: c815a1e493b678f20067c59aef680c0b266f9890be53457d111b606f8ede623ceecde339be979024cadd2dc97b36139c9ab200af80ad41bca8ec625cb2ddcbb4
|
data/AUTHORS
CHANGED
data/README.md
CHANGED
@@ -1,40 +1,121 @@
|
|
1
|
-
TriX Support for RDF.rb
|
2
|
-
=======================
|
1
|
+
# TriX Support for RDF.rb
|
3
2
|
|
4
|
-
|
5
|
-
[TriX][], an XML-based RDF serialization format developed by HP Labs and
|
6
|
-
Nokia.
|
3
|
+
[TriX][] reader/writer for [RDF.rb][RDF.rb] .
|
7
4
|
|
8
|
-
|
9
|
-
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/rdf-trix.png)](https://badge.fury.io/rb/rdf-trix)
|
6
|
+
[![Build Status](https://github.com/ruby-rdf/rdf-trix/workflows/CI/badge.svg?branch=develop)](https://github.com/ruby-rdf/rdf-trix/actions?query=workflow%3ACI)
|
7
|
+
[![Coverage Status](https://coveralls.io/repos/ruby-rdf/rdf-trix/badge.svg?branch=develop)](https://coveralls.io/github/ruby-rdf/rdf-trix?branch=develop)
|
8
|
+
[![Gitter chat](https://badges.gitter.im/ruby-rdf/rdf.png)](https://gitter.im/ruby-rdf/rdf)
|
10
9
|
|
11
|
-
|
12
|
-
[
|
10
|
+
## Description
|
11
|
+
This is a [Ruby][] implementation of a [TriX][] reader and writer for [RDF.rb][]. TriX is an XML-based RDF serialization format developed by HP Labs and Nokia.
|
13
12
|
|
14
|
-
|
15
|
-
|
13
|
+
## Features
|
14
|
+
RDF::TriX parses [TriX][] into statements or quads. It also serializes to TriX.
|
15
|
+
|
16
|
+
Install with `gem install rdf-trix`
|
17
|
+
|
18
|
+
* 100% free and unencumbered [public domain](https://unlicense.org/) software.
|
19
|
+
* Implements a complete parser and serializer for [TriX][].
|
20
|
+
* Compatible with Ruby >= 2.4, and JRuby 1.7+.
|
21
|
+
|
22
|
+
### Support for xml:base
|
23
|
+
|
24
|
+
The TriX reader natively supports `xml:base` in the top-level element without the need for an XSLT. This allows values of a `uri` element to be relative URIs and resolved against that base. The base can also be specified as an option to the reader.
|
25
|
+
|
26
|
+
For example:
|
27
|
+
|
28
|
+
<TriX xmlns="http://www.w3.org/2004/03/trix/trix-1/"
|
29
|
+
xml:base="http://example.org/">
|
30
|
+
<graph>
|
31
|
+
<uri>graph1</uri>
|
32
|
+
<triple>
|
33
|
+
<uri>Bob</uri>
|
34
|
+
<uri>wife</uri>
|
35
|
+
<uri>Mary</uri>
|
36
|
+
</triple>
|
37
|
+
<triple>
|
38
|
+
<uri>Bob</uri>
|
39
|
+
<uri>name</uri>
|
40
|
+
<plainLiteral>Bob</plainLiteral>
|
41
|
+
</triple>
|
42
|
+
<triple>
|
43
|
+
<uri>Mary</uri>
|
44
|
+
<uri>age</uri>
|
45
|
+
<typedLiteral datatype="http://www.w3.org/2001/XMLSchema#integer">32</typedLiteral>
|
46
|
+
</triple>
|
47
|
+
</graph>
|
48
|
+
</TriX>
|
49
|
+
|
50
|
+
### RDF-star
|
51
|
+
|
52
|
+
Both reader and writer include provisional support for [RDF-star][].
|
53
|
+
|
54
|
+
Internally, an `RDF::Statement` is treated as another resource, along with `RDF::URI` and `RDF::Node`, which allows an `RDF::Statement` to have a `#subject` or `#object` which is also an `RDF::Statement`.
|
55
|
+
|
56
|
+
RDF-star is supported by allowing a `triple` element to contain another `triple` as either or both the _subject_ or _object_.
|
57
|
+
|
58
|
+
Note that this requires the `rdfstar` option to be se.
|
59
|
+
|
60
|
+
**Note: This feature is subject to change or elimination as the standards process progresses.**
|
61
|
+
|
62
|
+
For example:
|
63
|
+
|
64
|
+
<TriX xmlns="http://www.w3.org/2004/03/trix/trix-1/">
|
65
|
+
<graph>
|
66
|
+
<triple>
|
67
|
+
<triple>
|
68
|
+
<uri>http://example/s1</uri>
|
69
|
+
<uri>http://example/p1</uri>
|
70
|
+
<uri>http://example/o1</uri>
|
71
|
+
</triple>
|
72
|
+
<uri>http://example/p</uri>
|
73
|
+
<uri>http://example/o</uri>
|
74
|
+
</triple>
|
75
|
+
</graph>
|
76
|
+
</TriX>
|
77
|
+
|
78
|
+
## Usage
|
79
|
+
Instantiate a reader from a local file:
|
80
|
+
|
81
|
+
repo = RDF::Repository.load("etc/doap.trix", :format => :trix)
|
82
|
+
|
83
|
+
Define `@base` and `@prefix` definitions, and use for serialization using `:base_uri` an `:prefixes` options.
|
84
|
+
|
85
|
+
Canonicalize and validate using `:canonicalize` and `:validate` options.
|
86
|
+
|
87
|
+
Write a repository to a file:
|
88
|
+
|
89
|
+
RDF::TriX::Writer.open("etc/test.trix") do |writer|
|
90
|
+
writer << repo
|
91
|
+
end
|
92
|
+
|
93
|
+
## Dependencies
|
94
|
+
* [RDF.rb](https://rubygems.org/gems/rdf) (~> 3.1)
|
95
|
+
* Soft dependency on [Nokogiri](https://rubygems.org/gems/nokogiri) (>= 1.10)
|
96
|
+
* Soft dependency on [Libxml-Ruby](https://rubygems.org/gems/libxml-ruby) (>= 3.0)
|
97
|
+
|
98
|
+
## Documentation
|
16
99
|
|
17
100
|
* {RDF::TriX}
|
18
101
|
* {RDF::TriX::Format}
|
19
102
|
* {RDF::TriX::Reader}
|
20
103
|
* {RDF::TriX::Writer}
|
21
104
|
|
22
|
-
Dependencies
|
23
|
-
------------
|
105
|
+
## Dependencies
|
24
106
|
|
25
|
-
* [RDF.rb](
|
26
|
-
[Nokogiri](
|
107
|
+
* [RDF.rb](https://rubygems.org/gems/rdf) (~> 3.1)
|
108
|
+
[Nokogiri](https://rubygems.org/gems/nokogiri) (~> 1.10)
|
109
|
+
[LibXML](https://rubygems.org/gems/libxml) (>= 3.0)
|
27
110
|
|
28
|
-
Installation
|
29
|
-
------------
|
111
|
+
## Installation
|
30
112
|
|
31
|
-
The recommended installation method is via [RubyGems](
|
113
|
+
The recommended installation method is via [RubyGems](https://rubygems.org/).
|
32
114
|
To install the latest official release of the `RDF::TriX` gem, do:
|
33
115
|
|
34
116
|
% [sudo] gem install rdf-trix
|
35
117
|
|
36
|
-
Download
|
37
|
-
--------
|
118
|
+
## Download
|
38
119
|
|
39
120
|
To get a local working copy of the development repository, do:
|
40
121
|
|
@@ -43,20 +124,18 @@ To get a local working copy of the development repository, do:
|
|
43
124
|
Alternatively, download the latest development version as a tarball as
|
44
125
|
follows:
|
45
126
|
|
46
|
-
% wget
|
127
|
+
% wget https://github.com/ruby-rdf/rdf-trix/tarball/master
|
47
128
|
|
48
|
-
Mailing List
|
49
|
-
------------
|
129
|
+
## Mailing List
|
50
130
|
|
51
|
-
* <
|
131
|
+
* <https://lists.w3.org/Archives/Public/public-rdf-ruby/>
|
52
132
|
|
53
|
-
|
54
|
-
------
|
133
|
+
## Authors
|
55
134
|
|
56
|
-
* [Arto Bendiken](
|
135
|
+
* [Arto Bendiken](https://github.com/artob) - <https://ar.to/>
|
136
|
+
* [Gregg Kellogg](https://github.com/gkellogg) - <https://greggkellogg.net/>
|
57
137
|
|
58
|
-
Contributors
|
59
|
-
------------
|
138
|
+
# Contributors
|
60
139
|
|
61
140
|
Refer to the accompanying {file:CREDITS} file.
|
62
141
|
|
@@ -77,12 +156,16 @@ This repository uses [Git Flow](https://github.com/nvie/gitflow) to mange develo
|
|
77
156
|
enough, be assured we will eventually add you in there.
|
78
157
|
* Do note that in order for us to merge any non-trivial changes (as a rule
|
79
158
|
of thumb, additions larger than about 15 lines of code), we need an
|
80
|
-
explicit [public domain dedication][PDD] on record from you
|
159
|
+
explicit [public domain dedication][PDD] on record from you,
|
160
|
+
which you will be asked to agree to on the first commit to a repo within the organization.
|
161
|
+
Note that the agreement applies to all repos in the [Ruby RDF](https://github.com/ruby-rdf/) organization.
|
81
162
|
|
82
163
|
## License
|
83
164
|
|
84
165
|
This is free and unencumbered public domain software. For more information,
|
85
|
-
see <
|
166
|
+
see <https://unlicense.org/> or the accompanying {file:UNLICENSE} file.
|
86
167
|
|
87
|
-
[RDF.rb]:
|
88
|
-
[TriX]:
|
168
|
+
[RDF.rb]: https://rubygems.org/gems/rdf/
|
169
|
+
[TriX]: https://www.hpl.hp.com/techreports/2004/HPL-2004-56.html
|
170
|
+
[PDD]: https://unlicense.org/#unlicensing-contributions
|
171
|
+
[RDF-star]: https://w3c.github.io/rdf-star/rdf-star-cg-spec.html
|
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.1
|
data/etc/doap.xml
CHANGED
@@ -2,114 +2,109 @@
|
|
2
2
|
<TriX xmlns="http://www.w3.org/2004/03/trix/trix-1/">
|
3
3
|
<graph>
|
4
4
|
<triple>
|
5
|
-
<uri>
|
5
|
+
<uri>https://rubygems.org/gems/rdf-trix</uri>
|
6
6
|
<uri>http://www.w3.org/1999/02/22-rdf-syntax-ns#type</uri>
|
7
7
|
<uri>http://usefulinc.com/ns/doap#Project</uri>
|
8
8
|
</triple>
|
9
9
|
<triple>
|
10
|
-
<uri>
|
10
|
+
<uri>https://rubygems.org/gems/rdf-trix</uri>
|
11
11
|
<uri>http://usefulinc.com/ns/doap#name</uri>
|
12
12
|
<plainLiteral>RDF::TriX</plainLiteral>
|
13
13
|
</triple>
|
14
14
|
<triple>
|
15
|
-
<uri>
|
15
|
+
<uri>https://rubygems.org/gems/rdf-trix</uri>
|
16
16
|
<uri>http://usefulinc.com/ns/doap#homepage</uri>
|
17
|
-
<uri>
|
17
|
+
<uri>https://github.com/ruby-rdf/rdf-trix/</uri>
|
18
18
|
</triple>
|
19
19
|
<triple>
|
20
|
-
<uri>
|
20
|
+
<uri>https://rubygems.org/gems/rdf-trix</uri>
|
21
21
|
<uri>http://usefulinc.com/ns/doap#license</uri>
|
22
|
-
<uri>
|
22
|
+
<uri>https://unlicense.org/1.0/</uri>
|
23
23
|
</triple>
|
24
24
|
<triple>
|
25
|
-
<uri>
|
25
|
+
<uri>https://rubygems.org/gems/rdf-trix</uri>
|
26
26
|
<uri>http://usefulinc.com/ns/doap#shortdesc</uri>
|
27
27
|
<plainLiteral xml:lang="en">TriX support for RDF.rb.</plainLiteral>
|
28
28
|
</triple>
|
29
29
|
<triple>
|
30
|
-
<uri>
|
30
|
+
<uri>https://rubygems.org/gems/rdf-trix</uri>
|
31
31
|
<uri>http://usefulinc.com/ns/doap#description</uri>
|
32
|
-
<plainLiteral xml:lang="en">RDF
|
32
|
+
<plainLiteral xml:lang="en">RDF::TriX is an TriX reader/writer for the RDF.rb library suite.</plainLiteral>
|
33
33
|
</triple>
|
34
34
|
<triple>
|
35
|
-
<uri>
|
35
|
+
<uri>https://rubygems.org/gems/rdf-trix</uri>
|
36
36
|
<uri>http://usefulinc.com/ns/doap#created</uri>
|
37
37
|
<plainLiteral>2010-02-02</plainLiteral>
|
38
38
|
</triple>
|
39
39
|
<triple>
|
40
|
-
<uri>
|
41
|
-
<uri>http://usefulinc.com/ns/doap#
|
40
|
+
<uri>https://rubygems.org/gems/rdf-trix</uri>
|
41
|
+
<uri>http://usefulinc.com/ns/doap#programming-language</uri>
|
42
42
|
<plainLiteral>Ruby</plainLiteral>
|
43
43
|
</triple>
|
44
44
|
<triple>
|
45
|
-
<uri>
|
45
|
+
<uri>https://rubygems.org/gems/rdf-trix</uri>
|
46
46
|
<uri>http://usefulinc.com/ns/doap#download-page</uri>
|
47
|
-
<uri>
|
47
|
+
<uri>https://rubygems.org/gems/rdf-trix</uri>
|
48
48
|
</triple>
|
49
49
|
<triple>
|
50
|
-
<uri>
|
50
|
+
<uri>https://rubygems.org/gems/rdf-trix</uri>
|
51
51
|
<uri>http://usefulinc.com/ns/doap#bug-database</uri>
|
52
|
-
<uri>
|
52
|
+
<uri>https://github.com/ruby-rdf/rdf-trix/issues</uri>
|
53
53
|
</triple>
|
54
54
|
<triple>
|
55
|
-
<uri>
|
55
|
+
<uri>https://rubygems.org/gems/rdf-trix</uri>
|
56
56
|
<uri>http://usefulinc.com/ns/doap#blog</uri>
|
57
|
-
<uri>
|
57
|
+
<uri>https://greggkellogg.net/</uri>
|
58
58
|
</triple>
|
59
59
|
<triple>
|
60
|
-
<uri>
|
61
|
-
<uri>http://usefulinc.com/ns/doap#
|
62
|
-
<uri>
|
60
|
+
<uri>https://rubygems.org/gems/rdf-trix</uri>
|
61
|
+
<uri>http://usefulinc.com/ns/doap#developer</uri>
|
62
|
+
<uri>https://ar.to/#self</uri>
|
63
63
|
</triple>
|
64
64
|
<triple>
|
65
|
-
<uri>
|
65
|
+
<uri>https://rubygems.org/gems/rdf-trix</uri>
|
66
66
|
<uri>http://usefulinc.com/ns/doap#developer</uri>
|
67
|
-
<uri>
|
67
|
+
<uri>https://greggkellogg.net/</uri>
|
68
68
|
</triple>
|
69
69
|
<triple>
|
70
|
-
<uri>
|
70
|
+
<uri>https://rubygems.org/gems/rdf-trix</uri>
|
71
71
|
<uri>http://usefulinc.com/ns/doap#maintainer</uri>
|
72
|
-
<uri>
|
72
|
+
<uri>https://greggkellogg.net/</uri>
|
73
73
|
</triple>
|
74
74
|
<triple>
|
75
|
-
<uri>
|
75
|
+
<uri>https://rubygems.org/gems/rdf-trix</uri>
|
76
76
|
<uri>http://usefulinc.com/ns/doap#documenter</uri>
|
77
|
-
<uri>
|
77
|
+
<uri>https://ar.to/#self</uri>
|
78
78
|
</triple>
|
79
79
|
<triple>
|
80
|
-
<uri>
|
80
|
+
<uri>https://rubygems.org/gems/rdf-trix</uri>
|
81
81
|
<uri>http://xmlns.com/foaf/0.1/maker</uri>
|
82
|
-
<uri>
|
82
|
+
<uri>https://ar.to/#self</uri>
|
83
83
|
</triple>
|
84
84
|
<triple>
|
85
|
-
<uri>
|
85
|
+
<uri>https://rubygems.org/gems/rdf-trix</uri>
|
86
86
|
<uri>http://purl.org/dc/terms/creator</uri>
|
87
|
-
<uri>
|
87
|
+
<uri>https://ar.to/#self</uri>
|
88
88
|
</triple>
|
89
89
|
<triple>
|
90
|
-
<uri>
|
90
|
+
<uri>https://ar.to/#self</uri>
|
91
91
|
<uri>http://www.w3.org/1999/02/22-rdf-syntax-ns#type</uri>
|
92
92
|
<uri>http://xmlns.com/foaf/0.1/Person</uri>
|
93
93
|
</triple>
|
94
94
|
<triple>
|
95
|
-
<uri>
|
95
|
+
<uri>https://ar.to/#self</uri>
|
96
96
|
<uri>http://xmlns.com/foaf/0.1/name</uri>
|
97
97
|
<plainLiteral>Arto Bendiken</plainLiteral>
|
98
98
|
</triple>
|
99
99
|
<triple>
|
100
|
-
<uri>
|
100
|
+
<uri>https://ar.to/#self</uri>
|
101
101
|
<uri>http://xmlns.com/foaf/0.1/mbox</uri>
|
102
102
|
<uri>mailto:arto@bendiken.net</uri>
|
103
103
|
</triple>
|
104
104
|
<triple>
|
105
|
-
<uri>
|
105
|
+
<uri>https://ar.to/#self</uri>
|
106
106
|
<uri>http://xmlns.com/foaf/0.1/made</uri>
|
107
|
-
<uri>
|
108
|
-
</triple>
|
109
|
-
<triple>
|
110
|
-
<uri>http://ar.to/#self</uri>
|
111
|
-
<uri>http://www.w3.org/2000/01/rdf-schema#isDefinedBy</uri>
|
112
|
-
<uri>http://datagraph.org/bendiken/foaf</uri>
|
107
|
+
<uri>https://rubygems.org/gems/rdf-trix</uri>
|
113
108
|
</triple>
|
114
109
|
</graph>
|
115
110
|
</TriX>
|
data/lib/rdf/trix.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'rdf'
|
1
|
+
require 'rdf'
|
2
2
|
|
3
3
|
module RDF
|
4
4
|
##
|
@@ -21,12 +21,12 @@ module RDF
|
|
21
21
|
# end
|
22
22
|
# end
|
23
23
|
#
|
24
|
-
# @see
|
25
|
-
# @see
|
26
|
-
# @see
|
27
|
-
# @see
|
24
|
+
# @see https://rubygems.org/gems/rdf
|
25
|
+
# @see https://www.w3.org/2004/03/trix/
|
26
|
+
# @see https://www.hpl.hp.com/techreports/2004/HPL-2004-56.pdf
|
27
|
+
# @see https://swdev.nokia.com/trix/trix.html
|
28
28
|
#
|
29
|
-
# @author [Arto Bendiken](
|
29
|
+
# @author [Arto Bendiken](https://ar.to/)
|
30
30
|
module TriX
|
31
31
|
require 'rdf/trix/format'
|
32
32
|
autoload :Reader, 'rdf/trix/reader'
|
data/lib/rdf/trix/format.rb
CHANGED
@@ -12,7 +12,7 @@ module RDF::TriX
|
|
12
12
|
# RDF::Format.for(:file_extension => "xml")
|
13
13
|
# RDF::Format.for(:content_type => "application/trix")
|
14
14
|
#
|
15
|
-
# @see
|
15
|
+
# @see https://www.w3.org/2004/03/trix/
|
16
16
|
class Format < RDF::Format
|
17
17
|
content_type 'application/trix', :extension => :xml
|
18
18
|
content_encoding 'utf-8'
|
data/lib/rdf/trix/reader.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'rdf/xsd'
|
2
|
+
|
1
3
|
module RDF::TriX
|
2
4
|
##
|
3
5
|
# TriX parser.
|
@@ -8,9 +10,9 @@ module RDF::TriX
|
|
8
10
|
# can explicitly override the used implementation by passing in a
|
9
11
|
# `:library` option to `Reader.new` or `Reader.open`.
|
10
12
|
#
|
11
|
-
# [REXML]:
|
12
|
-
# [LibXML]:
|
13
|
-
# [Nokogiri]:
|
13
|
+
# [REXML]: https://www.germane-software.com/software/rexml/
|
14
|
+
# [LibXML]: https://rubygems.org/gems/libxml-ruby/
|
15
|
+
# [Nokogiri]: https://nokogiri.org/
|
14
16
|
#
|
15
17
|
# @example Loading TriX parsing support
|
16
18
|
# require 'rdf/trix'
|
@@ -46,7 +48,7 @@ module RDF::TriX
|
|
46
48
|
# end
|
47
49
|
# end
|
48
50
|
#
|
49
|
-
# @see
|
51
|
+
# @see https://www.w3.org/2004/03/trix/
|
50
52
|
class Reader < RDF::Reader
|
51
53
|
format RDF::TriX::Format
|
52
54
|
|
@@ -56,6 +58,12 @@ module RDF::TriX
|
|
56
58
|
# @return [Module]
|
57
59
|
attr_reader :implementation
|
58
60
|
|
61
|
+
##
|
62
|
+
# Returns the Base URI as provided, or found from xml:base
|
63
|
+
#
|
64
|
+
# @return [RDF::URI]
|
65
|
+
attr_reader :base_uri
|
66
|
+
|
59
67
|
##
|
60
68
|
# Initializes the TriX reader instance.
|
61
69
|
#
|
@@ -63,10 +71,12 @@ module RDF::TriX
|
|
63
71
|
# @param [Hash{Symbol => Object}] options
|
64
72
|
# any additional options (see `RDF::Reader#initialize`)
|
65
73
|
# @option options [Symbol] :library (:nokogiri, :libxml, or :rexml)
|
74
|
+
# @option options [#to_s] :base_uri (nil)
|
75
|
+
# the base URI to use when resolving relative URIs
|
66
76
|
# @yield [reader] `self`
|
67
77
|
# @yieldparam [RDF::Reader] reader
|
68
78
|
# @yieldreturn [void] ignored
|
69
|
-
def initialize(input = $stdin, options
|
79
|
+
def initialize(input = $stdin, **options, &block)
|
70
80
|
super do
|
71
81
|
@library = case options[:library]
|
72
82
|
when nil
|
@@ -97,7 +107,7 @@ module RDF::TriX
|
|
97
107
|
self.extend(@implementation)
|
98
108
|
|
99
109
|
begin
|
100
|
-
initialize_xml(options)
|
110
|
+
initialize_xml(input, **options)
|
101
111
|
rescue
|
102
112
|
log_error("Malformed document: #{$!.message}")
|
103
113
|
end
|
@@ -111,6 +121,47 @@ module RDF::TriX
|
|
111
121
|
end
|
112
122
|
end
|
113
123
|
|
124
|
+
##
|
125
|
+
# @private
|
126
|
+
# @see RDF::Reader#each_graph
|
127
|
+
def each_graph(&block)
|
128
|
+
if block_given?
|
129
|
+
base = read_base
|
130
|
+
@base_uri = base_uri ? base : base_uri.join(base)
|
131
|
+
find_graphs do |graph_element|
|
132
|
+
graph_name = read_graph(graph_element)
|
133
|
+
graph_name = base_uri.join(graph_name) if
|
134
|
+
base_uri && graph_name && graph_name.relative?
|
135
|
+
graph = RDF::Graph.new(graph_name: graph_name)
|
136
|
+
read_statements(graph_element) { |statement| graph << statement }
|
137
|
+
block.call(graph)
|
138
|
+
end
|
139
|
+
|
140
|
+
if validate? && log_statistics[:error]
|
141
|
+
raise RDF::ReaderError, "Errors found during processing"
|
142
|
+
end
|
143
|
+
end
|
144
|
+
enum_graph
|
145
|
+
end
|
146
|
+
|
147
|
+
##
|
148
|
+
# @private
|
149
|
+
# @see RDF::Reader#each_statement
|
150
|
+
def each_statement(&block)
|
151
|
+
if block_given?
|
152
|
+
base = read_base
|
153
|
+
@base_uri = base_uri ? base_uri.join(base) : base
|
154
|
+
find_graphs do |graph_element|
|
155
|
+
read_statements(graph_element, &block)
|
156
|
+
end
|
157
|
+
|
158
|
+
if validate? && log_statistics[:error]
|
159
|
+
raise RDF::ReaderError, "Errors found during processing"
|
160
|
+
end
|
161
|
+
end
|
162
|
+
enum_statement
|
163
|
+
end
|
164
|
+
|
114
165
|
##
|
115
166
|
# @private
|
116
167
|
# @see RDF::Reader#each_triple
|
@@ -135,30 +186,62 @@ module RDF::TriX
|
|
135
186
|
enum_quad
|
136
187
|
end
|
137
188
|
|
189
|
+
##
|
190
|
+
# Yield each statement from a graph
|
191
|
+
#
|
192
|
+
# @param [Object] element
|
193
|
+
# @yield statement
|
194
|
+
# @yieldparam [RDF::Statement] statement
|
195
|
+
def read_statements(graph_element, &block)
|
196
|
+
graph_name = read_graph(graph_element)
|
197
|
+
graph_name = base_uri.join(graph_name) if
|
198
|
+
base_uri && graph_name && graph_name.relative?
|
199
|
+
triple_elements(graph_element).each do |triple_element|
|
200
|
+
block.call(read_triple(triple_element, graph_name: graph_name))
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
##
|
205
|
+
# Read a <triple>
|
206
|
+
# @param [Hash{String => Object}] element
|
207
|
+
# @return [RDF::Statement] statement
|
208
|
+
def read_triple(element, graph_name: nil)
|
209
|
+
terms = element_elements(element)[0..2].map do |element|
|
210
|
+
parse_element(element.name, element, element_content(element))
|
211
|
+
end
|
212
|
+
RDF::Statement(*terms, graph_name: graph_name)
|
213
|
+
end
|
214
|
+
|
138
215
|
##
|
139
216
|
# Returns the RDF value of the given TriX element.
|
140
217
|
#
|
141
218
|
# @param [String] name
|
142
|
-
# @param [Hash{String => Object}]
|
219
|
+
# @param [Hash{String => Object}] element
|
143
220
|
# @param [String] content
|
144
221
|
# @return [RDF::Value]
|
145
|
-
def parse_element(name,
|
222
|
+
def parse_element(name, element, content)
|
146
223
|
case name.to_sym
|
147
224
|
when :id
|
148
|
-
RDF::Node.
|
225
|
+
RDF::Node.intern(content.strip)
|
149
226
|
when :uri
|
150
227
|
uri = RDF::URI.new(content.strip) # TODO: interned URIs
|
228
|
+
uri = base_uri.join(uri) if base_uri && uri.relative?
|
151
229
|
uri.validate! if validate?
|
152
230
|
uri.canonicalize! if canonicalize?
|
153
231
|
uri
|
232
|
+
when :triple # RDF-star
|
233
|
+
log_error "expected 'triple' element" unless @options[:rdfstar]
|
234
|
+
read_triple(element)
|
154
235
|
when :typedLiteral
|
155
|
-
|
236
|
+
content = element.children.c14nxl(library: @library) if
|
237
|
+
element['datatype'] == RDF.XMLLiteral
|
238
|
+
literal = RDF::Literal.new(content, :datatype => RDF::URI(element['datatype']))
|
156
239
|
literal.validate! if validate?
|
157
240
|
literal.canonicalize! if canonicalize?
|
158
241
|
literal
|
159
242
|
when :plainLiteral
|
160
243
|
literal = case
|
161
|
-
when lang =
|
244
|
+
when lang = element['xml:lang'] || element['lang']
|
162
245
|
RDF::Literal.new(content, :language => lang)
|
163
246
|
else
|
164
247
|
RDF::Literal.new(content)
|
@@ -167,7 +250,7 @@ module RDF::TriX
|
|
167
250
|
literal.canonicalize! if canonicalize?
|
168
251
|
literal
|
169
252
|
else
|
170
|
-
log_error "expected element name to be 'id', 'uri', 'typedLiteral', or 'plainLiteral', but got #{name.inspect}"
|
253
|
+
log_error "expected element name to be 'id', 'uri', 'triple', 'typedLiteral', or 'plainLiteral', but got #{name.inspect}"
|
171
254
|
end
|
172
255
|
end
|
173
256
|
end # Reader
|