rdf-turtle 1.0.8 → 1.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
- ---
2
- SHA1:
3
- metadata.gz: c68accbd136340b3f800311160c941f8e4a49918
4
- data.tar.gz: cd836cf67206a0ac55fa42d24f4f86787cb9ccb9
5
- SHA512:
6
- metadata.gz: cc9d22cd4cf0409a63c54b0c7d866778f2edbedf3df8b1c0dc73b22ab2c95514c0fadbc02d4a20a509e04e956807355a6d859b9d23538e0d1bcdd0832ab820b9
7
- data.tar.gz: 3598c50ae9c4d4d485b9da24ad59870d26034bd428a3b0914c6bff0708853d28b5df4fc83d674185685e67071a1eac87e2412fafe409966d4142374e62c04aa0
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MWFjZTgwYTA4YmJmMDk2NDZkZGQ1YjA3MTkxMmY1ZDFhM2ViMDBlNg==
5
+ data.tar.gz: !binary |-
6
+ MDhmM2ZlOWEwYjdlYmY4MWU4NTM1YmY3MjdlOTFiOTEwOGU4NWYzMQ==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ NDQ3ODc2YWMwY2I5YzhlOGY0ZmQxOThhMzcyM2U5ZDE4OTU3NDNmNjFkZjVl
10
+ YWU0MTg3Y2I3MDQzN2Q4MDYxNDlkMzVjYTFhZDZhMWY4ZmQzNjBjNzkyZWRk
11
+ NjBiYzVjY2RmNGY2MjUzNzQyMzIxNjI5M2E4YjI4OTc4NGJlYTE=
12
+ data.tar.gz: !binary |-
13
+ ODQ3Njk3ZWM3NGFiZGJlNzE2ODcxMzRiNGQ0Mjg5NzIzYmI0Y2EzMDQyN2Rj
14
+ YWI4ZjA3M2EzMjJjMzliMTgyYjRmNmM2MDdkYzAzYjRmMjgwYzkwOGVkZDk3
15
+ NGY0MmY2MmVkZmVhOGFlYWY1MTMwMTdjYmQ2NDQ5NTk1NzZiNDQ=
data/README.md CHANGED
@@ -16,6 +16,7 @@ Install with `gem install rdf-turtle`
16
16
  * 100% free and unencumbered [public domain](http://unlicense.org/) software.
17
17
  * Implements a complete parser for [Turtle][].
18
18
  * Compatible with Ruby 1.8.7+, Ruby >= 1.9, and JRuby 1.7+.
19
+ * Optional streaming writer, to serialize large graphs
19
20
 
20
21
  ## Usage
21
22
  Instantiate a reader from a local file:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.8
1
+ 1.0.9
@@ -0,0 +1,52 @@
1
+ require 'rdf/turtle/terminals'
2
+
3
+ module RDF::Turtle
4
+ ##
5
+ # Streaming writer interface
6
+ # @author [Gregg Kellogg](http://greggkellogg.net/)
7
+ module StreamingWriter
8
+ ##
9
+ # Write out declarations
10
+ # @return [void] `self`
11
+ def stream_prologue
12
+ if @options[:standard_prefixes]
13
+ RDF::Vocabulary.each do |vocab|
14
+ pfx = vocab.__name__.to_s.split('::').last.downcase
15
+ prefix(pfx, vocab.to_uri)
16
+ end
17
+ end
18
+ preprocess
19
+ start_document
20
+ @output.puts ""
21
+ self
22
+ end
23
+
24
+ ##
25
+ # Write out a statement, retaining current
26
+ # `subject` and `predicate` to create more compact output
27
+ # @return [void] `self`
28
+ def stream_statement(statement)
29
+ if statement.subject != @streaming_subject
30
+ @output.puts ' .' if @streaming_subject
31
+ @streaming_subject, @streaming_predicate = statement.subject, statement.predicate
32
+ @output.write "#{format_term(statement.subject)} "
33
+ @output.write "#{format_term(statement.predicate)} "
34
+ elsif statement.predicate != @streaming_predicate
35
+ @streaming_predicate = statement.predicate
36
+ @output.write ";\n#{indent(1)}#{format_term(statement.predicate)} "
37
+ else
38
+ @output.write ",\n#{indent(2)}"
39
+ end
40
+ @output.write("#{format_term(statement.object)}")
41
+ end
42
+
43
+ ##
44
+ # Complete open statements
45
+ # @return [void] `self`
46
+ def stream_epilogue
47
+ @output.puts ' .' if @streaming_subject
48
+ end
49
+
50
+ private
51
+ end
52
+ end
@@ -1,4 +1,5 @@
1
1
  require 'rdf/turtle/terminals'
2
+ require 'rdf/turtle/streaming_writer'
2
3
 
3
4
  module RDF::Turtle
4
5
  ##
@@ -34,6 +35,13 @@ module RDF::Turtle
34
35
  # end
35
36
  # end
36
37
  #
38
+ # @example Serializing RDF statements to a string in streaming mode
39
+ # RDF::Turtle::Writer.buffer(:stream => true) do |writer|
40
+ # graph.each_statement do |statement|
41
+ # writer << statement
42
+ # end
43
+ # end
44
+ #
37
45
  # The writer will add prefix definitions, and use them for creating @prefix definitions, and minting QNames
38
46
  #
39
47
  # @example Creating @base and @prefix definitions in output
@@ -48,12 +56,11 @@ module RDF::Turtle
48
56
  #
49
57
  # @author [Gregg Kellogg](http://greggkellogg.net/)
50
58
  class Writer < RDF::Writer
59
+ include StreamingWriter
51
60
  format RDF::Turtle::Format
52
61
 
53
62
  # @return [Graph] Graph of statements serialized
54
63
  attr_accessor :graph
55
- # @return [URI] Base URI used for relativizing URIs
56
- attr_accessor :base_uri
57
64
 
58
65
  ##
59
66
  # Initializes the Turtle writer instance.
@@ -74,6 +81,8 @@ module RDF::Turtle
74
81
  # Maximum depth for recursively defining resources, defaults to 3
75
82
  # @option options [Boolean] :standard_prefixes (false)
76
83
  # Add standard prefixes to @prefixes, if necessary.
84
+ # @option options [Boolean] :stream (false)
85
+ # Do not attempt to optimize graph presentation, suitable for streaming large graphs.
77
86
  # @option options [String] :default_namespace (nil)
78
87
  # URI to use as default namespace, same as `prefixes[nil]`
79
88
  # @yield [writer] `self`
@@ -82,10 +91,11 @@ module RDF::Turtle
82
91
  # @yield [writer]
83
92
  # @yieldparam [RDF::Writer] writer
84
93
  def initialize(output = $stdout, options = {}, &block)
94
+ reset
95
+ @graph = RDF::Graph.new
96
+ @uri_to_pname = {}
97
+ @uri_to_prefix = {}
85
98
  super do
86
- @graph = RDF::Graph.new
87
- @uri_to_pname = {}
88
- @uri_to_prefix = {}
89
99
  if block_given?
90
100
  case block.arity
91
101
  when 0 then instance_eval(&block)
@@ -95,21 +105,18 @@ module RDF::Turtle
95
105
  end
96
106
  end
97
107
 
98
- ##
99
- # Write whole graph
100
- #
101
- # @param [Graph] graph
102
- # @return [void]
103
- def write_graph(graph)
104
- @graph = graph
105
- end
106
-
107
108
  ##
108
109
  # Adds a statement to be serialized
109
110
  # @param [RDF::Statement] statement
110
111
  # @return [void]
111
112
  def write_statement(statement)
112
- @graph.insert(statement)
113
+ case
114
+ when @options[:stream]
115
+ stream_statement(statement)
116
+ else
117
+ # Add to local graph and output in epilogue
118
+ @graph.insert(statement)
119
+ end
113
120
  end
114
121
 
115
122
  ##
@@ -118,10 +125,19 @@ module RDF::Turtle
118
125
  # @param [RDF::URI] predicate
119
126
  # @param [RDF::Value] object
120
127
  # @return [void]
121
- # @raise [NotImplementedError] unless implemented in subclass
122
- # @abstract
123
128
  def write_triple(subject, predicate, object)
124
- @graph.insert(Statement.new(subject, predicate, object))
129
+ write_statement(Statement.new(subject, predicate, object))
130
+ end
131
+
132
+ ##
133
+ # Write out declarations
134
+ # @return [void] `self`
135
+ def write_prologue
136
+ case
137
+ when @options[:stream]
138
+ stream_prologue
139
+ else
140
+ end
125
141
  end
126
142
 
127
143
  ##
@@ -130,19 +146,23 @@ module RDF::Turtle
130
146
  # @return [void]
131
147
  # @see #write_triple
132
148
  def write_epilogue
133
- @max_depth = @options[:max_depth] || 3
134
- @base_uri = RDF::URI(@options[:base_uri])
149
+ case
150
+ when @options[:stream]
151
+ stream_epilogue
152
+ else
153
+ @max_depth = @options[:max_depth] || 3
135
154
 
136
- self.reset
155
+ self.reset
137
156
 
138
- debug("\nserialize") {"graph: #{@graph.size}"}
157
+ debug("\nserialize") {"graph: #{@graph.size}"}
139
158
 
140
- preprocess
141
- start_document
159
+ preprocess
160
+ start_document
142
161
 
143
- order_subjects.each do |subject|
144
- unless is_done?(subject)
145
- statement(subject)
162
+ order_subjects.each do |subject|
163
+ unless is_done?(subject)
164
+ statement(subject)
165
+ end
146
166
  end
147
167
  end
148
168
  end
@@ -300,8 +320,8 @@ module RDF::Turtle
300
320
 
301
321
  # Start with base_uri
302
322
  if base_uri && @subjects.keys.include?(base_uri)
303
- subjects << base_uri
304
- seen[base_uri] = true
323
+ subjects << RDF::URI(base_uri)
324
+ seen[RDF::URI(base_uri)] = true
305
325
  end
306
326
 
307
327
  # Add distinguished classes
@@ -328,11 +348,16 @@ module RDF::Turtle
328
348
  (@options[:prefixes] || {}).each_pair do |k, v|
329
349
  @uri_to_prefix[v.to_s] = k
330
350
  end
331
- @options[:prefixes] = {} # Will define actual used when matched
332
351
 
333
352
  prefix(nil, @options[:default_namespace]) if @options[:default_namespace]
334
353
 
335
- @graph.each {|statement| preprocess_statement(statement)}
354
+ case
355
+ when @options[:stream]
356
+ else
357
+ @options[:prefixes] = {} # Will define actual used when matched
358
+
359
+ @graph.each {|statement| preprocess_statement(statement)}
360
+ end
336
361
  end
337
362
 
338
363
  # Perform any statement preprocessing required. This is used to perform reference counts and determine required
metadata CHANGED
@@ -1,150 +1,184 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: rdf-turtle
3
- version: !ruby/object:Gem::Version
4
- version: 1.0.8
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.9
5
5
  platform: ruby
6
- authors:
6
+ authors:
7
7
  - Gregg Kellogg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
-
12
- date: 2013-06-18 00:00:00 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
11
+ date: 2013-07-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
15
14
  name: rdf
16
- prerelease: false
17
- requirement: &id001 !ruby/object:Gem::Requirement
18
- requirements:
19
- - - ">="
20
- - !ruby/object:Gem::Version
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
21
19
  version: 1.0.7
22
20
  type: :runtime
23
- version_requirements: *id001
24
- - !ruby/object:Gem::Dependency
25
- name: ebnf
26
21
  prerelease: false
27
- requirement: &id002 !ruby/object:Gem::Requirement
28
- requirements:
29
- - - ">="
30
- - !ruby/object:Gem::Version
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 1.0.7
27
+ - !ruby/object:Gem::Dependency
28
+ name: ebnf
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
31
33
  version: 0.3.0
32
34
  type: :runtime
33
- version_requirements: *id002
34
- - !ruby/object:Gem::Dependency
35
- name: open-uri-cached
36
35
  prerelease: false
37
- requirement: &id003 !ruby/object:Gem::Requirement
38
- requirements:
39
- - - ">="
40
- - !ruby/object:Gem::Version
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: 0.3.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: open-uri-cached
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
41
47
  version: 0.0.5
42
48
  type: :development
43
- version_requirements: *id003
44
- - !ruby/object:Gem::Dependency
45
- name: rspec
46
49
  prerelease: false
47
- requirement: &id004 !ruby/object:Gem::Requirement
48
- requirements:
49
- - - ">="
50
- - !ruby/object:Gem::Version
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 0.0.5
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
51
61
  version: 2.12.0
52
62
  type: :development
53
- version_requirements: *id004
54
- - !ruby/object:Gem::Dependency
55
- name: rdf-isomorphic
56
63
  prerelease: false
57
- requirement: &id005 !ruby/object:Gem::Requirement
58
- requirements:
59
- - &id006
60
- - ">="
61
- - !ruby/object:Gem::Version
62
- version: "0"
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: 2.12.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: rdf-isomorphic
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
63
76
  type: :development
64
- version_requirements: *id005
65
- - !ruby/object:Gem::Dependency
66
- name: json-ld
67
77
  prerelease: false
68
- requirement: &id007 !ruby/object:Gem::Requirement
69
- requirements:
70
- - *id006
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: json-ld
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
71
90
  type: :development
72
- version_requirements: *id007
73
- - !ruby/object:Gem::Dependency
74
- name: yard
75
91
  prerelease: false
76
- requirement: &id008 !ruby/object:Gem::Requirement
77
- requirements:
78
- - - ">="
79
- - !ruby/object:Gem::Version
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: yard
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
80
103
  version: 0.8.3
81
104
  type: :development
82
- version_requirements: *id008
83
- - !ruby/object:Gem::Dependency
84
- name: rdf-spec
85
105
  prerelease: false
86
- requirement: &id009 !ruby/object:Gem::Requirement
87
- requirements:
88
- - - ">="
89
- - !ruby/object:Gem::Version
90
- version: "1.0"
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: 0.8.3
111
+ - !ruby/object:Gem::Dependency
112
+ name: rdf-spec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '1.0'
91
118
  type: :development
92
- version_requirements: *id009
93
- - !ruby/object:Gem::Dependency
94
- name: rake
95
119
  prerelease: false
96
- requirement: &id010 !ruby/object:Gem::Requirement
97
- requirements:
98
- - *id006
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ! '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '1.0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rake
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
99
132
  type: :development
100
- version_requirements: *id010
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ! '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
101
139
  description: RDF::Turtle is an Turtle reader/writer for the RDF.rb library suite.
102
140
  email: public-rdf-ruby@w3.org
103
141
  executables: []
104
-
105
142
  extensions: []
106
-
107
143
  extra_rdoc_files: []
108
-
109
- files:
144
+ files:
110
145
  - AUTHORS
111
146
  - README.md
112
147
  - History
113
148
  - UNLICENSE
114
149
  - VERSION
115
- - lib/rdf/turtle.rb
116
150
  - lib/rdf/turtle/format.rb
117
151
  - lib/rdf/turtle/freebase_reader.rb
118
152
  - lib/rdf/turtle/meta.rb
119
153
  - lib/rdf/turtle/reader.rb
154
+ - lib/rdf/turtle/streaming_writer.rb
120
155
  - lib/rdf/turtle/terminals.rb
121
156
  - lib/rdf/turtle/version.rb
122
157
  - lib/rdf/turtle/writer.rb
158
+ - lib/rdf/turtle.rb
123
159
  homepage: http://ruby-rdf.github.com/rdf-turtle
124
- licenses:
160
+ licenses:
125
161
  - Public Domain
126
162
  metadata: {}
127
-
128
163
  post_install_message:
129
164
  rdoc_options: []
130
-
131
- require_paths:
165
+ require_paths:
132
166
  - lib
133
- required_ruby_version: !ruby/object:Gem::Requirement
134
- requirements:
135
- - - ">="
136
- - !ruby/object:Gem::Version
167
+ required_ruby_version: !ruby/object:Gem::Requirement
168
+ requirements:
169
+ - - ! '>='
170
+ - !ruby/object:Gem::Version
137
171
  version: 1.8.1
138
- required_rubygems_version: !ruby/object:Gem::Requirement
139
- requirements:
140
- - *id006
172
+ required_rubygems_version: !ruby/object:Gem::Requirement
173
+ requirements:
174
+ - - ! '>='
175
+ - !ruby/object:Gem::Version
176
+ version: '0'
141
177
  requirements: []
142
-
143
178
  rubyforge_project: rdf-turtle
144
- rubygems_version: 2.0.3
179
+ rubygems_version: 2.0.5
145
180
  signing_key:
146
181
  specification_version: 4
147
182
  summary: Turtle reader/writer for Ruby.
148
183
  test_files: []
149
-
150
184
  has_rdoc: false