rdf-n3 0.3.4.1 → 0.3.5

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.
File without changes
@@ -6,6 +6,10 @@ RDF::N3 is an Notation-3 parser for Ruby using the [RDF.rb][RDF.rb] library sui
6
6
 
7
7
  Reader inspired from TimBL predictiveParser and Python librdf implementation.
8
8
 
9
+ ## Turtle deprecated
10
+ Support for Turtle mime-types and specific format support has been deprecated from this gem,
11
+ as Turtle is now implemented using [RDF::Turtle][RDF::Turtle].
12
+
9
13
  ## Features
10
14
  RDF::N3 parses [Notation-3][N3], [Turtle][Turtle] and [N-Triples][N-Triples] into statements or triples. It also serializes to Turtle.
11
15
 
@@ -94,7 +98,7 @@ Full documentation available on [RubyForge](http://rdf.rubyforge.org/n3)
94
98
 
95
99
  ### Patches
96
100
  * {Array}
97
- * {RDF::Graph}
101
+ * {RDF::List}
98
102
 
99
103
  ## Resources
100
104
  * [RDF.rb][RDF.rb]
@@ -140,10 +144,11 @@ see <http://unlicense.org/> or the accompanying {file:UNLICENSE} file.
140
144
  * <http://github.com/gkellogg/rdf-n3>
141
145
  * <http://lists.w3.org/Archives/Public/public-rdf-ruby/>
142
146
 
143
- [RDF.rb]: http://rdf.rubyforge.org/
144
- [N3]: http://www.w3.org/DesignIssues/Notation3.html "Notation-3"
145
- [Turtle]: http://www.w3.org/TeamSubmission/turtle/
146
- [N-Triples]: http://www.w3.org/2001/sw/RDFCore/ntriples/
147
- [YARD]: http://yardoc.org/
148
- [YARD-GS]: http://rubydoc.info/docs/yard/file/docs/GettingStarted.md
149
- [PDD]: http://lists.w3.org/Archives/Public/public-rdf-ruby/2010May/0013.html
147
+ [RDF.rb]: http://rdf.rubyforge.org/
148
+ [RDF::Turtle] http://github.com/gkellogg/rdf-turtle/
149
+ [N3]: http://www.w3.org/DesignIssues/Notation3.html "Notation-3"
150
+ [Turtle]: http://www.w3.org/TeamSubmission/turtle/
151
+ [N-Triples]: http://www.w3.org/2001/sw/RDFCore/ntriples/
152
+ [YARD]: http://yardoc.org/
153
+ [YARD-GS]: http://rubydoc.info/docs/yard/file/docs/GettingStarted.md
154
+ [PDD]: http://lists.w3.org/Archives/Public/public-rdf-ruby/2010May/0013.html
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.4.1
1
+ 0.3.5
data/lib/rdf/n3.rb CHANGED
@@ -23,7 +23,7 @@ module RDF
23
23
  require 'rdf/n3/format'
24
24
  require 'rdf/n3/vocab'
25
25
  require 'rdf/n3/patches/array_hacks'
26
- require 'rdf/n3/patches/graph_properties'
26
+ require 'rdf/n3/patches/list'
27
27
  autoload :Meta, 'rdf/n3/reader/meta'
28
28
  autoload :Parser, 'rdf/n3/reader/parser'
29
29
  autoload :Reader, 'rdf/n3/reader'
data/lib/rdf/n3/format.rb CHANGED
@@ -4,28 +4,19 @@ module RDF::N3
4
4
  #
5
5
  # @example Obtaining an Notation3 format class
6
6
  # RDF::Format.for(:n3) #=> RDF::N3::Format
7
- # RDF::Format.for("etc/foaf.ttl")
8
7
  # RDF::Format.for("etc/foaf.n3")
9
- # RDF::Format.for(:file_name => "etc/foaf.ttl")
10
8
  # RDF::Format.for(:file_name => "etc/foaf.n3")
11
- # RDF::Format.for(:file_extension => "ttl")
12
9
  # RDF::Format.for(:file_extension => "n3")
13
- # RDF::Format.for(:content_type => "text/turtle")
14
10
  # RDF::Format.for(:content_type => "text/n3")
15
11
  #
16
12
  # @example Obtaining serialization format MIME types
17
- # RDF::Format.content_types #=> {"text/turtle" => [RDF::N3::Format]}
18
13
  # RDF::Format.content_types #=> {"text/n3")" => [RDF::N3::Format]}
19
14
  #
20
15
  # @example Obtaining serialization format file extension mappings
21
- # RDF::Format.file_extensions #=> {:ttl => "text/turtle"}
22
16
  # RDF::Format.file_extensions #=> {:n3 => "text/n3"}
23
17
  #
24
18
  # @see http://www.w3.org/TR/rdf-testcases/#ntriples
25
19
  class Format < RDF::Format
26
- content_type 'text/turtle', :extension => :ttl
27
- content_type 'application/turtle', :extension => :ttl
28
- content_type 'application/x-turtle',:extension => :ttl
29
20
  content_type 'text/n3', :extension => :n3
30
21
  content_type 'text/rdf+n3', :extension => :n3
31
22
  content_type 'application/rdf+n3', :extension => :n3
@@ -47,30 +38,4 @@ module RDF::N3
47
38
  reader { RDF::N3::Reader }
48
39
  writer { RDF::N3::Writer }
49
40
  end
50
-
51
- # Alias for N3 format
52
- #
53
- # This allows the following:
54
- #
55
- # @example Obtaining an TTL format class
56
- # RDF::Format.for(:ttl) # RDF::N3::TTL
57
- # RDF::Format.for(:ttl).reader # RDF::N3::Reader
58
- # RDF::Format.for(:ttl).writer # RDF::N3::Writer
59
- class TTL < RDF::Format
60
- reader { RDF::N3::Reader }
61
- writer { RDF::N3::Writer }
62
- end
63
-
64
- # Aliases for N3 format
65
- #
66
- # This allows the following:
67
- #
68
- # @example Obtaining an Turtle format class
69
- # RDF::Format.for(:turtle) # RDF::N3::Turtle
70
- # RDF::Format.for(:turtle).reader # RDF::N3::Reader
71
- # RDF::Format.for(:turtle).writer # RDF::N3::Writer
72
- class Turtle < RDF::Format
73
- reader { RDF::N3::Reader }
74
- writer { RDF::N3::Writer }
75
- end
76
41
  end
@@ -0,0 +1,36 @@
1
+ module RDF
2
+ class List
3
+ ##
4
+ # Validate the list ensuring that
5
+ # * rdf:rest values are all BNodes are nil
6
+ # * rdf:type, if it exists, is rdf:List
7
+ # * each subject has no properties other than single-valued rdf:first, rdf:rest
8
+ # other than for the first node in the list
9
+ # @return [Boolean]
10
+ def valid?
11
+ li = subject
12
+ while li != RDF.nil do
13
+ rest = nil
14
+ firsts = rests = 0
15
+ @graph.query(:subject => li) do |st|
16
+ case st.predicate
17
+ when RDF.type
18
+ # Be tollerant about rdf:type entries, as some OWL vocabularies use it excessively
19
+ when RDF.first
20
+ firsts += 1
21
+ when RDF.rest
22
+ rest = st.object
23
+ return false unless rest.node? || rest == RDF.nil
24
+ rests += 1
25
+ else
26
+ # First node may have other properties
27
+ return false unless li == subject
28
+ end
29
+ end
30
+ return false unless firsts == 1 && rests == 1
31
+ li = rest
32
+ end
33
+ true
34
+ end
35
+ end
36
+ end
data/lib/rdf/n3/reader.rb CHANGED
@@ -19,6 +19,12 @@ module RDF::N3
19
19
  include Meta
20
20
  include Parser
21
21
 
22
+ ##
23
+ # Missing in 0.3.2
24
+ def base_uri
25
+ @options[:base_uri]
26
+ end
27
+
22
28
  N3_KEYWORDS = %w(a is of has keywords prefix base true false forSome forAny)
23
29
 
24
30
  ##
@@ -88,19 +94,6 @@ module RDF::N3
88
94
  sprintf("#<%s:%#0x(%s)>", self.class.name, __id__, base_uri.to_s)
89
95
  end
90
96
 
91
- ##
92
- # XXX Remove when added to RDF::Reader
93
- # Returns the base URI determined by this reader.
94
- #
95
- # @example
96
- # reader.prefixes[:dc] #=> RDF::URI('http://purl.org/dc/terms/')
97
- #
98
- # @return [Hash{Symbol => RDF::URI}]
99
- # @since 0.3.0
100
- def base_uri
101
- @options[:base_uri]
102
- end
103
-
104
97
  ##
105
98
  # Iterates the given block for each RDF statement in the input.
106
99
  #
@@ -527,20 +520,12 @@ module RDF::N3
527
520
  end
528
521
  elsif anonnode[:pathlist]
529
522
  objects = [anonnode[:pathlist]].flatten.compact
530
- last = objects.pop
531
- first_bnode = bnode
532
- objects.each do |object|
533
- add_triple("anonnode", first_bnode, RDF.first, object)
534
- rest_bnode = RDF::Node.new
535
- add_triple("anonnode", first_bnode, RDF.rest, rest_bnode)
536
- first_bnode = rest_bnode
537
- end
538
- if last
539
- add_triple("anonnode", first_bnode, RDF.first, last)
540
- add_triple("anonnode", first_bnode, RDF.rest, RDF.nil)
541
- else
542
- bnode = RDF.nil
523
+ list = RDF::List.new(bnode, nil, objects)
524
+ list.each_statement do |statement|
525
+ next if statement.predicate == RDF.type && statement.object == RDF.List
526
+ add_triple("anonnode(list)", statement.subject, statement.predicate, statement.object)
543
527
  end
528
+ bnode = RDF.nil if list.empty?
544
529
  end
545
530
  bnode
546
531
  end
data/lib/rdf/n3/writer.rb CHANGED
@@ -1,5 +1,3 @@
1
- require 'rdf/n3/patches/graph_properties'
2
-
3
1
  module RDF::N3
4
2
  ##
5
3
  # A Turtle serialiser in Ruby
@@ -166,7 +164,7 @@ module RDF::N3
166
164
  return nil
167
165
  end
168
166
 
169
- add_debug "get_qname(#{resource}), std? #{RDF::Vocabulary.each.to_a.detect {|v| uri.index(v.to_uri.to_s) == 0}}"
167
+ add_debug "get_qname(#{resource}), std?}"
170
168
  qname = case
171
169
  when @uri_to_qname.has_key?(uri)
172
170
  return @uri_to_qname[uri]
@@ -202,20 +200,11 @@ module RDF::N3
202
200
  # @param [Hash{String => Array<Resource>}] properties A hash of Property to Resource mappings
203
201
  # @return [Array<String>}] Ordered list of properties. Uses predicate_order.
204
202
  def sort_properties(properties)
205
- properties.keys.each do |k|
206
- properties[k] = properties[k].sort do |a, b|
207
- a_li = a.to_s.index(RDF._.to_s) == 0 ? a.to_s.match(/\d+$/).to_s.to_i : a.to_s
208
- b_li = b.to_s.index(RDF._.to_s) == 0 ? b.to_s.match(/\d+$/).to_s.to_i : b.to_s
209
-
210
- a_li <=> b_li
211
- end
212
- end
213
-
214
203
  # Make sorted list of properties
215
204
  prop_list = []
216
205
 
217
206
  predicate_order.each do |prop|
218
- next unless properties[prop]
207
+ next unless properties[prop.to_s]
219
208
  prop_list << prop.to_s
220
209
  end
221
210
 
@@ -224,7 +213,7 @@ module RDF::N3
224
213
  prop_list << prop.to_s
225
214
  end
226
215
 
227
- add_debug "sort_properties: #{prop_list.to_sentence}"
216
+ add_debug "sort_properties: #{prop_list.join(', ')}"
228
217
  prop_list
229
218
  end
230
219
 
@@ -420,34 +409,20 @@ module RDF::N3
420
409
 
421
410
  # Checks if l is a valid RDF list, i.e. no nodes have other properties.
422
411
  def is_valid_list(l)
423
- props = @graph.properties(l)
424
- #add_debug "is_valid_list: #{props.inspect}"
425
- return false unless props.has_key?(RDF.first.to_s) || l == RDF.nil
426
- while l && l != RDF.nil do
427
- #add_debug "is_valid_list(length): #{props.length}"
428
- return false unless props.has_key?(RDF.first.to_s) && props.has_key?(RDF.rest.to_s)
429
- n = props[RDF.rest.to_s]
430
- #add_debug "is_valid_list(n): #{n.inspect}"
431
- return false unless n.is_a?(Array) && n.length == 1
432
- l = n.first
433
- props = @graph.properties(l)
434
- end
435
- #add_debug "is_valid_list: valid"
436
- true
412
+ #add_debug "is_valid_list: #{l.inspect}"
413
+ return RDF::List.new(l, @graph).valid?
437
414
  end
438
415
 
439
416
  def do_list(l)
440
- add_debug "do_list: #{l.inspect}"
417
+ list = RDF::List.new(l, @graph)
418
+ add_debug "do_list: #{list.inspect}"
441
419
  position = :subject
442
- while l do
443
- p = @graph.properties(l)
444
- item = p.fetch(RDF.first.to_s, []).first
445
- if item
446
- path(item, position)
447
- subject_done(l)
448
- position = :object
449
- end
450
- l = p.fetch(RDF.rest.to_s, []).first
420
+ list.each_statement do |st|
421
+ next unless st.predicate == RDF.first
422
+ add_debug " list this: #{st.subject} first: #{st.object}[#{position}]"
423
+ path(st.object, position)
424
+ subject_done(st.subject)
425
+ position = :object
451
426
  end
452
427
  end
453
428
 
@@ -507,13 +482,18 @@ module RDF::N3
507
482
  return if objects.empty?
508
483
 
509
484
  objects.each_with_index do |obj, i|
510
- @output.write(",\n#{indent(2)}") if i > 0
485
+ @output.write(",\n#{indent(4)}") if i > 0
511
486
  path(obj, :object)
512
487
  end
513
488
  end
514
489
 
515
490
  def predicate_list(subject)
516
- properties = @graph.properties(subject)
491
+ properties = {}
492
+ @graph.query(:subject => subject) do |st|
493
+ properties[st.predicate.to_s] ||= []
494
+ properties[st.predicate.to_s] << st.object
495
+ end
496
+
517
497
  prop_list = sort_properties(properties) - [RDF.first.to_s, RDF.rest.to_s]
518
498
  add_debug "predicate_list: #{prop_list.inspect}"
519
499
  return if prop_list.empty?
@@ -558,6 +538,7 @@ module RDF::N3
558
538
  add_debug "statement: #{subject.inspect}, s2?: #{s_squared?(subject)}"
559
539
  subject_done(subject)
560
540
  s_squared(subject) || s_default(subject)
541
+ @output.write("\n")
561
542
  end
562
543
 
563
544
  def is_done?(subject)
metadata CHANGED
@@ -1,23 +1,22 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdf-n3
3
3
  version: !ruby/object:Gem::Version
4
- hash: 69
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 4
10
- - 1
11
- version: 0.3.4.1
9
+ - 5
10
+ version: 0.3.5
12
11
  platform: ruby
13
12
  authors:
14
- - Gregg Kellogg
13
+ - Gregg
14
+ - Kellogg
15
15
  autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-07-11 00:00:00 -07:00
20
- default_executable:
19
+ date: 2011-09-04 00:00:00 Z
21
20
  dependencies:
22
21
  - !ruby/object:Gem::Dependency
23
22
  name: rdf
@@ -89,12 +88,12 @@ dependencies:
89
88
  requirements:
90
89
  - - ">="
91
90
  - !ruby/object:Gem::Version
92
- hash: 21
91
+ hash: 23
93
92
  segments:
94
93
  - 0
95
94
  - 3
96
- - 3
97
- version: 0.3.3
95
+ - 2
96
+ version: 0.3.2
98
97
  type: :development
99
98
  version_requirements: *id005
100
99
  - !ruby/object:Gem::Dependency
@@ -114,9 +113,25 @@ dependencies:
114
113
  type: :development
115
114
  version_requirements: *id006
116
115
  - !ruby/object:Gem::Dependency
117
- name: rdf-isomorphic
116
+ name: rdf-turtle
118
117
  prerelease: false
119
118
  requirement: &id007 !ruby/object:Gem::Requirement
119
+ none: false
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ hash: 23
124
+ segments:
125
+ - 0
126
+ - 0
127
+ - 4
128
+ version: 0.0.4
129
+ type: :development
130
+ version_requirements: *id007
131
+ - !ruby/object:Gem::Dependency
132
+ name: rdf-isomorphic
133
+ prerelease: false
134
+ requirement: &id008 !ruby/object:Gem::Requirement
120
135
  none: false
121
136
  requirements:
122
137
  - - ">="
@@ -128,87 +143,50 @@ dependencies:
128
143
  - 4
129
144
  version: 0.3.4
130
145
  type: :development
131
- version_requirements: *id007
146
+ version_requirements: *id008
132
147
  - !ruby/object:Gem::Dependency
133
148
  name: yard
134
149
  prerelease: false
135
- requirement: &id008 !ruby/object:Gem::Requirement
150
+ requirement: &id009 !ruby/object:Gem::Requirement
136
151
  none: false
137
152
  requirements:
138
153
  - - ">="
139
154
  - !ruby/object:Gem::Version
140
- hash: 3
155
+ hash: 7
141
156
  segments:
142
157
  - 0
143
- version: "0"
158
+ - 6
159
+ - 0
160
+ version: 0.6.0
144
161
  type: :development
145
- version_requirements: *id008
162
+ version_requirements: *id009
146
163
  description: RDF::N3 is an Notation-3 and Turtle reader/writer for the RDF.rb library suite.
147
- email: gregg@kellogg-assoc.com
164
+ email: public-rdf-ruby@w3.org
148
165
  executables: []
149
166
 
150
167
  extensions: []
151
168
 
152
- extra_rdoc_files:
153
- - AUTHORS
154
- - History.md
155
- - README.md
156
- - UNLICENSE
157
- - VERSION
169
+ extra_rdoc_files: []
170
+
158
171
  files:
159
- - .yardopts
172
+ - README.markdown
173
+ - History.markdown
160
174
  - AUTHORS
161
- - History.md
162
- - README
163
- - README.md
164
- - Rakefile
165
- - UNLICENSE
166
175
  - VERSION
167
- - example-files/arnau-registered-vocab.rb
168
- - example-files/arnau-stack-overflow.ttl
169
- - example-files/best-buy.nt
170
- - example-files/dwbutler-mj.n3
171
- - example-files/dwbutler-mj.ttl
172
- - example-files/lee-reilly-list.rb
173
- - example-files/recipe.ttl
174
- - example-files/sp2b.n3
175
- - example.rb
176
- - lib/rdf/n3.rb
176
+ - UNLICENSE
177
177
  - lib/rdf/n3/format.rb
178
178
  - lib/rdf/n3/patches/array_hacks.rb
179
- - lib/rdf/n3/patches/graph_properties.rb
180
- - lib/rdf/n3/reader.rb
181
- - lib/rdf/n3/reader/bnf-rules.n3
179
+ - lib/rdf/n3/patches/list.rb
182
180
  - lib/rdf/n3/reader/meta.rb
183
- - lib/rdf/n3/reader/n3-selectors.n3
184
- - lib/rdf/n3/reader/n3.n3
185
181
  - lib/rdf/n3/reader/parser.rb
182
+ - lib/rdf/n3/reader.rb
186
183
  - lib/rdf/n3/version.rb
187
184
  - lib/rdf/n3/vocab.rb
188
185
  - lib/rdf/n3/writer.rb
189
- - rdf-n3.gemspec
190
- - script/build_meta
191
- - script/console
192
- - script/parse
193
- - script/tc
194
- - script/yard-to-rubyforge
195
- - spec/.gitignore
196
- - spec/cwm_spec.rb
197
- - spec/cwm_test.rb
198
- - spec/format_spec.rb
199
- - spec/matchers.rb
200
- - spec/reader_spec.rb
201
- - spec/spec.opts
202
- - spec/spec_helper.rb
203
- - spec/swap_spec.rb
204
- - spec/swap_test.rb
205
- - spec/turtle_spec.rb
206
- - spec/turtle_test.rb
207
- - spec/writer_spec.rb
208
- has_rdoc: true
186
+ - lib/rdf/n3.rb
209
187
  homepage: http://github.com/gkellogg/rdf-n3
210
- licenses: []
211
-
188
+ licenses:
189
+ - Public Domain
212
190
  post_install_message:
213
191
  rdoc_options: []
214
192
 
@@ -219,10 +197,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
219
197
  requirements:
220
198
  - - ">="
221
199
  - !ruby/object:Gem::Version
222
- hash: 3
200
+ hash: 53
223
201
  segments:
224
- - 0
225
- version: "0"
202
+ - 1
203
+ - 8
204
+ - 1
205
+ version: 1.8.1
226
206
  required_rubygems_version: !ruby/object:Gem::Requirement
227
207
  none: false
228
208
  requirements:
@@ -234,8 +214,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
234
214
  version: "0"
235
215
  requirements: []
236
216
 
237
- rubyforge_project:
238
- rubygems_version: 1.5.0
217
+ rubyforge_project: rdf-n3
218
+ rubygems_version: 1.8.6
239
219
  signing_key:
240
220
  specification_version: 3
241
221
  summary: N3/Turtle reader/writer for RDF.rb.