rdf-trig 1.0.0.beta3 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/README.md +5 -1
  2. data/VERSION +1 -1
  3. data/lib/rdf/trig/reader.rb +200 -7
  4. metadata +35 -10
  5. checksums.yaml +0 -15
data/README.md CHANGED
@@ -1,6 +1,10 @@
1
- # RDF::TriG reader/writer [![Build Status](https://secure.travis-ci.org/ruby-rdf/rdf-trig.png?branch=master)](http://travis-ci.org/ruby-rdf/rdf-trig)
1
+ # RDF::TriG reader/writer
2
+
2
3
  [TriG][] reader/writer for [RDF.rb][RDF.rb] .
3
4
 
5
+ [![Gem Version](https://badge.fury.io/rb/rdf-trig.png)](http://badge.fury.io/rb/rdf-trig)
6
+ [![Build Status](https://travis-ci.org/ruby-rdf/rdf-trig.png?branch=master)](http://travis-ci.org/ruby-rdf/rdf-trig)
7
+
4
8
  ## Description
5
9
  This is a [Ruby][] implementation of a [TriG][] reader and writer for [RDF.rb][].
6
10
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0.beta3
1
+ 1.0.0
@@ -10,6 +10,62 @@ module RDF::TriG
10
10
  format Format
11
11
  include RDF::TriG::Meta
12
12
 
13
+ # Terminals passed to lexer. Order matters!
14
+ terminal(:ANON, ANON) do |prod, token, input|
15
+ input[:resource] = self.bnode
16
+ end
17
+ terminal(:BLANK_NODE_LABEL, BLANK_NODE_LABEL) do |prod, token, input|
18
+ input[:resource] = self.bnode(token.value[2..-1])
19
+ end
20
+ terminal(:IRIREF, IRIREF, :unescape => true) do |prod, token, input|
21
+ input[:resource] = process_iri(token.value[1..-2])
22
+ end
23
+ terminal(:DOUBLE, DOUBLE) do |prod, token, input|
24
+ # Note that a Turtle Double may begin with a '.[eE]', so tack on a leading
25
+ # zero if necessary
26
+ value = token.value.sub(/\.([eE])/, '.0\1')
27
+ input[:resource] = literal(value, :datatype => RDF::XSD.double)
28
+ end
29
+ terminal(:DECIMAL, DECIMAL) do |prod, token, input|
30
+ # Note that a Turtle Decimal may begin with a '.', so tack on a leading
31
+ # zero if necessary
32
+ value = token.value
33
+ value = "0#{token.value}" if token.value[0,1] == "."
34
+ input[:resource] = literal(value, :datatype => RDF::XSD.decimal)
35
+ end
36
+ terminal(:INTEGER, INTEGER) do |prod, token, input|
37
+ input[:resource] = literal(token.value, :datatype => RDF::XSD.integer)
38
+ end
39
+ # Spec confusion: spec says : "Literals , prefixed names and IRIs may also contain escape sequences"
40
+ terminal(:PNAME_LN, PNAME_LN, :unescape => true) do |prod, token, input|
41
+ prefix, suffix = token.value.split(":", 2)
42
+ input[:resource] = pname(prefix, suffix)
43
+ end
44
+ # Spec confusion: spec says : "Literals , prefixed names and IRIs may also contain escape sequences"
45
+ terminal(:PNAME_NS, PNAME_NS) do |prod, token, input|
46
+ prefix = token.value[0..-2]
47
+
48
+ # Two contexts, one when prefix is being defined, the other when being used
49
+ case prod
50
+ when :prefixID, :sparqlPrefix
51
+ input[:prefix] = prefix
52
+ else
53
+ input[:resource] = pname(prefix, '')
54
+ end
55
+ end
56
+ terminal(:STRING_LITERAL_LONG_SINGLE_QUOTE, STRING_LITERAL_LONG_SINGLE_QUOTE, :unescape => true) do |prod, token, input|
57
+ input[:string_value] = token.value[3..-4]
58
+ end
59
+ terminal(:STRING_LITERAL_LONG_QUOTE, STRING_LITERAL_LONG_QUOTE, :unescape => true) do |prod, token, input|
60
+ input[:string_value] = token.value[3..-4]
61
+ end
62
+ terminal(:STRING_LITERAL_QUOTE, STRING_LITERAL_QUOTE, :unescape => true) do |prod, token, input|
63
+ input[:string_value] = token.value[1..-2]
64
+ end
65
+ terminal(:STRING_LITERAL_SINGLE_QUOTE, STRING_LITERAL_SINGLE_QUOTE, :unescape => true) do |prod, token, input|
66
+ input[:string_value] = token.value[1..-2]
67
+ end
68
+
13
69
  # String terminals
14
70
  terminal(nil, %r([\{\}\(\),.;\[\]a]|\^\^|@base|@prefix|true|false)) do |prod, token, input|
15
71
  case token.value
@@ -20,6 +76,17 @@ module RDF::TriG
20
76
  end
21
77
  end
22
78
 
79
+ terminal(:LANGTAG, LANGTAG) do |prod, token, input|
80
+ input[:lang] = token.value[1..-1]
81
+ end
82
+
83
+ terminal(:SPARQL_PREFIX, SPARQL_PREFIX) do |prod, token, input|
84
+ input[:string_value] = token.value.downcase
85
+ end
86
+ terminal(:SPARQL_BASE, SPARQL_BASE) do |prod, token, input|
87
+ input[:string_value] = token.value.downcase
88
+ end
89
+
23
90
  # Productions
24
91
  # [3g] graph defines the basic creation of context
25
92
  start_production(:graph) do |input, current, callback|
@@ -28,7 +95,7 @@ module RDF::TriG
28
95
  production(:graph) do |input, current, callback|
29
96
  callback.call(:context, "graph", nil)
30
97
  end
31
-
98
+
32
99
  # [4g] graphIri
33
100
  # Normally, just returns the IRIref, but if called from [3g], also
34
101
  # sets the context for triples defined within that graph
@@ -37,7 +104,121 @@ module RDF::TriG
37
104
  debug("graphIri") {"Set graph context to #{current[:resource]}"}
38
105
  callback.call(:context, "graphIri", current[:resource])
39
106
  end
40
-
107
+
108
+
109
+ # Productions
110
+ # [4] prefixID defines a prefix mapping
111
+ production(:prefixID) do |input, current, callback|
112
+ prefix = current[:prefix]
113
+ iri = current[:resource]
114
+ debug("prefixID") {"Defined prefix #{prefix.inspect} mapping to #{iri.inspect}"}
115
+ prefix(prefix, iri)
116
+ end
117
+
118
+ # [5] base set base_uri
119
+ production(:base) do |input, current, callback|
120
+ iri = current[:resource]
121
+ debug("base") {"Defined base as #{iri}"}
122
+ options[:base_uri] = iri
123
+ end
124
+
125
+ # [28s] sparqlPrefix ::= [Pp][Rr][Ee][Ff][Ii][Xx] PNAME_NS IRIREF
126
+ production(:sparqlPrefix) do |input, current, callback|
127
+ prefix = current[:prefix]
128
+ iri = current[:resource]
129
+ debug("sparqlPrefix") {"Defined prefix #{prefix.inspect} mapping to #{iri.inspect}"}
130
+ prefix(prefix, iri)
131
+ end
132
+
133
+ # [29s] sparqlBase ::= [Bb][Aa][Ss][Ee] IRIREF
134
+ production(:sparqlBase) do |input, current, callback|
135
+ iri = current[:resource]
136
+ debug("base") {"Defined base as #{iri}"}
137
+ options[:base_uri] = iri
138
+ end
139
+
140
+ # [6] triples
141
+ start_production(:triples) do |input, current, callback|
142
+ # Note production as triples for blankNodePropertyList
143
+ # to set :subject instead of :resource
144
+ current[:triples] = true
145
+ end
146
+ production(:triples) do |input, current, callback|
147
+ # Note production as triples for blankNodePropertyList
148
+ # to set :subject instead of :resource
149
+ current[:triples] = true
150
+ end
151
+
152
+ # [9] verb ::= predicate | "a"
153
+ production(:verb) do |input, current, callback|
154
+ input[:predicate] = current[:resource]
155
+ end
156
+
157
+ # [10] subject ::= IRIref | BlankNode | collection
158
+ start_production(:subject) do |input, current, callback|
159
+ current[:triples] = nil
160
+ end
161
+
162
+ production(:subject) do |input, current, callback|
163
+ input[:subject] = current[:resource]
164
+ end
165
+
166
+ # [12] object ::= iri | BlankNode | collection | blankNodePropertyList | literal
167
+ production(:object) do |input, current, callback|
168
+ if input[:object_list]
169
+ # Part of an rdf:List collection
170
+ input[:object_list] << current[:resource]
171
+ else
172
+ debug("object") {"current: #{current.inspect}"}
173
+ callback.call(:statement, "object", input[:subject], input[:predicate], current[:resource])
174
+ end
175
+ end
176
+
177
+ # [14] blankNodePropertyList ::= "[" predicateObjectList "]"
178
+ start_production(:blankNodePropertyList) do |input, current, callback|
179
+ current[:subject] = self.bnode
180
+ end
181
+
182
+ production(:blankNodePropertyList) do |input, current, callback|
183
+ if input[:triples]
184
+ input[:subject] = current[:subject]
185
+ else
186
+ input[:resource] = current[:subject]
187
+ end
188
+ end
189
+
190
+ # [15] collection ::= "(" object* ")"
191
+ start_production(:collection) do |input, current, callback|
192
+ # Tells the object production to collect and not generate statements
193
+ current[:object_list] = []
194
+ end
195
+
196
+ production(:collection) do |input, current, callback|
197
+ # Create an RDF list
198
+ bnode = self.bnode
199
+ objects = current[:object_list]
200
+ list = RDF::List.new(bnode, nil, objects)
201
+ list.each_statement do |statement|
202
+ # Spec Confusion, referenced section "Collection" is missing from the spec.
203
+ # Anicdodal evidence indicates that some expect each node to be of type rdf:list,
204
+ # but existing Notation3 and Turtle tests (http://www.w3.org/2001/sw/DataAccess/df1/tests/manifest.ttl) do not.
205
+ next if statement.predicate == RDF.type && statement.object == RDF.List
206
+ callback.call(:statement, "collection", statement.subject, statement.predicate, statement.object)
207
+ end
208
+ bnode = RDF.nil if list.empty?
209
+
210
+ # Return bnode as resource
211
+ input[:resource] = bnode
212
+ end
213
+
214
+ # [16] RDFLiteral ::= String ( LanguageTag | ( "^^" IRIref ) )?
215
+ production(:RDFLiteral) do |input, current, callback|
216
+ opts = {}
217
+ opts[:datatype] = current[:resource] if current[:resource]
218
+ opts[:language] = current[:lang] if current[:lang]
219
+ input[:resource] = literal(current[:string_value], opts)
220
+ end
221
+
41
222
  ##
42
223
  # Iterates the given block for each RDF statement in the input.
43
224
  #
@@ -49,25 +230,37 @@ module RDF::TriG
49
230
 
50
231
  parse(@input, START.to_sym, @options.merge(:branch => BRANCH,
51
232
  :first => FIRST,
52
- :follow => FOLLOW)
233
+ :follow => FOLLOW,
234
+ :reset_on_start => true)
53
235
  ) do |context, *data|
54
- loc = data.shift
55
236
  case context
56
237
  when :context
57
- @context = data[0]
238
+ @context = data[1]
58
239
  when :statement
59
240
  data << @context if @context
60
241
  debug("each_statement") {"data: #{data.inspect}, context: #{@context.inspect}"}
242
+ loc = data.shift
61
243
  add_statement(loc, RDF::Statement.from(data))
62
244
  when :trace
63
- debug(loc, *data)
245
+ level, lineno, depth, *args = data
246
+ message = "#{args.join(': ')}"
247
+ d_str = depth > 100 ? ' ' * 100 + '+' : ' ' * depth
248
+ str = "[#{lineno}](#{level})#{d_str}#{message}"
249
+ case @options[:debug]
250
+ when Array
251
+ @options[:debug] << str
252
+ when TrueClass
253
+ $stderr.puts str
254
+ when Integer
255
+ $stderr.puts(str) if level <= @options[:debug]
256
+ end
64
257
  end
65
258
  end
66
259
  rescue EBNF::LL1::Parser::Error => e
67
260
  debug("Parsing completed with errors:\n\t#{e.message}")
68
261
  raise RDF::ReaderError, e.message if validate?
69
262
  end
70
-
263
+
71
264
  ##
72
265
  # Iterates the given block for each RDF quad in the input.
73
266
  #
metadata CHANGED
@@ -1,18 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdf-trig
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.beta3
4
+ version: 1.0.0
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Gregg Kellogg
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-03-24 00:00:00.000000000 Z
12
+ date: 2013-05-11 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: rdf
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
19
  - - ! '>='
18
20
  - !ruby/object:Gem::Version
@@ -20,6 +22,7 @@ dependencies:
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
27
  - - ! '>='
25
28
  - !ruby/object:Gem::Version
@@ -27,6 +30,7 @@ dependencies:
27
30
  - !ruby/object:Gem::Dependency
28
31
  name: ebnf
29
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
30
34
  requirements:
31
35
  - - ! '>='
32
36
  - !ruby/object:Gem::Version
@@ -34,6 +38,7 @@ dependencies:
34
38
  type: :runtime
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
43
  - - ! '>='
39
44
  - !ruby/object:Gem::Version
@@ -41,20 +46,23 @@ dependencies:
41
46
  - !ruby/object:Gem::Dependency
42
47
  name: rdf-turtle
43
48
  requirement: !ruby/object:Gem::Requirement
49
+ none: false
44
50
  requirements:
45
51
  - - ! '>='
46
52
  - !ruby/object:Gem::Version
47
- version: '1.0'
53
+ version: 1.0.4
48
54
  type: :runtime
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
51
58
  requirements:
52
59
  - - ! '>='
53
60
  - !ruby/object:Gem::Version
54
- version: '1.0'
61
+ version: 1.0.4
55
62
  - !ruby/object:Gem::Dependency
56
63
  name: open-uri-cached
57
64
  requirement: !ruby/object:Gem::Requirement
65
+ none: false
58
66
  requirements:
59
67
  - - ! '>='
60
68
  - !ruby/object:Gem::Version
@@ -62,6 +70,7 @@ dependencies:
62
70
  type: :development
63
71
  prerelease: false
64
72
  version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
65
74
  requirements:
66
75
  - - ! '>='
67
76
  - !ruby/object:Gem::Version
@@ -69,6 +78,7 @@ dependencies:
69
78
  - !ruby/object:Gem::Dependency
70
79
  name: json-ld
71
80
  requirement: !ruby/object:Gem::Requirement
81
+ none: false
72
82
  requirements:
73
83
  - - ! '>='
74
84
  - !ruby/object:Gem::Version
@@ -76,6 +86,7 @@ dependencies:
76
86
  type: :development
77
87
  prerelease: false
78
88
  version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
79
90
  requirements:
80
91
  - - ! '>='
81
92
  - !ruby/object:Gem::Version
@@ -83,6 +94,7 @@ dependencies:
83
94
  - !ruby/object:Gem::Dependency
84
95
  name: rspec
85
96
  requirement: !ruby/object:Gem::Requirement
97
+ none: false
86
98
  requirements:
87
99
  - - ! '>='
88
100
  - !ruby/object:Gem::Version
@@ -90,6 +102,7 @@ dependencies:
90
102
  type: :development
91
103
  prerelease: false
92
104
  version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
93
106
  requirements:
94
107
  - - ! '>='
95
108
  - !ruby/object:Gem::Version
@@ -97,6 +110,7 @@ dependencies:
97
110
  - !ruby/object:Gem::Dependency
98
111
  name: rdf-isomorphic
99
112
  requirement: !ruby/object:Gem::Requirement
113
+ none: false
100
114
  requirements:
101
115
  - - ! '>='
102
116
  - !ruby/object:Gem::Version
@@ -104,6 +118,7 @@ dependencies:
104
118
  type: :development
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
107
122
  requirements:
108
123
  - - ! '>='
109
124
  - !ruby/object:Gem::Version
@@ -111,6 +126,7 @@ dependencies:
111
126
  - !ruby/object:Gem::Dependency
112
127
  name: yard
113
128
  requirement: !ruby/object:Gem::Requirement
129
+ none: false
114
130
  requirements:
115
131
  - - ! '>='
116
132
  - !ruby/object:Gem::Version
@@ -118,6 +134,7 @@ dependencies:
118
134
  type: :development
119
135
  prerelease: false
120
136
  version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
121
138
  requirements:
122
139
  - - ! '>='
123
140
  - !ruby/object:Gem::Version
@@ -125,6 +142,7 @@ dependencies:
125
142
  - !ruby/object:Gem::Dependency
126
143
  name: rdf-spec
127
144
  requirement: !ruby/object:Gem::Requirement
145
+ none: false
128
146
  requirements:
129
147
  - - ! '>='
130
148
  - !ruby/object:Gem::Version
@@ -132,6 +150,7 @@ dependencies:
132
150
  type: :development
133
151
  prerelease: false
134
152
  version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
135
154
  requirements:
136
155
  - - ! '>='
137
156
  - !ruby/object:Gem::Version
@@ -139,6 +158,7 @@ dependencies:
139
158
  - !ruby/object:Gem::Dependency
140
159
  name: rake
141
160
  requirement: !ruby/object:Gem::Requirement
161
+ none: false
142
162
  requirements:
143
163
  - - ! '>='
144
164
  - !ruby/object:Gem::Version
@@ -146,6 +166,7 @@ dependencies:
146
166
  type: :development
147
167
  prerelease: false
148
168
  version_requirements: !ruby/object:Gem::Requirement
169
+ none: false
149
170
  requirements:
150
171
  - - ! '>='
151
172
  - !ruby/object:Gem::Version
@@ -167,29 +188,33 @@ files:
167
188
  - lib/rdf/trig/version.rb
168
189
  - lib/rdf/trig/writer.rb
169
190
  - lib/rdf/trig.rb
170
- homepage: http://github.com/ruby-rdf/rdf-trig
191
+ homepage: http://ruby-rdf.github.com/rdf-trig
171
192
  licenses:
172
193
  - Public Domain
173
- metadata: {}
174
194
  post_install_message:
175
195
  rdoc_options: []
176
196
  require_paths:
177
197
  - lib
178
198
  required_ruby_version: !ruby/object:Gem::Requirement
199
+ none: false
179
200
  requirements:
180
201
  - - ! '>='
181
202
  - !ruby/object:Gem::Version
182
203
  version: 1.8.1
183
204
  required_rubygems_version: !ruby/object:Gem::Requirement
205
+ none: false
184
206
  requirements:
185
- - - ! '>'
207
+ - - ! '>='
186
208
  - !ruby/object:Gem::Version
187
- version: 1.3.1
209
+ version: '0'
210
+ segments:
211
+ - 0
212
+ hash: 3391794697366494735
188
213
  requirements: []
189
214
  rubyforge_project: rdf-trig
190
- rubygems_version: 2.0.3
215
+ rubygems_version: 1.8.25
191
216
  signing_key:
192
- specification_version: 4
217
+ specification_version: 3
193
218
  summary: TriG reader/writer for Ruby.
194
219
  test_files: []
195
220
  has_rdoc: false
checksums.yaml DELETED
@@ -1,15 +0,0 @@
1
- ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ZDc0OWU2MTY0ZWYwNTc3MDk3YTdkZTM0YTVmN2FiZDI3Yzg0NzdmZg==
5
- data.tar.gz: !binary |-
6
- YjYzNzFlNmEzNTYwMGVjOWU2M2ZkZjEwMWE4YTg1ZjY1NjFlODA0OQ==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- MWVlNjU0NDhmMDA1YmJiZmVjOTA0ZTVhYjRmNDhhZDc2M2Q2ODFjYjM3ZjUw
10
- MGQ1ZTZkZTY5NGU4MzM2ZTA5YWM5NGUwZWEyNGNjNDE1YzZlMjk1MTQwMzI4
11
- OTU5Yjg3NGI0MzU1OWM1ZGZkNTE5MGFiOTczZGQ4M2I5MWFkNjY=
12
- data.tar.gz: !binary |-
13
- NThhZjllOTU0MjcxNGQzOGM2N2Y5ZmMwMmE1OTBhOWQ3NTg0ODE0ZDEyZTdm
14
- OTljOTk1Mzg0MDQ0MmFhODk3MDk2N2Y1OTViMmY2MWJkODYxYmJmYzAwMGUz
15
- NGRiNTkzZjNlNjVhYWZmNTBiMjIyZDcyYjczZjRiOTA2MmZkYzE=