rdf-trix 2.2.0 → 3.2.0
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/format.rb +1 -1
- 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/reader.rb +95 -12
- data/lib/rdf/trix/writer/nokogiri.rb +7 -3
- data/lib/rdf/trix/writer/rexml.rb +7 -3
- data/lib/rdf/trix/writer.rb +47 -20
- data/lib/rdf/trix.rb +5 -5
- metadata +62 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 191853659bf68e4e8cbbda85cea03df689440c7a2ac2a43617df3ea76dd6cdf2
|
4
|
+
data.tar.gz: b33711aca646cf5f98597697d0c3b7b9f14ffd2f16ad45c76286c20511f0eae5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2c213efad3bd49f38977f0f19e5832bbc8fc4d2bbdf670bd8370b134e93fe61c4d84a9fab2784f7c660f15eb38cb0ae27d0d4416507c2bc1f32e08d24586ed6
|
7
|
+
data.tar.gz: a881d218ba453a4a4d0ceb9f5ff39de8c8948340f0f33ebd79bee7982a9ff2bacff2bdb23a4b2e2befa82e9d1f69b70907f31cc4f1b1b7047d23ac68a13d4683
|
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.6, and JRuby 9+.
|
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.2)
|
108
|
+
[Nokogiri](https://rubygems.org/gems/nokogiri) (~> 1.12)
|
109
|
+
[LibXML](https://rubygems.org/gems/libxml) (>= 3.2)
|
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.2.0
|
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/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'
|
@@ -3,7 +3,7 @@ module RDF::TriX
|
|
3
3
|
##
|
4
4
|
# LibXML-Ruby implementation of the TriX reader.
|
5
5
|
#
|
6
|
-
# @see
|
6
|
+
# @see https://rubygems.org/gems/libxml-ruby/
|
7
7
|
module LibXML
|
8
8
|
OPTIONS = {'trix' => Format::XMLNS}.freeze
|
9
9
|
|
@@ -20,43 +20,30 @@ module RDF::TriX
|
|
20
20
|
#
|
21
21
|
# @param [Hash{Symbol => Object}] options
|
22
22
|
# @return [void]
|
23
|
-
def initialize_xml(options
|
23
|
+
def initialize_xml(input, **options)
|
24
24
|
require 'libxml' unless defined?(::LibXML)
|
25
|
-
@xml = case
|
26
|
-
when File then ::LibXML::XML::Document.file(
|
27
|
-
when IO, StringIO then ::LibXML::XML::Document.io(
|
28
|
-
else ::LibXML::XML::Document.string(
|
25
|
+
@xml = case input
|
26
|
+
when File then ::LibXML::XML::Document.file(input.path)
|
27
|
+
when IO, StringIO then ::LibXML::XML::Document.io(input)
|
28
|
+
else ::LibXML::XML::Document.string(input.to_s)
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
+
protected
|
33
|
+
|
32
34
|
##
|
33
35
|
# @private
|
34
|
-
|
35
|
-
|
36
|
-
if block_given?
|
37
|
-
@xml.find('//trix:graph', OPTIONS).each do |graph_element|
|
38
|
-
graph = RDF::Graph.new(read_graph(graph_element))
|
39
|
-
read_statements(graph_element) { |statement| graph << statement }
|
40
|
-
block.call(graph)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
enum_graph
|
36
|
+
def find_graphs(&block)
|
37
|
+
@xml.find('//trix:graph', OPTIONS).each(&block)
|
44
38
|
end
|
45
39
|
|
46
40
|
##
|
47
41
|
# @private
|
48
|
-
|
49
|
-
|
50
|
-
if
|
51
|
-
@xml.find('//trix:graph', OPTIONS).each do |graph_element|
|
52
|
-
read_statements(graph_element, &block)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
enum_statement
|
42
|
+
def read_base
|
43
|
+
base = @xml.root.attributes.get_attribute_ns("http://www.w3.org/XML/1998/namespace", "base") if @xml && @xml.root
|
44
|
+
RDF::URI(base.value) if base
|
56
45
|
end
|
57
46
|
|
58
|
-
protected
|
59
|
-
|
60
47
|
##
|
61
48
|
# @private
|
62
49
|
def read_graph(graph_element)
|
@@ -66,14 +53,20 @@ module RDF::TriX
|
|
66
53
|
|
67
54
|
##
|
68
55
|
# @private
|
69
|
-
def
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
56
|
+
def triple_elements(element)
|
57
|
+
element.find('./trix:triple', OPTIONS)
|
58
|
+
end
|
59
|
+
|
60
|
+
##
|
61
|
+
# @private
|
62
|
+
def element_elements(element)
|
63
|
+
element.children.select { |node| node.element? }
|
64
|
+
end
|
65
|
+
|
66
|
+
##
|
67
|
+
# @private
|
68
|
+
def element_content(element)
|
69
|
+
element.content
|
77
70
|
end
|
78
71
|
end # LibXML
|
79
72
|
end # Reader
|
@@ -3,7 +3,7 @@ module RDF::TriX
|
|
3
3
|
##
|
4
4
|
# Nokogiri implementation of the TriX reader.
|
5
5
|
#
|
6
|
-
# @see
|
6
|
+
# @see https://nokogiri.org/
|
7
7
|
module Nokogiri
|
8
8
|
OPTIONS = {'trix' => Format::XMLNS}.freeze
|
9
9
|
|
@@ -20,41 +20,28 @@ module RDF::TriX
|
|
20
20
|
#
|
21
21
|
# @param [Hash{Symbol => Object}] options
|
22
22
|
# @return [void]
|
23
|
-
def initialize_xml(options
|
23
|
+
def initialize_xml(input, **options)
|
24
24
|
require 'nokogiri' unless defined?(::Nokogiri)
|
25
|
-
@xml = ::Nokogiri::XML(
|
25
|
+
@xml = ::Nokogiri::XML(input)
|
26
26
|
log_error("Errors: #{@xml.errors.join('\n')}") unless @xml.errors.empty?
|
27
27
|
@xml
|
28
28
|
end
|
29
29
|
|
30
|
+
protected
|
31
|
+
|
30
32
|
##
|
31
33
|
# @private
|
32
|
-
|
33
|
-
|
34
|
-
if block_given?
|
35
|
-
@xml.xpath('//trix:graph', OPTIONS).each do |graph_element|
|
36
|
-
graph = RDF::Graph.new(read_graph(graph_element))
|
37
|
-
read_statements(graph_element) { |statement| graph << statement }
|
38
|
-
block.call(graph)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
enum_graph
|
34
|
+
def find_graphs(&block)
|
35
|
+
@xml.xpath('//trix:graph', OPTIONS).each(&block)
|
42
36
|
end
|
43
37
|
|
44
38
|
##
|
45
39
|
# @private
|
46
|
-
|
47
|
-
|
48
|
-
if
|
49
|
-
@xml.xpath('//trix:graph', OPTIONS).each do |graph_element|
|
50
|
-
read_statements(graph_element, &block)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
enum_statement
|
40
|
+
def read_base
|
41
|
+
base = @xml.root.attribute_with_ns("base", "http://www.w3.org/XML/1998/namespace") if @xml && @xml.root
|
42
|
+
RDF::URI(base.to_s) if base
|
54
43
|
end
|
55
44
|
|
56
|
-
protected
|
57
|
-
|
58
45
|
##
|
59
46
|
# @private
|
60
47
|
def read_graph(graph_element)
|
@@ -64,14 +51,20 @@ module RDF::TriX
|
|
64
51
|
|
65
52
|
##
|
66
53
|
# @private
|
67
|
-
def
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
54
|
+
def triple_elements(element)
|
55
|
+
element.xpath('./trix:triple', OPTIONS)
|
56
|
+
end
|
57
|
+
|
58
|
+
##
|
59
|
+
# @private
|
60
|
+
def element_elements(element)
|
61
|
+
element.children.select { |node| node.element? }
|
62
|
+
end
|
63
|
+
|
64
|
+
##
|
65
|
+
# @private
|
66
|
+
def element_content(element)
|
67
|
+
element.content
|
75
68
|
end
|
76
69
|
end # Nokogiri
|
77
70
|
end # Reader
|
@@ -3,7 +3,7 @@ module RDF::TriX
|
|
3
3
|
##
|
4
4
|
# REXML implementation of the TriX reader.
|
5
5
|
#
|
6
|
-
# @see
|
6
|
+
# @see https://www.germane-software.com/software/rexml/
|
7
7
|
module REXML
|
8
8
|
OPTIONS = {}.freeze
|
9
9
|
|
@@ -20,39 +20,26 @@ module RDF::TriX
|
|
20
20
|
#
|
21
21
|
# @param [Hash{Symbol => Object}] options
|
22
22
|
# @return [void]
|
23
|
-
def initialize_xml(options
|
23
|
+
def initialize_xml(input, **options)
|
24
24
|
require 'rexml/document' unless defined?(::REXML)
|
25
|
-
@xml = ::REXML::Document.new(
|
25
|
+
@xml = ::REXML::Document.new(input, :compress_whitespace => %w{uri})
|
26
26
|
end
|
27
27
|
|
28
|
+
protected
|
29
|
+
|
28
30
|
##
|
29
31
|
# @private
|
30
|
-
|
31
|
-
|
32
|
-
if block_given?
|
33
|
-
@xml.elements.each('TriX/graph') do |graph_element|
|
34
|
-
graph = RDF::Graph.new(read_graph(graph_element))
|
35
|
-
read_statements(graph_element) { |statement| graph << statement }
|
36
|
-
block.call(graph)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
enum_graph
|
32
|
+
def find_graphs(&block)
|
33
|
+
@xml.elements.each('TriX/graph', &block)
|
40
34
|
end
|
41
35
|
|
42
36
|
##
|
43
37
|
# @private
|
44
|
-
|
45
|
-
|
46
|
-
if
|
47
|
-
@xml.elements.each('TriX/graph') do |graph_element|
|
48
|
-
read_statements(graph_element, &block)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
enum_statement
|
38
|
+
def read_base
|
39
|
+
base = @xml.root.attribute("base", "http://www.w3.org/XML/1998/namespace") if @xml && @xml.root
|
40
|
+
RDF::URI(base.to_s) if base
|
52
41
|
end
|
53
42
|
|
54
|
-
protected
|
55
|
-
|
56
43
|
##
|
57
44
|
# @private
|
58
45
|
def read_graph(graph_element)
|
@@ -62,14 +49,20 @@ module RDF::TriX
|
|
62
49
|
|
63
50
|
##
|
64
51
|
# @private
|
65
|
-
def
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
52
|
+
def triple_elements(element)
|
53
|
+
element.get_elements('triple')
|
54
|
+
end
|
55
|
+
|
56
|
+
##
|
57
|
+
# @private
|
58
|
+
def element_elements(element)
|
59
|
+
element.elements.to_a
|
60
|
+
end
|
61
|
+
|
62
|
+
##
|
63
|
+
# @private
|
64
|
+
def element_content(element)
|
65
|
+
element.text
|
73
66
|
end
|
74
67
|
end # REXML
|
75
68
|
end # Reader
|
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] graph_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
|
@@ -3,7 +3,7 @@ module RDF::TriX
|
|
3
3
|
##
|
4
4
|
# Nokogiri implementation of the TriX writer.
|
5
5
|
#
|
6
|
-
# @see
|
6
|
+
# @see https://nokogiri.org/
|
7
7
|
module Nokogiri
|
8
8
|
##
|
9
9
|
# Returns the name of the underlying XML library.
|
@@ -18,7 +18,7 @@ module RDF::TriX
|
|
18
18
|
#
|
19
19
|
# @param [Hash{Symbol => Object}] options
|
20
20
|
# @return [void]
|
21
|
-
def initialize_xml(options
|
21
|
+
def initialize_xml(**options)
|
22
22
|
require 'nokogiri' unless defined?(::Nokogiri)
|
23
23
|
@xml = ::Nokogiri::XML::Document.new
|
24
24
|
@xml.encoding = @encoding
|
@@ -29,7 +29,9 @@ module RDF::TriX
|
|
29
29
|
#
|
30
30
|
# @return [void]
|
31
31
|
def write_prologue
|
32
|
-
|
32
|
+
options = {xmlns: Format::XMLNS, xml: "http://www.w3.org/XML/1998/namespace"}
|
33
|
+
options["xml:base"] = base_uri.to_s if base_uri
|
34
|
+
@xml << (@trix = create_element(:TriX, nil, options))
|
33
35
|
super
|
34
36
|
end
|
35
37
|
|
@@ -85,8 +87,10 @@ module RDF::TriX
|
|
85
87
|
if xmlns = attributes.delete(:xmlns)
|
86
88
|
element.default_namespace = xmlns
|
87
89
|
end
|
90
|
+
fragment = attributes.delete(:fragment)
|
88
91
|
attributes.each { |k, v| element[k.to_s] = v }
|
89
92
|
element.content = content.to_s unless content.nil?
|
93
|
+
element << fragment if fragment
|
90
94
|
block.call(element) if block_given?
|
91
95
|
element
|
92
96
|
end
|
@@ -3,7 +3,7 @@ module RDF::TriX
|
|
3
3
|
##
|
4
4
|
# REXML implementation of the TriX writer.
|
5
5
|
#
|
6
|
-
# @see
|
6
|
+
# @see https://www.germane-software.com/software/rexml/
|
7
7
|
module REXML
|
8
8
|
##
|
9
9
|
# Returns the name of the underlying XML library.
|
@@ -18,7 +18,7 @@ module RDF::TriX
|
|
18
18
|
#
|
19
19
|
# @param [Hash{Symbol => Object}] options
|
20
20
|
# @return [void]
|
21
|
-
def initialize_xml(options
|
21
|
+
def initialize_xml(**options)
|
22
22
|
require 'rexml/document' unless defined?(::REXML)
|
23
23
|
@xml = ::REXML::Document.new(nil, :attribute_quote => :quote)
|
24
24
|
@xml << ::REXML::XMLDecl.new(::REXML::XMLDecl::DEFAULT_VERSION, @encoding)
|
@@ -29,7 +29,9 @@ module RDF::TriX
|
|
29
29
|
#
|
30
30
|
# @return [void]
|
31
31
|
def write_prologue
|
32
|
-
|
32
|
+
options = {"xmlns" => Format::XMLNS, "xml" => "http://www.w3.org/XML/1998/namespace"}
|
33
|
+
options["xml:base"] = base_uri.to_s if base_uri
|
34
|
+
@trix = @xml.add_element('TriX', options)
|
33
35
|
super
|
34
36
|
end
|
35
37
|
|
@@ -85,8 +87,10 @@ module RDF::TriX
|
|
85
87
|
# @return [REXML::Element]
|
86
88
|
def create_element(name, content = nil, attributes = {}, &block)
|
87
89
|
element = ::REXML::Element.new(name.to_s, nil, @xml.context)
|
90
|
+
fragment = attributes.delete(:fragment)
|
88
91
|
attributes.each { |k, v| element.add_attribute(k.to_s, v) }
|
89
92
|
element.text = content.to_s unless content.nil?
|
93
|
+
element << fragment if fragment
|
90
94
|
block.call(element) if block_given?
|
91
95
|
element
|
92
96
|
end
|
data/lib/rdf/trix/writer.rb
CHANGED
@@ -8,9 +8,9 @@ module RDF::TriX
|
|
8
8
|
# override the used implementation by passing in a `:library` option to
|
9
9
|
# `Writer.new` or `Writer.open`.
|
10
10
|
#
|
11
|
-
# [REXML]:
|
12
|
-
# [LibXML]:
|
13
|
-
# [Nokogiri]:
|
11
|
+
# [REXML]: https://www.germane-software.com/software/rexml/
|
12
|
+
# [LibXML]: https://rubygems.org/gems/libxml-ruby/
|
13
|
+
# [Nokogiri]: https://nokogiri.org/
|
14
14
|
#
|
15
15
|
# @example Loading TriX serialization support
|
16
16
|
# require 'rdf/trix'
|
@@ -42,7 +42,7 @@ module RDF::TriX
|
|
42
42
|
# end
|
43
43
|
# end
|
44
44
|
#
|
45
|
-
# @see
|
45
|
+
# @see https://www.w3.org/2004/03/trix/
|
46
46
|
class Writer < RDF::Writer
|
47
47
|
format RDF::TriX::Format
|
48
48
|
|
@@ -70,7 +70,7 @@ module RDF::TriX
|
|
70
70
|
# @yield [writer] `self`
|
71
71
|
# @yieldparam [RDF::Writer] writer
|
72
72
|
# @yieldreturn [void] ignored
|
73
|
-
def initialize(output = $stdout, options
|
73
|
+
def initialize(output = $stdout, **options, &block)
|
74
74
|
@graph_name = nil
|
75
75
|
@nesting = 0
|
76
76
|
|
@@ -104,7 +104,7 @@ module RDF::TriX
|
|
104
104
|
self.extend(@implementation)
|
105
105
|
|
106
106
|
@encoding = (options[:encoding] || 'utf-8').to_s
|
107
|
-
initialize_xml(options)
|
107
|
+
initialize_xml(**options)
|
108
108
|
|
109
109
|
super do
|
110
110
|
if block_given?
|
@@ -185,6 +185,31 @@ module RDF::TriX
|
|
185
185
|
log_error(subject, predicate, object, e.message)
|
186
186
|
end
|
187
187
|
|
188
|
+
##
|
189
|
+
# Returns the TriX representation of a statement.
|
190
|
+
#
|
191
|
+
# @param [RDF::Statement] statement
|
192
|
+
# @param [Hash{Symbol => Object}] options ({})
|
193
|
+
# @return [String]
|
194
|
+
def format_statement(statement, **options)
|
195
|
+
format_triple(*statement.to_triple, **options)
|
196
|
+
end
|
197
|
+
|
198
|
+
##
|
199
|
+
# Formats a referenced triple.
|
200
|
+
#
|
201
|
+
# @example
|
202
|
+
# <<<s> <p> <o>>> <p> <o> .
|
203
|
+
#
|
204
|
+
# @param [RDF::Statement] statement
|
205
|
+
# @param [Hash{Symbol => Object}] options = ({})
|
206
|
+
# @return [String]
|
207
|
+
# @raise [NotImplementedError] unless implemented in subclass
|
208
|
+
# @abstract
|
209
|
+
def format_quotedTriple(statement, **options)
|
210
|
+
format_statement(statement, **options)
|
211
|
+
end
|
212
|
+
|
188
213
|
##
|
189
214
|
# Returns the TriX representation of a triple.
|
190
215
|
#
|
@@ -193,11 +218,11 @@ module RDF::TriX
|
|
193
218
|
# @param [RDF::Value] object
|
194
219
|
# @param [Hash{Symbol => Object}] options
|
195
220
|
# @return [Element]
|
196
|
-
def format_triple(subject, predicate, object, options
|
221
|
+
def format_triple(subject, predicate, object, **options)
|
197
222
|
create_element(:triple) do |triple|
|
198
|
-
triple << format_term(subject, options)
|
199
|
-
triple << format_term(predicate, options)
|
200
|
-
triple << format_term(object, options)
|
223
|
+
triple << format_term(subject, **options)
|
224
|
+
triple << format_term(predicate, **options)
|
225
|
+
triple << format_term(object, **options)
|
201
226
|
end
|
202
227
|
end
|
203
228
|
|
@@ -207,7 +232,7 @@ module RDF::TriX
|
|
207
232
|
# @param [RDF::Node] value
|
208
233
|
# @param [Hash{Symbol => Object}] options
|
209
234
|
# @return [Element]
|
210
|
-
def format_node(value, options
|
235
|
+
def format_node(value, **options)
|
211
236
|
create_element(:id, value.id.to_s)
|
212
237
|
end
|
213
238
|
|
@@ -217,8 +242,8 @@ module RDF::TriX
|
|
217
242
|
# @param [RDF::URI] value
|
218
243
|
# @param [Hash{Symbol => Object}] options
|
219
244
|
# @return [Element]
|
220
|
-
def format_uri(value, options
|
221
|
-
create_element(:uri, value.to_s)
|
245
|
+
def format_uri(value, **options)
|
246
|
+
create_element(:uri, value.relativize(base_uri).to_s)
|
222
247
|
end
|
223
248
|
|
224
249
|
##
|
@@ -227,14 +252,16 @@ module RDF::TriX
|
|
227
252
|
# @param [RDF::Literal, String, #to_s] value
|
228
253
|
# @param [Hash{Symbol => Object}] options
|
229
254
|
# @return [Element]
|
230
|
-
def format_literal(value, options
|
255
|
+
def format_literal(value, **options)
|
231
256
|
case
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
257
|
+
when value.datatype == RDF.XMLLiteral
|
258
|
+
create_element(:typedLiteral, nil, 'datatype' => value.datatype.to_s, fragment: value.value.to_s)
|
259
|
+
when value.has_datatype?
|
260
|
+
create_element(:typedLiteral, value.value.to_s, 'datatype' => value.datatype.to_s)
|
261
|
+
when value.has_language?
|
262
|
+
create_element(:plainLiteral, value.value.to_s, 'xml:lang' => value.language.to_s)
|
263
|
+
else
|
264
|
+
create_element(:plainLiteral, value.value.to_s)
|
238
265
|
end
|
239
266
|
end
|
240
267
|
end # Writer
|
data/lib/rdf/trix.rb
CHANGED
@@ -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'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rdf-trix
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arto Bendiken
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-12-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rdf
|
@@ -16,56 +16,98 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '3.2'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '3.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rdf-xsd
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.2'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.2'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rdf-spec
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
45
|
- - "~>"
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
47
|
+
version: '3.2'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.2'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rdf-trig
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.2'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.2'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rdf-ordered-repo
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.2'
|
34
76
|
type: :development
|
35
77
|
prerelease: false
|
36
78
|
version_requirements: !ruby/object:Gem::Requirement
|
37
79
|
requirements:
|
38
80
|
- - "~>"
|
39
81
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
82
|
+
version: '3.2'
|
41
83
|
- !ruby/object:Gem::Dependency
|
42
84
|
name: rspec
|
43
85
|
requirement: !ruby/object:Gem::Requirement
|
44
86
|
requirements:
|
45
87
|
- - "~>"
|
46
88
|
- !ruby/object:Gem::Version
|
47
|
-
version: '3.
|
89
|
+
version: '3.10'
|
48
90
|
type: :development
|
49
91
|
prerelease: false
|
50
92
|
version_requirements: !ruby/object:Gem::Requirement
|
51
93
|
requirements:
|
52
94
|
- - "~>"
|
53
95
|
- !ruby/object:Gem::Version
|
54
|
-
version: '3.
|
96
|
+
version: '3.10'
|
55
97
|
- !ruby/object:Gem::Dependency
|
56
98
|
name: rspec-its
|
57
99
|
requirement: !ruby/object:Gem::Requirement
|
58
100
|
requirements:
|
59
101
|
- - "~>"
|
60
102
|
- !ruby/object:Gem::Version
|
61
|
-
version: '1.
|
103
|
+
version: '1.3'
|
62
104
|
type: :development
|
63
105
|
prerelease: false
|
64
106
|
version_requirements: !ruby/object:Gem::Requirement
|
65
107
|
requirements:
|
66
108
|
- - "~>"
|
67
109
|
- !ruby/object:Gem::Version
|
68
|
-
version: '1.
|
110
|
+
version: '1.3'
|
69
111
|
- !ruby/object:Gem::Dependency
|
70
112
|
name: yard
|
71
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,28 +128,28 @@ dependencies:
|
|
86
128
|
requirements:
|
87
129
|
- - "~>"
|
88
130
|
- !ruby/object:Gem::Version
|
89
|
-
version: '1.
|
131
|
+
version: '1.10'
|
90
132
|
type: :development
|
91
133
|
prerelease: false
|
92
134
|
version_requirements: !ruby/object:Gem::Requirement
|
93
135
|
requirements:
|
94
136
|
- - "~>"
|
95
137
|
- !ruby/object:Gem::Version
|
96
|
-
version: '1.
|
138
|
+
version: '1.10'
|
97
139
|
- !ruby/object:Gem::Dependency
|
98
140
|
name: libxml-ruby
|
99
141
|
requirement: !ruby/object:Gem::Requirement
|
100
142
|
requirements:
|
101
143
|
- - "~>"
|
102
144
|
- !ruby/object:Gem::Version
|
103
|
-
version: '3.
|
145
|
+
version: '3.2'
|
104
146
|
type: :development
|
105
147
|
prerelease: false
|
106
148
|
version_requirements: !ruby/object:Gem::Requirement
|
107
149
|
requirements:
|
108
150
|
- - "~>"
|
109
151
|
- !ruby/object:Gem::Version
|
110
|
-
version: '3.
|
152
|
+
version: '3.2'
|
111
153
|
description: RDF.rb extension for parsing/serializing TriX data.
|
112
154
|
email: public-rdf-ruby@w3.org
|
113
155
|
executables: []
|
@@ -130,11 +172,11 @@ files:
|
|
130
172
|
- lib/rdf/trix/writer.rb
|
131
173
|
- lib/rdf/trix/writer/nokogiri.rb
|
132
174
|
- lib/rdf/trix/writer/rexml.rb
|
133
|
-
homepage:
|
175
|
+
homepage: https://github.com/ruby-rdf/rdf-trix
|
134
176
|
licenses:
|
135
177
|
- Unlicense
|
136
178
|
metadata: {}
|
137
|
-
post_install_message:
|
179
|
+
post_install_message:
|
138
180
|
rdoc_options: []
|
139
181
|
require_paths:
|
140
182
|
- lib
|
@@ -142,16 +184,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
142
184
|
requirements:
|
143
185
|
- - ">="
|
144
186
|
- !ruby/object:Gem::Version
|
145
|
-
version: 2.
|
187
|
+
version: '2.6'
|
146
188
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
189
|
requirements:
|
148
190
|
- - ">="
|
149
191
|
- !ruby/object:Gem::Version
|
150
192
|
version: '0'
|
151
193
|
requirements: []
|
152
|
-
|
153
|
-
|
154
|
-
signing_key:
|
194
|
+
rubygems_version: 3.3.3
|
195
|
+
signing_key:
|
155
196
|
specification_version: 4
|
156
197
|
summary: TriX support for RDF.rb.
|
157
198
|
test_files: []
|