rdf-n3 1.0.0 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,9 @@
1
1
  # RDF::N3 reader/writer
2
2
  Notation-3 reader/writer for [RDF.rb][RDF.rb] .
3
3
 
4
+ [![Gem Version](https://badge.fury.io/rb/rdf-n3.png)](http://badge.fury.io/rb/rdf-n3)
5
+ [![Build Status](https://travis-ci.org/ruby-rdf/rdf-n3.png?branch=master)](http://travis-ci.org/ruby-rdf/rdf-n3)
6
+
4
7
  ## Description
5
8
  RDF::N3 is an Notation-3 parser for Ruby using the [RDF.rb][RDF.rb] library suite.
6
9
 
@@ -81,7 +84,7 @@ http://www.w3.org/2000/10/swap/grammar/n3.n3 (along with bnf-rules.n3) using cwm
81
84
  * Create equivalent to `--think` to iterate on solutions.
82
85
 
83
86
  ## Dependencies
84
- * [RDF.rb](http://rubygems.org/gems/rdf) (>= 0.3.4)
87
+ * [RDF.rb](http://rubygems.org/gems/rdf) (>= 1.0)
85
88
 
86
89
  ## Documentation
87
90
  Full documentation available on [RubyDoc.info](http://rubydoc.info/github/ruby-rdf/rdf-n3/frames)
@@ -144,11 +147,11 @@ see <http://unlicense.org/> or the accompanying {file:UNLICENSE} file.
144
147
  * <http://github.com/ruby-rdf/rdf-n3>
145
148
  * <http://lists.w3.org/Archives/Public/public-rdf-ruby/>
146
149
 
147
- [RDF.rb]: http://rdf.rubyforge.org/
148
- [RDF::Turtle] http://github.com/ruby-rdf/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
150
+ [RDF.rb]: http://ruby-rdf.github.com/rdf
151
+ [RDF::Turtle]: http://ruby-rdf.github.com/rdf-turtle/
152
+ [N3]: http://www.w3.org/DesignIssues/Notation3.html "Notation-3"
153
+ [Turtle]: http://www.w3.org/TR/turtle/
154
+ [N-Triples]: http://www.w3.org/TR/n-triples/
155
+ [YARD]: http://yardoc.org/
156
+ [YARD-GS]: http://rubydoc.info/docs/yard/file/docs/GettingStarted.md
157
+ [PDD]: http://lists.w3.org/Archives/Public/public-rdf-ruby/2010May/0013.html
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.0.2
data/lib/rdf/n3/reader.rb CHANGED
@@ -59,8 +59,9 @@ module RDF::N3
59
59
 
60
60
  @branches = BRANCHES # Get from meta class
61
61
  @regexps = REGEXPS # Get from meta class
62
-
63
- @formulae = [] # Nodes used as Formluae context identifiers
62
+
63
+ @formulae = [] # Nodes used as Formluae graph names
64
+ @formulae_nodes = {}
64
65
  @variables = {} # variable definitions along with defining formula
65
66
 
66
67
  if options[:base_uri]
@@ -114,17 +115,17 @@ module RDF::N3
114
115
  # Start of production
115
116
  def onStart(prod)
116
117
  handler = "#{prod}Start".to_sym
117
- add_debug("#{handler}(#{respond_to?(handler)})", prod)
118
+ add_debug("#{handler}(#{respond_to?(handler, true)})", prod)
118
119
  @productions << prod
119
- send(handler, prod) if respond_to?(handler)
120
+ send(handler, prod) if respond_to?(handler, true)
120
121
  end
121
122
 
122
123
  # End of production
123
124
  def onFinish
124
125
  prod = @productions.pop()
125
126
  handler = "#{prod}Finish".to_sym
126
- add_debug("#{handler}(#{respond_to?(handler)})") {"#{prod}: #{@prod_data.last.inspect}"}
127
- send(handler) if respond_to?(handler)
127
+ add_debug("#{handler}(#{respond_to?(handler, true)})") {"#{prod}: #{@prod_data.last.inspect}"}
128
+ send(handler) if respond_to?(handler, true)
128
129
  end
129
130
 
130
131
  # Process of a token
@@ -132,8 +133,8 @@ module RDF::N3
132
133
  unless @productions.empty?
133
134
  parentProd = @productions.last
134
135
  handler = "#{parentProd}Token".to_sym
135
- add_debug("#{handler}(#{respond_to?(handler)})") {"#{prod}, #{tok}: #{@prod_data.last.inspect}"}
136
- send(handler, prod, tok) if respond_to?(handler)
136
+ add_debug("#{handler}(#{respond_to?(handler, true)})") {"#{prod}, #{tok}: #{@prod_data.last.inspect}"}
137
+ send(handler, prod, tok) if respond_to?(handler, true)
137
138
  else
138
139
  error("Token has no parent production")
139
140
  end
@@ -312,11 +313,12 @@ module RDF::N3
312
313
  symbol = process_anonnode(@prod_data.pop)
313
314
  add_prod_data(:symbol, symbol)
314
315
  when "{"
315
- # A new formula, push on a graph as a formula context
316
- context = RDF::Graph.new(RDF::Node.new)
317
- @formulae << context
316
+ # A new formula, push on a node as a named graph
317
+ node = RDF::Node.new
318
+ @formulae << node
319
+ @formulae_nodes[node] = true
318
320
  when "}"
319
- # Pop off the formula, and remove any variables defined in this context
321
+ # Pop off the formula, and remove any variables defined in this graph
320
322
  formula = @formulae.pop
321
323
  @variables.delete_if {|k, v| v[:formula] == formula}
322
324
  add_prod_data(:symbol, formula)
@@ -482,7 +484,7 @@ module RDF::N3
482
484
  verb = @prod_data.pop
483
485
  if verb[:expression]
484
486
  error("Literal may not be used as a predicate") if verb[:expression].is_a?(RDF::Literal)
485
- error("Formula may not be used as a peredicate") if verb[:expression].is_a?(RDF::Graph)
487
+ error("Formula may not be used as a peredicate") if @formulae_nodes.has_key?(verb[:expression])
486
488
  add_prod_data(:verb, verb[:expression])
487
489
  add_prod_data(:invert, true) if verb[:invert]
488
490
  else
@@ -498,26 +500,26 @@ module RDF::N3
498
500
 
499
501
  def process_anonnode(anonnode)
500
502
  add_debug("process_anonnode") {anonnode.inspect}
501
- bnode = RDF::Node.new
502
503
 
503
504
  if anonnode[:propertylist]
504
505
  properties = anonnode[:propertylist]
506
+ bnode = RDF::Node.new
505
507
  properties.each do |p|
506
508
  predicate = p[:verb]
507
509
  add_debug("process_anonnode(verb)") {predicate.inspect}
508
510
  objects = [p[:object]].flatten.compact
509
511
  objects.each { |object| add_triple("anonnode", bnode, predicate, object) }
510
512
  end
513
+ bnode
511
514
  elsif anonnode[:pathlist]
512
515
  objects = [anonnode[:pathlist]].flatten.compact
513
- list = RDF::List.new(bnode, nil, objects)
516
+ list = RDF::List[*objects]
514
517
  list.each_statement do |statement|
515
518
  next if statement.predicate == RDF.type && statement.object == RDF.List
516
519
  add_triple("anonnode(list)", statement.subject, statement.predicate, statement.object)
517
520
  end
518
- bnode = RDF.nil if list.empty?
521
+ list.subject
519
522
  end
520
- bnode
521
523
  end
522
524
 
523
525
  # Process a path, such as:
@@ -613,7 +615,7 @@ module RDF::N3
613
615
 
614
616
  # Add debug event to debug array, if specified
615
617
  #
616
- # @param [XML Node, any] node XML Node or string for showing context
618
+ # @param [any] node string for showing context
617
619
  # @param [String] message
618
620
  # @yieldreturn [String] appended to message, to allow for lazy-evaulation of message
619
621
  def add_debug(node, message = "")
@@ -625,19 +627,16 @@ module RDF::N3
625
627
 
626
628
  # add a statement, object can be literal or URI or bnode
627
629
  #
628
- # @param [Nokogiri::XML::Node, any] node XML Node or string for showing context
630
+ # @param [any] node string for showing context
629
631
  # @param [URI, Node] subject the subject of the statement
630
632
  # @param [URI] predicate the predicate of the statement
631
633
  # @param [URI, Node, Literal] object the object of the statement
632
634
  # @return [Statement] Added statement
633
635
  # @raise [RDF::ReaderError] Checks parameter types and raises if they are incorrect if parsing mode is _validate_.
634
636
  def add_triple(node, subject, predicate, object)
635
- context_opts = {:context => @formulae.last.context} if @formulae.last
637
+ context_opts = @formulae.last ? {:context => @formulae.last} : {}
636
638
 
637
- # Replace graph with it's context
638
- subject = subject.context if subject.graph?
639
- object = object.context if object.graph?
640
- statement = RDF::Statement.new(subject, predicate, object, context_opts || {})
639
+ statement = RDF::Statement.new(subject, predicate, object, context_opts)
641
640
  add_debug(node) {statement.to_s}
642
641
  @callback.call(statement)
643
642
  end
data/lib/rdf/n3/writer.rb CHANGED
@@ -15,7 +15,6 @@ module RDF::N3
15
15
  # RDF::Writer.for(:file_extension => "n3")
16
16
  # RDF::Writer.for(:file_extension => "ttl")
17
17
  # RDF::Writer.for(:content_type => "text/n3")
18
- # RDF::Writer.for(:content_type => "text/turtle")
19
18
  #
20
19
  # @example Serializing RDF graph into an Turtle file
21
20
  # RDF::N3::Writer.open("etc/test.n3") do |writer|
metadata CHANGED
@@ -1,169 +1,152 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: rdf-n3
3
- version: !ruby/object:Gem::Version
4
- hash: 23
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.2
5
5
  prerelease:
6
- segments:
7
- - 1
8
- - 0
9
- - 0
10
- version: 1.0.0
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Gregg
14
9
  - Kellogg
15
10
  autorequire:
16
11
  bindir: bin
17
12
  cert_chain: []
18
-
19
- date: 2013-01-19 00:00:00 Z
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
13
+ date: 2013-06-29 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
22
16
  name: rdf
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 15
30
- segments:
31
- - 1
32
- - 0
33
- version: "1.0"
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: 1.0.7
34
23
  type: :runtime
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
37
- name: open-uri-cached
38
24
  prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
40
- none: false
41
- requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- hash: 21
45
- segments:
46
- - 0
47
- - 0
48
- - 5
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: 1.0.7
31
+ - !ruby/object:Gem::Dependency
32
+ name: open-uri-cached
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
49
38
  version: 0.0.5
50
39
  type: :development
51
- version_requirements: *id002
52
- - !ruby/object:Gem::Dependency
53
- name: spira
54
40
  prerelease: false
55
- requirement: &id003 !ruby/object:Gem::Requirement
56
- none: false
57
- requirements:
58
- - - ">="
59
- - !ruby/object:Gem::Version
60
- hash: 7
61
- segments:
62
- - 0
63
- - 0
64
- - 12
65
- version: 0.0.12
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: 0.0.5
47
+ - !ruby/object:Gem::Dependency
48
+ name: json-ld
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
66
55
  type: :development
67
- version_requirements: *id003
68
- - !ruby/object:Gem::Dependency
69
- name: rspec
70
56
  prerelease: false
71
- requirement: &id004 !ruby/object:Gem::Requirement
72
- none: false
73
- requirements:
74
- - - ">="
75
- - !ruby/object:Gem::Version
76
- hash: 47
77
- segments:
78
- - 2
79
- - 8
80
- - 0
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ - !ruby/object:Gem::Dependency
64
+ name: rspec
65
+ requirement: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
81
70
  version: 2.8.0
82
71
  type: :development
83
- version_requirements: *id004
84
- - !ruby/object:Gem::Dependency
85
- name: rdf-spec
86
72
  prerelease: false
87
- requirement: &id005 !ruby/object:Gem::Requirement
88
- none: false
89
- requirements:
90
- - - ">="
91
- - !ruby/object:Gem::Version
92
- hash: 15
93
- segments:
94
- - 1
95
- - 0
96
- version: "1.0"
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: 2.8.0
79
+ - !ruby/object:Gem::Dependency
80
+ name: rdf-spec
81
+ requirement: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '1.0'
97
87
  type: :development
98
- version_requirements: *id005
99
- - !ruby/object:Gem::Dependency
100
- name: rdf-rdfxml
101
88
  prerelease: false
102
- requirement: &id006 !ruby/object:Gem::Requirement
103
- none: false
104
- requirements:
105
- - - ">="
106
- - !ruby/object:Gem::Version
107
- hash: 3
108
- segments:
109
- - 0
110
- version: "0"
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '1.0'
95
+ - !ruby/object:Gem::Dependency
96
+ name: rdf-rdfxml
97
+ requirement: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
111
103
  type: :development
112
- version_requirements: *id006
113
- - !ruby/object:Gem::Dependency
114
- name: rdf-turtle
115
104
  prerelease: false
116
- requirement: &id007 !ruby/object:Gem::Requirement
117
- none: false
118
- requirements:
119
- - - ">="
120
- - !ruby/object:Gem::Version
121
- hash: 3
122
- segments:
123
- - 0
124
- version: "0"
125
- type: :development
126
- version_requirements: *id007
127
- - !ruby/object:Gem::Dependency
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
128
112
  name: rdf-isomorphic
129
- prerelease: false
130
- requirement: &id008 !ruby/object:Gem::Requirement
131
- none: false
132
- requirements:
133
- - - ">="
134
- - !ruby/object:Gem::Version
135
- hash: 3
136
- segments:
137
- - 0
138
- version: "0"
113
+ requirement: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ! '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
139
119
  type: :development
140
- version_requirements: *id008
141
- - !ruby/object:Gem::Dependency
142
- name: yard
143
120
  prerelease: false
144
- requirement: &id009 !ruby/object:Gem::Requirement
145
- none: false
146
- requirements:
147
- - - ">="
148
- - !ruby/object:Gem::Version
149
- hash: 57
150
- segments:
151
- - 0
152
- - 8
153
- - 3
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ! '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ - !ruby/object:Gem::Dependency
128
+ name: yard
129
+ requirement: !ruby/object:Gem::Requirement
130
+ none: false
131
+ requirements:
132
+ - - ! '>='
133
+ - !ruby/object:Gem::Version
154
134
  version: 0.8.3
155
135
  type: :development
156
- version_requirements: *id009
136
+ prerelease: false
137
+ version_requirements: !ruby/object:Gem::Requirement
138
+ none: false
139
+ requirements:
140
+ - - ! '>='
141
+ - !ruby/object:Gem::Version
142
+ version: 0.8.3
157
143
  description: RDF::N3 is an Notation-3 reader/writer for the RDF.rb library suite.
158
144
  email: public-rdf-ruby@w3.org
159
145
  executables: []
160
-
161
146
  extensions: []
162
-
163
147
  extra_rdoc_files: []
164
-
165
- files:
166
- - README.markdown
148
+ files:
149
+ - README.md
167
150
  - History.markdown
168
151
  - AUTHORS
169
152
  - VERSION
@@ -178,41 +161,30 @@ files:
178
161
  - lib/rdf/n3/vocab.rb
179
162
  - lib/rdf/n3/writer.rb
180
163
  - lib/rdf/n3.rb
181
- homepage: http://github.com/ruby-rdf/rdf-n3
182
- licenses:
164
+ homepage: http://ruby-rdf.github.com/rdf-n3
165
+ licenses:
183
166
  - Public Domain
184
167
  post_install_message:
185
168
  rdoc_options: []
186
-
187
- require_paths:
169
+ require_paths:
188
170
  - lib
189
- required_ruby_version: !ruby/object:Gem::Requirement
171
+ required_ruby_version: !ruby/object:Gem::Requirement
190
172
  none: false
191
- requirements:
192
- - - ">="
193
- - !ruby/object:Gem::Version
194
- hash: 53
195
- segments:
196
- - 1
197
- - 8
198
- - 1
173
+ requirements:
174
+ - - ! '>='
175
+ - !ruby/object:Gem::Version
199
176
  version: 1.8.1
200
- required_rubygems_version: !ruby/object:Gem::Requirement
177
+ required_rubygems_version: !ruby/object:Gem::Requirement
201
178
  none: false
202
- requirements:
203
- - - ">="
204
- - !ruby/object:Gem::Version
205
- hash: 3
206
- segments:
207
- - 0
208
- version: "0"
179
+ requirements:
180
+ - - ! '>='
181
+ - !ruby/object:Gem::Version
182
+ version: '0'
209
183
  requirements: []
210
-
211
184
  rubyforge_project: rdf-n3
212
- rubygems_version: 1.8.24
185
+ rubygems_version: 1.8.25
213
186
  signing_key:
214
187
  specification_version: 3
215
188
  summary: Notation3 reader/writer for RDF.rb.
216
189
  test_files: []
217
-
218
190
  has_rdoc: false