rdf-trix 1.1.0.1 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 147cdb2e02fe4edfcd27d30489737d24a515c5dc
4
- data.tar.gz: d0afbd93a45315a1e631bfd911591dc90284b7c5
2
+ SHA256:
3
+ metadata.gz: fcb519d95583f7549372cf7158b3d6f6eff1534e74d7d6f5183587fecf974dd3
4
+ data.tar.gz: a75d81aa6706ad6d05d0e5d9bdb793ab5c2f6d62351b8aafe1e1b83b69d588a4
5
5
  SHA512:
6
- metadata.gz: 1d78b6f700492b541bf56a115a6336179e5341be90b719199a1bb402278793038f458b012c6ba16970b6680d1c5caf7af5e9de68bdd5f980632c68863b521a49
7
- data.tar.gz: 6bf0255b66b73755b8e0f30395afa3b6983edd3c0005f27bb2e43e9bcd1a3d133d6216488c9c7a9840c001ad5cfbd0ccedbe11cecb366743371e8d2be433a8a6
6
+ metadata.gz: effcfaeffb7c99ff1434d81ba17e22b29caf22b22f5649a7321e25621b8132a77224fdb7e51e876a9e57256a96e1f98b487c93c00d7448ecdbf415afacc0ec6e
7
+ data.tar.gz: 85107068c714384204d1ce8e642777470b1e6e573019dd3347726deeefcdd7aaaf55d50c65b497ccab278f8a8de5978c6296c9eab375f11737123dcba4094a69
@@ -22,8 +22,8 @@ Documentation
22
22
  Dependencies
23
23
  ------------
24
24
 
25
- * [RDF.rb](http://rubygems.org/gems/rdf) (>= 1.1)
26
- [Nokogiri](http://rubygems.org/gems/nokogiri) (>= 1.6.0)
25
+ * [RDF.rb](http://rubygems.org/gems/rdf) (~> 3.1)
26
+ [Nokogiri](http://rubygems.org/gems/nokogiri) (>= 1.10.0)
27
27
 
28
28
  Installation
29
29
  ------------
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0.1
1
+ 3.1.0
@@ -44,7 +44,7 @@
44
44
  <triple>
45
45
  <uri>http://rubygems.org/gems/rdf-trix</uri>
46
46
  <uri>http://usefulinc.com/ns/doap#download-page</uri>
47
- <uri>http://rubyforge.org/projects/rdf/</uri>
47
+ <uri>http://rubygems.org/gems/rdf-trix/</uri>
48
48
  </triple>
49
49
  <triple>
50
50
  <uri>http://rubygems.org/gems/rdf-trix</uri>
@@ -1,4 +1,4 @@
1
- require 'rdf' # @see http://rubygems.org/gems/rdf
1
+ require 'rdf'
2
2
 
3
3
  module RDF
4
4
  ##
@@ -21,7 +21,7 @@ module RDF
21
21
  # end
22
22
  # end
23
23
  #
24
- # @see http://rdf.rubyforge.org/
24
+ # @see http://rubygems.org/gems/rdf
25
25
  # @see http://www.w3.org/2004/03/trix/
26
26
  # @see http://www.hpl.hp.com/techreports/2004/HPL-2004-56.pdf
27
27
  # @see http://swdev.nokia.com/trix/trix.html
@@ -66,7 +66,7 @@ module RDF::TriX
66
66
  # @yield [reader] `self`
67
67
  # @yieldparam [RDF::Reader] reader
68
68
  # @yieldreturn [void] ignored
69
- def initialize(input = $stdin, options = {}, &block)
69
+ def initialize(input = $stdin, **options, &block)
70
70
  super do
71
71
  @library = case options[:library]
72
72
  when nil
@@ -96,7 +96,12 @@ module RDF::TriX
96
96
  end
97
97
  self.extend(@implementation)
98
98
 
99
- initialize_xml(options)
99
+ begin
100
+ initialize_xml(**options)
101
+ rescue
102
+ log_error("Malformed document: #{$!.message}")
103
+ end
104
+
100
105
  if block_given?
101
106
  case block.arity
102
107
  when 0 then instance_eval(&block)
@@ -162,7 +167,7 @@ module RDF::TriX
162
167
  literal.canonicalize! if canonicalize?
163
168
  literal
164
169
  else
165
- raise RDF::ReaderError, "expected element name to be 'id', 'uri', 'typedLiteral', or 'plainLiteral', but got #{name.inspect}"
170
+ log_error "expected element name to be 'id', 'uri', 'typedLiteral', or 'plainLiteral', but got #{name.inspect}"
166
171
  end
167
172
  end
168
173
  end # Reader
@@ -20,11 +20,11 @@ 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(**options)
24
24
  require 'libxml' unless defined?(::LibXML)
25
25
  @xml = case @input
26
- when File then ::LibXML::XML::Document.file(@input.path)
27
- when IO then ::LibXML::XML::Document.io(@input)
26
+ when File then ::LibXML::XML::Document.file(@input.path)
27
+ when IO, StringIO then ::LibXML::XML::Document.io(@input)
28
28
  else ::LibXML::XML::Document.string(@input.to_s)
29
29
  end
30
30
  end
@@ -35,7 +35,7 @@ module RDF::TriX
35
35
  def each_graph(&block)
36
36
  if block_given?
37
37
  @xml.find('//trix:graph', OPTIONS).each do |graph_element|
38
- graph = RDF::Graph.new(read_context(graph_element))
38
+ graph = RDF::Graph.new(read_graph(graph_element))
39
39
  read_statements(graph_element) { |statement| graph << statement }
40
40
  block.call(graph)
41
41
  end
@@ -59,7 +59,7 @@ module RDF::TriX
59
59
 
60
60
  ##
61
61
  # @private
62
- def read_context(graph_element)
62
+ def read_graph(graph_element)
63
63
  name = graph_element.children.select { |node| node.element? && node.name.to_s == 'uri' }.first.content.strip rescue nil
64
64
  name ? RDF::URI.intern(name) : nil
65
65
  end
@@ -67,12 +67,12 @@ module RDF::TriX
67
67
  ##
68
68
  # @private
69
69
  def read_statements(graph_element, &block)
70
- context = read_context(graph_element)
70
+ context = read_graph(graph_element)
71
71
  graph_element.find('./trix:triple', OPTIONS).each do |triple_element|
72
72
  triple = triple_element.children.select { |node| node.element? }[0..2]
73
73
  triple = triple.map { |element| parse_element(element.name, element.attributes, element.content) }
74
74
  triple << {:context => context} if context
75
- block.call(RDF::Statement.new(*triple))
75
+ block.call(RDF::Statement(*triple))
76
76
  end
77
77
  end
78
78
  end # LibXML
@@ -20,9 +20,11 @@ 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(**options)
24
24
  require 'nokogiri' unless defined?(::Nokogiri)
25
25
  @xml = ::Nokogiri::XML(@input)
26
+ log_error("Errors: #{@xml.errors.join('\n')}") unless @xml.errors.empty?
27
+ @xml
26
28
  end
27
29
 
28
30
  ##
@@ -31,7 +33,7 @@ module RDF::TriX
31
33
  def each_graph(&block)
32
34
  if block_given?
33
35
  @xml.xpath('//trix:graph', OPTIONS).each do |graph_element|
34
- graph = RDF::Graph.new(read_context(graph_element))
36
+ graph = RDF::Graph.new(read_graph(graph_element))
35
37
  read_statements(graph_element) { |statement| graph << statement }
36
38
  block.call(graph)
37
39
  end
@@ -55,7 +57,7 @@ module RDF::TriX
55
57
 
56
58
  ##
57
59
  # @private
58
- def read_context(graph_element)
60
+ def read_graph(graph_element)
59
61
  name = graph_element.children.select { |node| node.element? && node.name.to_s == 'uri' }.first.content.strip rescue nil
60
62
  name ? RDF::URI.intern(name) : nil
61
63
  end
@@ -63,12 +65,12 @@ module RDF::TriX
63
65
  ##
64
66
  # @private
65
67
  def read_statements(graph_element, &block)
66
- context = read_context(graph_element)
68
+ context = read_graph(graph_element)
67
69
  graph_element.xpath('./trix:triple', OPTIONS).each do |triple_element|
68
70
  triple = triple_element.children.select { |node| node.element? }[0..2]
69
71
  triple = triple.map { |element| parse_element(element.name, element, element.content) }
70
72
  triple << {:context => context} if context
71
- block.call(RDF::Statement.new(*triple))
73
+ block.call(RDF::Statement(*triple))
72
74
  end
73
75
  end
74
76
  end # Nokogiri
@@ -20,7 +20,7 @@ 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(**options)
24
24
  require 'rexml/document' unless defined?(::REXML)
25
25
  @xml = ::REXML::Document.new(@input, :compress_whitespace => %w{uri})
26
26
  end
@@ -31,7 +31,7 @@ module RDF::TriX
31
31
  def each_graph(&block)
32
32
  if block_given?
33
33
  @xml.elements.each('TriX/graph') do |graph_element|
34
- graph = RDF::Graph.new(read_context(graph_element))
34
+ graph = RDF::Graph.new(read_graph(graph_element))
35
35
  read_statements(graph_element) { |statement| graph << statement }
36
36
  block.call(graph)
37
37
  end
@@ -55,7 +55,7 @@ module RDF::TriX
55
55
 
56
56
  ##
57
57
  # @private
58
- def read_context(graph_element)
58
+ def read_graph(graph_element)
59
59
  name = graph_element.elements.select { |element| element.name.to_s == 'uri' }.first.text.strip rescue nil
60
60
  name ? RDF::URI.intern(name) : nil
61
61
  end
@@ -63,12 +63,12 @@ module RDF::TriX
63
63
  ##
64
64
  # @private
65
65
  def read_statements(graph_element, &block)
66
- context = read_context(graph_element)
66
+ context = read_graph(graph_element)
67
67
  graph_element.elements.each('triple') do |triple_element|
68
68
  triple = triple_element.elements.to_a[0..2]
69
69
  triple = triple.map { |element| parse_element(element.name, element.attributes, element.text) }
70
70
  triple << {:context => context} if context
71
- block.call(RDF::Statement.new(*triple))
71
+ block.call(RDF::Statement(*triple))
72
72
  end
73
73
  end
74
74
  end # REXML
@@ -53,10 +53,10 @@ module RDF::TriX
53
53
  attr_reader :implementation
54
54
 
55
55
  ##
56
- # Returns the current named graph context, if any.
56
+ # Returns the current graph_name, if any.
57
57
  #
58
58
  # @return [RDF::Resource]
59
- attr_reader :context
59
+ attr_reader :graph_name
60
60
 
61
61
  ##
62
62
  # Initializes the TriX writer instance.
@@ -70,8 +70,8 @@ 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 = {}, &block)
74
- @context = nil
73
+ def initialize(output = $stdout, **options, &block)
74
+ @graph_name = nil
75
75
  @nesting = 0
76
76
 
77
77
  @library = case options[:library]
@@ -104,12 +104,20 @@ module RDF::TriX
104
104
  self.extend(@implementation)
105
105
 
106
106
  @encoding = (options[:encoding] || 'utf-8').to_s
107
- initialize_xml(options)
108
- super
107
+ initialize_xml(**options)
108
+
109
+ super do
110
+ if block_given?
111
+ case block.arity
112
+ when 0 then instance_eval(&block)
113
+ else block.call(self)
114
+ end
115
+ end
116
+ end
109
117
  end
110
118
 
111
119
  ##
112
- # Defines a named graph context.
120
+ # Defines a named graph.
113
121
  #
114
122
  # @param [RDF::Resource] name
115
123
  # @yield [writer]
@@ -117,7 +125,7 @@ module RDF::TriX
117
125
  # @return [void]
118
126
  def graph(name = nil, &block)
119
127
  @nesting += 1
120
- @graph = create_graph(@context = name)
128
+ @graph = create_graph(@graph_name = name)
121
129
  if block_given?
122
130
  case block.arity
123
131
  when 1 then block.call(self)
@@ -149,24 +157,18 @@ module RDF::TriX
149
157
  end
150
158
 
151
159
  ##
152
- # @private
153
- # @see RDF::Writer#write_graph
154
- # @since 0.2.0
155
- def write_graph(graph)
156
- @graph = create_graph(@context = graph.context)
157
- graph.each_triple { |*triple| write_triple(*triple) }
158
- end
159
-
160
- ##
161
- # Generates the TriX representation of an RDF statement.
160
+ # Generates the TriX representation of a quad.
162
161
  #
163
- # @param [RDF::Statement] statement
162
+ # @param [RDF::Resource] subject
163
+ # @param [RDF::URI] predicate
164
+ # @param [RDF::Value] object
165
+ # @param [RDF::Resource] graph_name
164
166
  # @return [void]
165
- def write_statement(statement)
166
- unless nested? || statement.context.to_s == @context.to_s
167
- @graph = create_graph(@context = statement.context)
167
+ def write_quad(subject, predicate, object, graph_name)
168
+ unless nested? || graph_name.to_s == @graph_name.to_s
169
+ @graph = create_graph(@graph_name = graph_name)
168
170
  end
169
- write_triple(*statement.to_triple)
171
+ write_triple(subject, predicate, object)
170
172
  end
171
173
 
172
174
  ##
@@ -179,6 +181,8 @@ module RDF::TriX
179
181
  def write_triple(subject, predicate, object)
180
182
  @graph = create_graph unless @graph
181
183
  @graph << format_triple(subject, predicate, object)
184
+ rescue ArgumentError => e
185
+ log_error(subject, predicate, object, e.message)
182
186
  end
183
187
 
184
188
  ##
@@ -189,11 +193,11 @@ module RDF::TriX
189
193
  # @param [RDF::Value] object
190
194
  # @param [Hash{Symbol => Object}] options
191
195
  # @return [Element]
192
- def format_triple(subject, predicate, object, options = {})
196
+ def format_triple(subject, predicate, object, **options)
193
197
  create_element(:triple) do |triple|
194
- triple << format_term(subject, options)
195
- triple << format_term(predicate, options)
196
- triple << format_term(object, options)
198
+ triple << format_term(subject, **options)
199
+ triple << format_term(predicate, **options)
200
+ triple << format_term(object, **options)
197
201
  end
198
202
  end
199
203
 
@@ -203,7 +207,7 @@ module RDF::TriX
203
207
  # @param [RDF::Node] value
204
208
  # @param [Hash{Symbol => Object}] options
205
209
  # @return [Element]
206
- def format_node(value, options = {})
210
+ def format_node(value, **options)
207
211
  create_element(:id, value.id.to_s)
208
212
  end
209
213
 
@@ -213,7 +217,7 @@ module RDF::TriX
213
217
  # @param [RDF::URI] value
214
218
  # @param [Hash{Symbol => Object}] options
215
219
  # @return [Element]
216
- def format_uri(value, options = {})
220
+ def format_uri(value, **options)
217
221
  create_element(:uri, value.to_s)
218
222
  end
219
223
 
@@ -223,7 +227,7 @@ module RDF::TriX
223
227
  # @param [RDF::Literal, String, #to_s] value
224
228
  # @param [Hash{Symbol => Object}] options
225
229
  # @return [Element]
226
- def format_literal(value, options = {})
230
+ def format_literal(value, **options)
227
231
  case
228
232
  when value.has_datatype?
229
233
  create_element(:typedLiteral, value.value.to_s, 'datatype' => value.datatype.to_s)
@@ -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
@@ -30,6 +30,7 @@ module RDF::TriX
30
30
  # @return [void]
31
31
  def write_prologue
32
32
  @xml << (@trix = create_element(:TriX, nil, :xmlns => Format::XMLNS))
33
+ super
33
34
  end
34
35
 
35
36
  ##
@@ -39,6 +40,7 @@ module RDF::TriX
39
40
  def write_epilogue
40
41
  puts @xml.to_xml
41
42
  @xml = @trix = nil
43
+ super
42
44
  end
43
45
 
44
46
  ##
@@ -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)
@@ -30,6 +30,7 @@ module RDF::TriX
30
30
  # @return [void]
31
31
  def write_prologue
32
32
  @trix = @xml.add_element('TriX', 'xmlns' => Format::XMLNS)
33
+ super
33
34
  end
34
35
 
35
36
  ##
@@ -42,6 +43,7 @@ module RDF::TriX
42
43
  formatter.write(@xml, @output)
43
44
  puts # add a line break after the last line
44
45
  @xml = @trix = nil
46
+ super
45
47
  end
46
48
 
47
49
  ##
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: 1.1.0.1
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arto Bendiken
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-09 00:00:00.000000000 Z
11
+ date: 2019-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rdf
@@ -16,96 +16,98 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.1'
20
- - - "<"
21
- - !ruby/object:Gem::Version
22
- version: '1.99'
19
+ version: '3.1'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
24
  - - "~>"
28
25
  - !ruby/object:Gem::Version
29
- version: '1.1'
30
- - - "<"
31
- - !ruby/object:Gem::Version
32
- version: '1.99'
26
+ version: '3.1'
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: rdf-spec
35
29
  requirement: !ruby/object:Gem::Requirement
36
30
  requirements:
37
31
  - - "~>"
38
32
  - !ruby/object:Gem::Version
39
- version: '1.1'
40
- - - "<"
41
- - !ruby/object:Gem::Version
42
- version: '1.99'
33
+ version: '3.1'
43
34
  type: :development
44
35
  prerelease: false
45
36
  version_requirements: !ruby/object:Gem::Requirement
46
37
  requirements:
47
38
  - - "~>"
48
39
  - !ruby/object:Gem::Version
49
- version: '1.1'
50
- - - "<"
51
- - !ruby/object:Gem::Version
52
- version: '1.99'
40
+ version: '3.1'
53
41
  - !ruby/object:Gem::Dependency
54
42
  name: rspec
55
43
  requirement: !ruby/object:Gem::Requirement
56
44
  requirements:
57
45
  - - "~>"
58
46
  - !ruby/object:Gem::Version
59
- version: '3.0'
47
+ version: '3.9'
60
48
  type: :development
61
49
  prerelease: false
62
50
  version_requirements: !ruby/object:Gem::Requirement
63
51
  requirements:
64
52
  - - "~>"
65
53
  - !ruby/object:Gem::Version
66
- version: '3.0'
54
+ version: '3.9'
67
55
  - !ruby/object:Gem::Dependency
68
56
  name: rspec-its
69
57
  requirement: !ruby/object:Gem::Requirement
70
58
  requirements:
71
59
  - - "~>"
72
60
  - !ruby/object:Gem::Version
73
- version: '1.0'
61
+ version: '1.3'
74
62
  type: :development
75
63
  prerelease: false
76
64
  version_requirements: !ruby/object:Gem::Requirement
77
65
  requirements:
78
66
  - - "~>"
79
67
  - !ruby/object:Gem::Version
80
- version: '1.0'
68
+ version: '1.3'
81
69
  - !ruby/object:Gem::Dependency
82
70
  name: yard
83
71
  requirement: !ruby/object:Gem::Requirement
84
72
  requirements:
85
73
  - - "~>"
86
74
  - !ruby/object:Gem::Version
87
- version: '0.8'
75
+ version: 0.9.20
88
76
  type: :development
89
77
  prerelease: false
90
78
  version_requirements: !ruby/object:Gem::Requirement
91
79
  requirements:
92
80
  - - "~>"
93
81
  - !ruby/object:Gem::Version
94
- version: '0.8'
82
+ version: 0.9.20
95
83
  - !ruby/object:Gem::Dependency
96
84
  name: nokogiri
97
85
  requirement: !ruby/object:Gem::Requirement
98
86
  requirements:
99
87
  - - "~>"
100
88
  - !ruby/object:Gem::Version
101
- version: '1.6'
89
+ version: '1.10'
102
90
  type: :development
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
93
  requirements:
106
94
  - - "~>"
107
95
  - !ruby/object:Gem::Version
108
- version: '1.6'
96
+ version: '1.10'
97
+ - !ruby/object:Gem::Dependency
98
+ name: libxml-ruby
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.0'
109
111
  description: RDF.rb extension for parsing/serializing TriX data.
110
112
  email: public-rdf-ruby@w3.org
111
113
  executables: []
@@ -114,7 +116,7 @@ extra_rdoc_files: []
114
116
  files:
115
117
  - AUTHORS
116
118
  - CREDITS
117
- - README
119
+ - README.md
118
120
  - UNLICENSE
119
121
  - VERSION
120
122
  - etc/doap.xml
@@ -130,7 +132,7 @@ files:
130
132
  - lib/rdf/trix/writer/rexml.rb
131
133
  homepage: http://ruby-rdf.github.com/rdf-trix
132
134
  licenses:
133
- - Public Domain
135
+ - Unlicense
134
136
  metadata: {}
135
137
  post_install_message:
136
138
  rdoc_options: []
@@ -140,17 +142,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
140
142
  requirements:
141
143
  - - ">="
142
144
  - !ruby/object:Gem::Version
143
- version: 1.9.2
145
+ version: '2.4'
144
146
  required_rubygems_version: !ruby/object:Gem::Requirement
145
147
  requirements:
146
148
  - - ">="
147
149
  - !ruby/object:Gem::Version
148
150
  version: '0'
149
151
  requirements: []
150
- rubyforge_project: rdf
151
- rubygems_version: 2.4.5.1
152
+ rubygems_version: 3.0.6
152
153
  signing_key:
153
154
  specification_version: 4
154
155
  summary: TriX support for RDF.rb.
155
156
  test_files: []
156
- has_rdoc: false