rdf-n3 1.99.0 → 2.0.0.beta1

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
2
  SHA1:
3
- metadata.gz: b9b52d4f54d09368875b654dad895204b3fe645c
4
- data.tar.gz: ab49163f1b25a7deb4982273c7ef698504624d4f
3
+ metadata.gz: fe956e29cb0b37c4312d36cecd9bb0ec6f31804b
4
+ data.tar.gz: dd3873a8d7fb00e530beec9f2cdef6ac7784f13b
5
5
  SHA512:
6
- metadata.gz: 8308ad1b87c6905d0e6ab9551adc67f851c689d0a21713e22da310fddf66c241ca46752c0468de1778fe5a27235d8dc826c6172894db21a149155451c3842a7a
7
- data.tar.gz: bed77496be0b312dbaa8ac1a63a2647bfefbd4c0e542ff64fe3389a84eb15d31be45c4e8653626a6ce129a43f2129319809e4addd492216dd4825aabb139729f
6
+ metadata.gz: 46a8c8d72bebde3675a64b0b4f405e200c0fc5bba2f75d705766d44a6c9fcab24d9ef1d596266dba13715d1dba134359261f302e0d4b50c8ea4404a2f28bb3e6
7
+ data.tar.gz: 2d2c2fbad6f9bdf55fd82a753aef7eeaad0fd7ce15e99b381ea837b06258f968ab854eb6e7a12cf328f7f31bb5cb74e09cdb13e6a7e1b9b103da98ce09d1f3f3
data/README.md CHANGED
@@ -19,7 +19,7 @@ RDF::N3 parses [Notation-3][N3], [Turtle][Turtle] and [N-Triples][N-Triples] int
19
19
  Install with `gem install rdf-n3`
20
20
 
21
21
  ## Limitations
22
- * Full support of Unicode input requires Ruby version 1.9 or greater.
22
+ * Full support of Unicode input requires Ruby version 2.0 or greater.
23
23
  * Support for Variables in Formulae dependent on underlying repository. Existential variables are quantified to RDF::Node instances, Universals to RDF::Query::Variable, with the URI of the variable target used as the variable name.
24
24
  * No support for N3 Reification. If there were, it would be through a :reify option to the reader.
25
25
 
@@ -64,7 +64,7 @@ results in:
64
64
 
65
65
  h = RDF::Query::Variable.new(<#h>)
66
66
  g = RDF::Node.new()
67
- RDF::Statement.new(f, <#loves>, h)
67
+ RDF::Statement(f, <#loves>, h)
68
68
 
69
69
  ## Implementation Notes
70
70
  The parser is driven through a rules table contained in lib/rdf/n3/reader/meta.rb. This includes
@@ -84,7 +84,7 @@ http://www.w3.org/2000/10/swap/grammar/n3.n3 (along with bnf-rules.n3) using cwm
84
84
  * Create equivalent to `--think` to iterate on solutions.
85
85
 
86
86
  ## Dependencies
87
- * [RDF.rb](http://rubygems.org/gems/rdf) (>= 1.1)
87
+ * [RDF.rb](http://rubygems.org/gems/rdf) (>= 2.0)
88
88
 
89
89
  ## Documentation
90
90
  Full documentation available on [RubyDoc.info](http://rubydoc.info/github/ruby-rdf/rdf-n3/frames)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.99.0
1
+ 2.0.0.beta1
@@ -28,8 +28,5 @@ module RDF
28
28
  autoload :Reader, 'rdf/n3/reader'
29
29
  autoload :VERSION, 'rdf/n3/version'
30
30
  autoload :Writer, 'rdf/n3/writer'
31
-
32
- def self.debug?; @debug; end
33
- def self.debug=(value); @debug = value; end
34
31
  end
35
32
  end
@@ -22,21 +22,10 @@ module RDF::N3
22
22
 
23
23
  reader { RDF::N3::Reader }
24
24
  writer { RDF::N3::Writer }
25
- end
26
-
27
- # Alias for N3 format
28
- #
29
- # This allows the following:
30
- #
31
- # @example Obtaining an Notation3 format class
32
- # RDF::Format.for(:ttl) #=> RDF::N3::Notation3
33
- # RDF::Format.for(:ttl).reader #=> RDF::N3::Reader
34
- # RDF::Format.for(:ttl).writer #=> RDF::N3::Writer
35
- class Notation3 < RDF::Format
36
- content_type 'text/n3', extension: :n3
37
- content_encoding 'utf-8'
38
25
 
39
- reader { RDF::N3::Reader }
40
- writer { RDF::N3::Writer }
26
+ # Symbols which may be used to lookup this format
27
+ def self.symbols
28
+ [:n3, :notation3]
29
+ end
41
30
  end
42
31
  end
@@ -1,3 +1,4 @@
1
+ # coding: utf-8
1
2
  module RDF::N3
2
3
  ##
3
4
  # A Notation-3/Turtle parser in Ruby
@@ -16,6 +17,7 @@ module RDF::N3
16
17
  class Reader < RDF::Reader
17
18
  format Format
18
19
 
20
+ include RDF::Util::Logger
19
21
  include Meta
20
22
  include Parser
21
23
 
@@ -26,8 +28,6 @@ module RDF::N3
26
28
  #
27
29
  # @param [IO, File, String] input
28
30
  # the input stream to read
29
- # @option options [Array] :debug
30
- # Array to place debug messages
31
31
  # @option options [#to_s] :base_uri (nil)
32
32
  # the base URI to use when resolving relative URIs (not supported by
33
33
  # all readers)
@@ -65,12 +65,12 @@ module RDF::N3
65
65
  @variables = {} # variable definitions along with defining formula
66
66
 
67
67
  if options[:base_uri]
68
- add_debug("@uri") { base_uri.inspect}
68
+ log_debug("@uri") { base_uri.inspect}
69
69
  namespace(nil, uri("#{base_uri}#"))
70
70
  end
71
- add_debug("validate") {validate?.inspect}
72
- add_debug("canonicalize") {canonicalize?.inspect}
73
- add_debug("intern") {intern?.inspect}
71
+ log_debug("validate") {validate?.inspect}
72
+ log_debug("canonicalize") {canonicalize?.inspect}
73
+ log_debug("intern") {intern?.inspect}
74
74
 
75
75
  if block_given?
76
76
  case block.arity
@@ -96,6 +96,10 @@ module RDF::N3
96
96
  @callback = block
97
97
 
98
98
  parse(START.to_sym)
99
+
100
+ if validate? && log_statistics[:error]
101
+ raise RDF::ReaderError, "Errors found during processing"
102
+ end
99
103
  end
100
104
  enum_for(:each_triple)
101
105
  end
@@ -121,7 +125,7 @@ module RDF::N3
121
125
  # Start of production
122
126
  def onStart(prod)
123
127
  handler = "#{prod}Start".to_sym
124
- add_debug("#{handler}(#{respond_to?(handler, true)})", prod)
128
+ log_debug("#{handler}(#{respond_to?(handler, true)})", prod)
125
129
  @productions << prod
126
130
  send(handler, prod) if respond_to?(handler, true)
127
131
  end
@@ -130,7 +134,7 @@ module RDF::N3
130
134
  def onFinish
131
135
  prod = @productions.pop()
132
136
  handler = "#{prod}Finish".to_sym
133
- add_debug("#{handler}(#{respond_to?(handler, true)})") {"#{prod}: #{@prod_data.last.inspect}"}
137
+ log_debug("#{handler}(#{respond_to?(handler, true)})") {"#{prod}: #{@prod_data.last.inspect}"}
134
138
  send(handler) if respond_to?(handler, true)
135
139
  end
136
140
 
@@ -139,7 +143,7 @@ module RDF::N3
139
143
  unless @productions.empty?
140
144
  parentProd = @productions.last
141
145
  handler = "#{parentProd}Token".to_sym
142
- add_debug("#{handler}(#{respond_to?(handler, true)})") {"#{prod}, #{tok}: #{@prod_data.last.inspect}"}
146
+ log_debug("#{handler}(#{respond_to?(handler, true)})") {"#{prod}, #{tok}: #{@prod_data.last.inspect}"}
143
147
  send(handler, prod, tok) if respond_to?(handler, true)
144
148
  else
145
149
  error("Token has no parent production")
@@ -186,9 +190,9 @@ module RDF::N3
186
190
  # This means that <#foo> can be written :foo and using @keywords one can reduce that to foo.
187
191
 
188
192
  namespace(nil, uri.match(/[\/\#]$/) ? base_uri : process_uri("#{uri}#"))
189
- add_debug("declarationFinish[@base]") {"@base=#{base_uri}"}
193
+ log_debug("declarationFinish[@base]") {"@base=#{base_uri}"}
190
194
  when "@keywords"
191
- add_debug("declarationFinish[@keywords]") {@keywords.inspect}
195
+ log_debug("declarationFinish[@keywords]") {@keywords.inspect}
192
196
  # Keywords are handled in tokenizer and maintained in @keywords array
193
197
  if (@keywords & N3_KEYWORDS) != @keywords
194
198
  error("Undefined keywords used: #{(@keywords - N3_KEYWORDS).to_sentence}") if validate?
@@ -238,7 +242,7 @@ module RDF::N3
238
242
  # If we're in teh middle of a pathtail, append
239
243
  if @prod_data.last[:pathtail] && expression[:pathitem] && expression[:pathtail]
240
244
  path_list = [expression[:pathitem]] + expression[:pathtail]
241
- add_debug("expressionFinish(pathtail)") {"set pathtail to #{path_list.inspect}"}
245
+ log_debug("expressionFinish(pathtail)") {"set pathtail to #{path_list.inspect}"}
242
246
  @prod_data.last[:pathtail] = path_list
243
247
 
244
248
  dir_list = [expression[:direction]] if expression[:direction]
@@ -402,7 +406,7 @@ module RDF::N3
402
406
  properties.each do |p|
403
407
  predicate = p[:verb]
404
408
  next unless predicate
405
- add_debug("simpleStatementFinish(pred)") {predicate.to_s}
409
+ log_debug("simpleStatementFinish(pred)") {predicate.to_s}
406
410
  error(%(Illegal statment: "#{predicate}" missing object)) unless p.has_key?(:object)
407
411
  objects = Array(p[:object])
408
412
  objects.each do |object|
@@ -505,14 +509,14 @@ module RDF::N3
505
509
  ###################
506
510
 
507
511
  def process_anonnode(anonnode)
508
- add_debug("process_anonnode") {anonnode.inspect}
512
+ log_debug("process_anonnode") {anonnode.inspect}
509
513
 
510
514
  if anonnode[:propertylist]
511
515
  properties = anonnode[:propertylist]
512
516
  bnode = RDF::Node.new
513
517
  properties.each do |p|
514
518
  predicate = p[:verb]
515
- add_debug("process_anonnode(verb)") {predicate.inspect}
519
+ log_debug("process_anonnode(verb)") {predicate.inspect}
516
520
  objects = Array(p[:object])
517
521
  objects.each { |object| add_triple("anonnode", bnode, predicate, object) }
518
522
  end
@@ -535,7 +539,7 @@ module RDF::N3
535
539
  #
536
540
  # Create triple and return property used for next iteration
537
541
  def process_path(expression)
538
- add_debug("process_path") {expression.inspect}
542
+ log_debug("process_path") {expression.inspect}
539
543
 
540
544
  pathitem = expression[:pathitem]
541
545
  pathtail = expression[:pathtail]
@@ -579,17 +583,17 @@ module RDF::N3
579
583
  end
580
584
 
581
585
  uri = if prefix(prefix)
582
- add_debug('process_qname(ns)') {"#{prefix(prefix)}, #{name}"}
586
+ log_debug('process_qname(ns)') {"#{prefix(prefix)}, #{name}"}
583
587
  ns(prefix, name)
584
588
  elsif prefix == '_'
585
- add_debug('process_qname(bnode)', name)
589
+ log_debug('process_qname(bnode)', name)
586
590
  bnode(name)
587
591
  else
588
- add_debug('process_qname(default_ns)', name)
592
+ log_debug('process_qname(default_ns)', name)
589
593
  namespace(nil, uri("#{base_uri}#")) unless prefix(nil)
590
594
  ns(nil, name)
591
595
  end
592
- add_debug('process_qname') {uri.inspect}
596
+ log_debug('process_qname') {uri.inspect}
593
597
  uri
594
598
  end
595
599
 
@@ -619,18 +623,6 @@ module RDF::N3
619
623
  RDF::Query::Variable.new(label.to_s)
620
624
  end
621
625
 
622
- # Add debug event to debug array, if specified
623
- #
624
- # @param [any] node string for showing graph_name
625
- # @param [String] message
626
- # @yieldreturn [String] appended to message, to allow for lazy-evaulation of message
627
- def add_debug(node, message = "")
628
- return unless ::RDF::N3.debug? || @options[:debug]
629
- message = message + yield if block_given?
630
- puts "[#{@lineno},#{@pos}]#{' ' * @productions.length}#{node}: #{message}" if ::RDF::N3::debug?
631
- @options[:debug] << "[#{@lineno},#{@pos}]#{' ' * @productions.length}#{node}: #{message}" if @options[:debug].is_a?(Array)
632
- end
633
-
634
626
  # add a statement, object can be literal or URI or bnode
635
627
  #
636
628
  # @param [any] node string for showing graph_name
@@ -642,8 +634,8 @@ module RDF::N3
642
634
  def add_triple(node, subject, predicate, object)
643
635
  graph_name_opts = @formulae.last ? {graph_name: @formulae.last} : {}
644
636
 
645
- statement = RDF::Statement.new(subject, predicate, object, graph_name_opts)
646
- add_debug(node) {statement.to_s}
637
+ statement = RDF::Statement(subject, predicate, object, graph_name_opts)
638
+ log_debug(node) {statement.to_s}
647
639
  @callback.call(statement)
648
640
  end
649
641
 
@@ -652,7 +644,7 @@ module RDF::N3
652
644
  if uri == '#'
653
645
  uri = prefix(nil).to_s + '#'
654
646
  end
655
- add_debug("namespace") {"'#{prefix}' <#{uri}>"}
647
+ log_debug("namespace") {"'#{prefix}' <#{uri}>"}
656
648
  prefix(prefix, uri(uri))
657
649
  end
658
650
 
@@ -682,7 +674,7 @@ module RDF::N3
682
674
  def ns(prefix, suffix)
683
675
  base = prefix(prefix).to_s
684
676
  suffix = suffix.to_s.sub(/^\#/, "") if base.index("#")
685
- add_debug("ns") {"base: '#{base}', suffix: '#{suffix}'"}
677
+ log_debug("ns") {"base: '#{base}', suffix: '#{suffix}'"}
686
678
  uri(base + suffix.to_s)
687
679
  end
688
680
  end
@@ -1,3 +1,4 @@
1
+ # coding: utf-8
1
2
  # This file is automatically generated by script/build_meta
2
3
  # Branch and Regexp tables derived from http://www.w3.org/2000/10/swap/grammar/n3-selectors.n3
3
4
  module RDF::N3::Meta
@@ -1,3 +1,4 @@
1
+ # coding: utf-8
1
2
  # Simple parser to go through productions without attempting evaluation
2
3
  module RDF::N3
3
4
  module Parser
@@ -9,7 +10,7 @@ module RDF::N3
9
10
  NOT_NAME_CHARS = NOT_QNAME_CHARS + ":"
10
11
 
11
12
  def error(str)
12
- raise RDF::ReaderError, "\n#{@line}\n#{'-' * @pos}^\nError on line #{@lineno} at offset #{@pos}: #{str}"
13
+ log_error(str, lineno: @lineno, exception: RDF::ReaderError)
13
14
  end
14
15
 
15
16
  def parse(prod)
@@ -19,7 +20,7 @@ module RDF::N3
19
20
  if todo_stack.last[:terms].nil?
20
21
  todo_stack.last[:terms] = []
21
22
  tok = self.token
22
- #puts "parse tok: '#{tok}', prod #{todo_stack.last[:prod]}"
23
+ #log_debug("parse tok: '#{tok}'") {"prod #{todo_stack.last[:prod]}"}
23
24
 
24
25
  # Got an opened production
25
26
  onStart(abbr(todo_stack.last[:prod]))
@@ -34,15 +35,15 @@ module RDF::N3
34
35
  expected = prod_branch.values.uniq.map {|u| u.map {|v| abbr(v).inspect}.join(",")}
35
36
  error("Found '#{tok}' when parsing a #{abbr(cur_prod)}. expected #{expected.join(' | ')}")
36
37
  end
37
- #puts "sequence: #{sequence.inspect}"
38
+ #log_debug("sequence") {sequence.inspect}
38
39
  todo_stack.last[:terms] += sequence
39
40
  end
40
41
 
41
- #puts "parse: #{todo_stack.last.inspect}"
42
+ #log_debug("parse") {todo_stack.last.inspect}
42
43
  while !todo_stack.last[:terms].to_a.empty?
43
44
  term = todo_stack.last[:terms].shift
44
45
  if term.is_a?(String)
45
- puts "parse term(string): #{term}" if $verbose
46
+ log_debug("parse term(string)") {term.to_s}
46
47
  word = buffer[0, term.length]
47
48
  if word == term
48
49
  onToken(term, word)
@@ -59,28 +60,28 @@ module RDF::N3
59
60
  string = '"""'
60
61
  consume(3)
61
62
  next_line = buffer
62
- #puts "ml-str(start): #{next_line.dump}" if $verbose
63
+ #log_debug("ml-str(start)") {next_line.dump}
63
64
  until md = R_MLSTRING.match(next_line)
64
65
  begin
65
66
  string += next_line
66
67
  next_line = readline
67
- rescue EOFError => e
68
+ rescue EOFError
68
69
  error("EOF reached searching for end of multi-line comment")
69
70
  end
70
71
  end
71
72
  string += md[0].to_s
72
73
  consume(md[0].to_s.length)
73
74
  onToken('string', string)
74
- #puts "ml-str now #{buffer.dump}"
75
+ #log_debug("ml-str now") {buffer.dump}
75
76
  else
76
77
  md = regexp.match(buffer)
77
78
  error("Token(#{abbr(term)}) '#{buffer[0, 10]}...' should match #{regexp}") unless md
78
- puts "parse term(#{abbr(term)}:regexp): #{term}, #{regexp}.match('#{buffer[0, 10]}...') => '#{md.inspect}'" if $verbose
79
+ log_debug("parse") {"term(#{abbr(term)}:regexp): #{term}, #{regexp}.match('#{buffer[0, 10]}...') => '#{md.inspect.force_encoding(Encoding::UTF_8)}'"}
79
80
  onToken(abbr(term), md.to_s)
80
81
  consume(md[0].length)
81
82
  end
82
83
  else
83
- puts "parse term(push): #{term}" if $verbose
84
+ log_debug("parse term(push)") {term}
84
85
  todo_stack << {prod: term, terms: nil}
85
86
  pushed = true
86
87
  break
@@ -104,7 +105,7 @@ module RDF::N3
104
105
  unless @memo.has_key?(@pos)
105
106
  tok = self.get_token
106
107
  @memo[@pos] = tok
107
- puts "token: '#{tok}'('#{buffer[0, 10]}...')" if buffer && $verbose
108
+ log_debug("token") {"'#{tok}'('#{buffer[0, 10]}...')"} if buffer
108
109
  end
109
110
  @memo[@pos]
110
111
  end
@@ -158,7 +159,7 @@ module RDF::N3
158
159
  while buffer && md = R_WHITESPACE.match(buffer)
159
160
  return unless md[0].length > 0
160
161
  consume(md[0].length)
161
- #puts "ws: '#{md[0]}', pos=#{@pos}"
162
+ #log_debug("ws") {"'#{md[0]}', pos=#{@pos}"}
162
163
  end
163
164
  end
164
165
 
@@ -166,10 +167,10 @@ module RDF::N3
166
167
  @line = @input.readline
167
168
  @lineno += 1
168
169
  @line.force_encoding(Encoding::UTF_8)
169
- puts "readline[#{@lineno}]: #{@line.dump}" if $verbose
170
+ log_debug("readline[#{@lineno}]") {@line.dump}
170
171
  @pos = 0
171
172
  @line
172
- rescue EOFError => e
173
+ rescue EOFError
173
174
  @line, @pos = nil, 0
174
175
  end
175
176
 
@@ -183,7 +184,7 @@ module RDF::N3
183
184
  @memo = {}
184
185
  @pos += n
185
186
  readline while @line && @line.length <= @pos
186
- #puts "consume[#{n}]: '#{buffer}'" if $verbose
187
+ #log_debug("consume[#{n}]") {buffer}
187
188
  end
188
189
 
189
190
  def abbr(prodURI)
@@ -1,3 +1,4 @@
1
+ # coding: utf-8
1
2
  module RDF::N3
2
3
  ##
3
4
  # A Turtle serialiser in Ruby
@@ -50,13 +51,32 @@ module RDF::N3
50
51
  # @author [Gregg Kellogg](http://greggkellogg.net/)
51
52
  class Writer < RDF::Writer
52
53
  format RDF::N3::Format
54
+ include RDF::Util::Logger
53
55
  QNAME = Meta::REGEXPS[:"http://www.w3.org/2000/10/swap/grammar/n3#qname"]
54
56
 
55
57
  # @return [Graph] Graph of statements serialized
56
58
  attr_accessor :graph
57
59
  # @return [URI] Base URI used for relativizing URIs
58
60
  attr_accessor :base_uri
59
-
61
+
62
+ ##
63
+ # N3 Writer options
64
+ # @see http://www.rubydoc.info/github/ruby-rdf/rdf/RDF/Writer#options-class_method
65
+ def self.options
66
+ super + [
67
+ RDF::CLI::Option.new(
68
+ symbol: :max_depth,
69
+ datatype: Integer,
70
+ on: ["--max-depth"],
71
+ description: "Maximum depth for recursively defining resources, defaults to 3.") {|arg| arg.to_i},
72
+ RDF::CLI::Option.new(
73
+ symbol: :default_namespace,
74
+ datatype: RDF::URI,
75
+ on: ["--default-namespace URI", :REQUIRED],
76
+ description: "URI to use as default namespace, same as prefixes.") {|arg| RDF::URI(arg)},
77
+ ]
78
+ end
79
+
60
80
  ##
61
81
  # Initializes the Turtle writer instance.
62
82
  #
@@ -99,23 +119,6 @@ module RDF::N3
99
119
  end
100
120
  end
101
121
 
102
- ##
103
- # Write whole graph
104
- #
105
- # @param [Graph] graph
106
- # @return [void]
107
- def write_graph(graph)
108
- @graph = graph
109
- end
110
-
111
- ##
112
- # Addes a statement to be serialized
113
- # @param [RDF::Statement] statement
114
- # @return [void]
115
- def write_statement(statement)
116
- @graph.insert(statement)
117
- end
118
-
119
122
  ##
120
123
  # Addes a triple to be serialized
121
124
  # @param [RDF::Resource] subject
@@ -125,7 +128,7 @@ module RDF::N3
125
128
  # @raise [NotImplementedError] unless implemented in subclass
126
129
  # @abstract
127
130
  def write_triple(subject, predicate, object)
128
- @graph.insert(Statement.new(subject, predicate, object))
131
+ @graph.insert(RDF::Statement(subject, predicate, object))
129
132
  end
130
133
 
131
134
  ##
@@ -136,11 +139,10 @@ module RDF::N3
136
139
  def write_epilogue
137
140
  @max_depth = @options[:max_depth] || 3
138
141
  @base_uri = RDF::URI(@options[:base_uri])
139
- @debug = @options[:debug]
140
142
 
141
143
  self.reset
142
144
 
143
- add_debug {"\nserialize: graph: #{@graph.size}"}
145
+ log_debug {"\nserialize: graph: #{@graph.size}"}
144
146
 
145
147
  preprocess
146
148
  start_document
@@ -150,6 +152,8 @@ module RDF::N3
150
152
  statement(subject)
151
153
  end
152
154
  end
155
+
156
+ super
153
157
  end
154
158
 
155
159
  # Return a QName for the URI, or nil. Adds namespace of QName to defined prefixes
@@ -165,7 +169,7 @@ module RDF::N3
165
169
  return nil
166
170
  end
167
171
 
168
- add_debug {"get_qname(#{resource}), std?}"}
172
+ log_debug {"get_qname(#{resource}), std?}"}
169
173
  qname = case
170
174
  when @uri_to_qname.has_key?(uri)
171
175
  return @uri_to_qname[uri]
@@ -173,13 +177,13 @@ module RDF::N3
173
177
  # Use a defined prefix
174
178
  prefix = @uri_to_prefix[u]
175
179
  prefix(prefix, u) unless u.to_s.empty? # Define for output
176
- add_debug {"get_qname: add prefix #{prefix.inspect} => #{u}"}
180
+ log_debug {"get_qname: add prefix #{prefix.inspect} => #{u}"}
177
181
  uri.sub(u.to_s, "#{prefix}:")
178
182
  when @options[:standard_prefixes] && vocab = RDF::Vocabulary.each.to_a.detect {|v| uri.index(v.to_uri.to_s) == 0}
179
183
  prefix = vocab.__name__.to_s.split('::').last.downcase
180
184
  @uri_to_prefix[vocab.to_uri.to_s] = prefix
181
185
  prefix(prefix, vocab.to_uri) # Define for output
182
- add_debug {"get_qname: add standard prefix #{prefix.inspect} => #{vocab.to_uri}"}
186
+ log_debug {"get_qname: add standard prefix #{prefix.inspect} => #{vocab.to_uri}"}
183
187
  uri.sub(vocab.to_uri.to_s, "#{prefix}:")
184
188
  else
185
189
  nil
@@ -214,7 +218,7 @@ module RDF::N3
214
218
  prop_list << prop.to_s
215
219
  end
216
220
 
217
- add_debug {"sort_properties: #{prop_list.join(', ')}"}
221
+ log_debug {"sort_properties: #{prop_list.join(', ')}"}
218
222
  prop_list
219
223
  end
220
224
 
@@ -252,7 +256,7 @@ module RDF::N3
252
256
  # @return [String]
253
257
  def format_uri(uri, options = {})
254
258
  md = relativize(uri)
255
- add_debug {"relativize(#{uri.inspect}) => #{md.inspect}"} if md != uri.to_s
259
+ log_debug {"relativize(#{uri.inspect}) => #{md.inspect}"} if md != uri.to_s
256
260
  md != uri.to_s ? "<#{md}>" : (get_qname(uri) || "<#{uri}>")
257
261
  end
258
262
 
@@ -273,7 +277,7 @@ module RDF::N3
273
277
 
274
278
  @output.write("#{indent}@base <#{base_uri}> .\n") unless base_uri.to_s.empty?
275
279
 
276
- add_debug {"start_document: #{prefixes.inspect}"}
280
+ log_debug {"start_document: #{prefixes.inspect}"}
277
281
  prefixes.keys.sort_by(&:to_s).each do |prefix|
278
282
  @output.write("#{indent}@prefix #{prefix}: <#{prefixes[prefix]}> .\n")
279
283
  end
@@ -309,17 +313,17 @@ module RDF::N3
309
313
  subjects << base_uri
310
314
  seen[base_uri] = true
311
315
  end
312
- add_debug {"subjects1: #{subjects.inspect}"}
316
+ log_debug {"subjects1: #{subjects.inspect}"}
313
317
 
314
318
  # Add distinguished classes
315
319
  top_classes.each do |class_uri|
316
320
  graph.query(predicate: RDF.type, object: class_uri).map {|st| st.subject}.sort.uniq.each do |subject|
317
- add_debug {"order_subjects: #{subject.inspect}"}
321
+ log_debug {"order_subjects: #{subject.inspect}"}
318
322
  subjects << subject
319
323
  seen[subject] = true
320
324
  end
321
325
  end
322
- add_debug {"subjects2: #{subjects.inspect}"}
326
+ log_debug {"subjects2: #{subjects.inspect}"}
323
327
 
324
328
  # Sort subjects by resources over bnodes, ref_counts and the subject URI itself
325
329
  recursable = @subjects.keys.
@@ -327,9 +331,9 @@ module RDF::N3
327
331
  map {|r| [r.node? ? 1 : 0, ref_count(r), r]}.
328
332
  sort
329
333
 
330
- add_debug {"subjects3: #{subjects.inspect}"}
334
+ log_debug {"subjects3: #{subjects.inspect}"}
331
335
  subjects += recursable.map{|r| r.last}
332
- add_debug {"subjects4: #{subjects.inspect}"}
336
+ log_debug {"subjects4: #{subjects.inspect}"}
333
337
  subjects
334
338
  end
335
339
 
@@ -350,7 +354,7 @@ module RDF::N3
350
354
  # prefixes.
351
355
  # @param [Statement] statement
352
356
  def preprocess_statement(statement)
353
- #add_debug {"preprocess: #{statement.inspect}"}
357
+ #log_debug {"preprocess: #{statement.inspect}"}
354
358
  references = ref_count(statement.object) + 1
355
359
  @references[statement.object] = references
356
360
  @subjects[statement.subject] = true
@@ -405,30 +409,19 @@ module RDF::N3
405
409
 
406
410
  private
407
411
 
408
- # Add debug event to debug array, if specified
409
- #
410
- # @param [String] message
411
- # @yieldreturn [String] appended to message, to allow for lazy-evaulation of message
412
- def add_debug(message = "")
413
- return unless ::RDF::N3.debug? || @debug
414
- message = message + yield if block_given?
415
- STDERR.puts message if ::RDF::N3::debug?
416
- @debug << message if @debug.is_a?(Array)
417
- end
418
-
419
412
  # Checks if l is a valid RDF list, i.e. no nodes have other properties.
420
413
  def is_valid_list(l)
421
- #add_debug {"is_valid_list: #{l.inspect}"}
422
- return (l.node? && RDF::List.new(l, @graph).valid?) || l == RDF.nil
414
+ #log_debug {"is_valid_list: #{l.inspect}"}
415
+ return (l.node? && RDF::List.new(subject: l, graph: @graph).valid?) || l == RDF.nil
423
416
  end
424
417
 
425
418
  def do_list(l)
426
- list = RDF::List.new(l, @graph)
427
- add_debug {"do_list: #{list.inspect}"}
419
+ list = RDF::List.new(subject: l, graph: @graph)
420
+ log_debug {"do_list: #{list.inspect}"}
428
421
  position = :subject
429
422
  list.each_statement do |st|
430
423
  next unless st.predicate == RDF.first
431
- add_debug {" list this: #{st.subject} first: #{st.object}[#{position}]"}
424
+ log_debug {" list this: #{st.subject} first: #{st.object}[#{position}]"}
432
425
  path(st.object, position)
433
426
  subject_done(st.subject)
434
427
  position = :object
@@ -437,7 +430,7 @@ module RDF::N3
437
430
 
438
431
  def p_list(node, position)
439
432
  return false if !is_valid_list(node)
440
- #add_debug {"p_list: #{node.inspect}, #{position}"}
433
+ #log_debug {"p_list: #{node.inspect}, #{position}"}
441
434
 
442
435
  @output.write(position == :subject ? "(" : " (")
443
436
  @depth += 2
@@ -455,7 +448,7 @@ module RDF::N3
455
448
  def p_squared(node, position)
456
449
  return false unless p_squared?(node, position)
457
450
 
458
- #add_debug {"p_squared: #{node.inspect}, #{position}"}
451
+ #log_debug {"p_squared: #{node.inspect}, #{position}"}
459
452
  subject_done(node)
460
453
  @output.write(position == :subject ? '[' : ' [')
461
454
  @depth += 2
@@ -467,13 +460,13 @@ module RDF::N3
467
460
  end
468
461
 
469
462
  def p_default(node, position)
470
- #add_debug {"p_default: #{node.inspect}, #{position}"}
463
+ #log_debug {"p_default: #{node.inspect}, #{position}"}
471
464
  l = (position == :subject ? "" : " ") + format_term(node, options)
472
465
  @output.write(l)
473
466
  end
474
467
 
475
468
  def path(node, position)
476
- add_debug do
469
+ log_debug do
477
470
  "path: #{node.inspect}, " +
478
471
  "pos: #{position}, " +
479
472
  "[]: #{is_valid_list(node)}, " +
@@ -484,7 +477,7 @@ module RDF::N3
484
477
  end
485
478
 
486
479
  def verb(node)
487
- add_debug {"verb: #{node.inspect}"}
480
+ log_debug {"verb: #{node.inspect}"}
488
481
  if node == RDF.type
489
482
  @output.write(" a")
490
483
  else
@@ -493,7 +486,7 @@ module RDF::N3
493
486
  end
494
487
 
495
488
  def object_list(objects)
496
- add_debug {"object_list: #{objects.inspect}"}
489
+ log_debug {"object_list: #{objects.inspect}"}
497
490
  return if objects.empty?
498
491
 
499
492
  objects.each_with_index do |obj, i|
@@ -510,7 +503,7 @@ module RDF::N3
510
503
  end
511
504
 
512
505
  prop_list = sort_properties(properties) - [RDF.first.to_s, RDF.rest.to_s]
513
- add_debug {"predicate_list: #{prop_list.inspect}"}
506
+ log_debug {"predicate_list: #{prop_list.inspect}"}
514
507
  return if prop_list.empty?
515
508
 
516
509
  prop_list.each_with_index do |prop, i|
@@ -519,7 +512,7 @@ module RDF::N3
519
512
  verb(prop[0, 2] == "_:" ? RDF::Node.intern(prop.split(':').last) : RDF::URI.intern(prop))
520
513
  object_list(properties[prop])
521
514
  rescue Addressable::URI::InvalidURIError => e
522
- add_debug {"Predicate #{prop.inspect} is an invalid URI: #{e.message}"}
515
+ log_debug {"Predicate #{prop.inspect} is an invalid URI: #{e.message}"}
523
516
  end
524
517
  end
525
518
  end
@@ -531,7 +524,7 @@ module RDF::N3
531
524
  def s_squared(subject)
532
525
  return false unless s_squared?(subject)
533
526
 
534
- add_debug {"s_squared: #{subject.inspect}"}
527
+ log_debug {"s_squared: #{subject.inspect}"}
535
528
  @output.write("\n#{indent} [")
536
529
  @depth += 1
537
530
  predicate_list(subject)
@@ -549,7 +542,7 @@ module RDF::N3
549
542
  end
550
543
 
551
544
  def statement(subject)
552
- add_debug {"statement: #{subject.inspect}, s2?: #{s_squared?(subject)}"}
545
+ log_debug {"statement: #{subject.inspect}, s2?: #{s_squared?(subject)}"}
553
546
  subject_done(subject)
554
547
  s_squared(subject) || s_default(subject)
555
548
  @output.write("\n")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdf-n3
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.99.0
4
+ version: 2.0.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregg
@@ -9,22 +9,28 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-10-14 00:00:00.000000000 Z
12
+ date: 2016-02-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rdf
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - "~>"
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: 2.0.0.beta
21
+ - - "<"
19
22
  - !ruby/object:Gem::Version
20
- version: '1.99'
23
+ version: '3'
21
24
  type: :runtime
22
25
  prerelease: false
23
26
  version_requirements: !ruby/object:Gem::Requirement
24
27
  requirements:
25
- - - "~>"
28
+ - - ">="
26
29
  - !ruby/object:Gem::Version
27
- version: '1.99'
30
+ version: 2.0.0.beta
31
+ - - "<"
32
+ - !ruby/object:Gem::Version
33
+ version: '3'
28
34
  - !ruby/object:Gem::Dependency
29
35
  name: open-uri-cached
30
36
  requirement: !ruby/object:Gem::Requirement
@@ -49,86 +55,90 @@ dependencies:
49
55
  name: json-ld
50
56
  requirement: !ruby/object:Gem::Requirement
51
57
  requirements:
52
- - - "~>"
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 2.0.0.beta
61
+ - - "<"
53
62
  - !ruby/object:Gem::Version
54
- version: '1.99'
63
+ version: '3'
55
64
  type: :development
56
65
  prerelease: false
57
66
  version_requirements: !ruby/object:Gem::Requirement
58
67
  requirements:
59
- - - "~>"
68
+ - - ">="
60
69
  - !ruby/object:Gem::Version
61
- version: '1.99'
70
+ version: 2.0.0.beta
71
+ - - "<"
72
+ - !ruby/object:Gem::Version
73
+ version: '3'
62
74
  - !ruby/object:Gem::Dependency
63
75
  name: rspec
64
76
  requirement: !ruby/object:Gem::Requirement
65
77
  requirements:
66
78
  - - "~>"
67
79
  - !ruby/object:Gem::Version
68
- version: '3.2'
80
+ version: '3.4'
69
81
  type: :development
70
82
  prerelease: false
71
83
  version_requirements: !ruby/object:Gem::Requirement
72
84
  requirements:
73
85
  - - "~>"
74
86
  - !ruby/object:Gem::Version
75
- version: '3.2'
87
+ version: '3.4'
76
88
  - !ruby/object:Gem::Dependency
77
89
  name: rspec-its
78
90
  requirement: !ruby/object:Gem::Requirement
79
91
  requirements:
80
92
  - - "~>"
81
93
  - !ruby/object:Gem::Version
82
- version: '1.0'
94
+ version: '1.2'
83
95
  type: :development
84
96
  prerelease: false
85
97
  version_requirements: !ruby/object:Gem::Requirement
86
98
  requirements:
87
99
  - - "~>"
88
100
  - !ruby/object:Gem::Version
89
- version: '1.0'
101
+ version: '1.2'
90
102
  - !ruby/object:Gem::Dependency
91
103
  name: rdf-spec
92
104
  requirement: !ruby/object:Gem::Requirement
93
105
  requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: '1.99'
97
- type: :development
98
- prerelease: false
99
- version_requirements: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - "~>"
106
+ - - ">="
102
107
  - !ruby/object:Gem::Version
103
- version: '1.99'
104
- - !ruby/object:Gem::Dependency
105
- name: rdf-rdfxml
106
- requirement: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - "~>"
108
+ version: 2.0.0.beta
109
+ - - "<"
109
110
  - !ruby/object:Gem::Version
110
- version: '1.1'
111
+ version: '3'
111
112
  type: :development
112
113
  prerelease: false
113
114
  version_requirements: !ruby/object:Gem::Requirement
114
115
  requirements:
115
- - - "~>"
116
+ - - ">="
116
117
  - !ruby/object:Gem::Version
117
- version: '1.1'
118
+ version: 2.0.0.beta
119
+ - - "<"
120
+ - !ruby/object:Gem::Version
121
+ version: '3'
118
122
  - !ruby/object:Gem::Dependency
119
123
  name: rdf-isomorphic
120
124
  requirement: !ruby/object:Gem::Requirement
121
125
  requirements:
122
- - - "~>"
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: 2.0.0.beta
129
+ - - "<"
123
130
  - !ruby/object:Gem::Version
124
- version: '1.1'
131
+ version: '3'
125
132
  type: :development
126
133
  prerelease: false
127
134
  version_requirements: !ruby/object:Gem::Requirement
128
135
  requirements:
129
- - - "~>"
136
+ - - ">="
130
137
  - !ruby/object:Gem::Version
131
- version: '1.1'
138
+ version: 2.0.0.beta
139
+ - - "<"
140
+ - !ruby/object:Gem::Version
141
+ version: '3'
132
142
  - !ruby/object:Gem::Dependency
133
143
  name: yard
134
144
  requirement: !ruby/object:Gem::Requirement
@@ -165,7 +175,7 @@ files:
165
175
  - lib/rdf/n3/writer.rb
166
176
  homepage: http://ruby-rdf.github.com/rdf-n3
167
177
  licenses:
168
- - Public Domain
178
+ - Unlicense
169
179
  metadata: {}
170
180
  post_install_message:
171
181
  rdoc_options: []
@@ -175,15 +185,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
175
185
  requirements:
176
186
  - - ">="
177
187
  - !ruby/object:Gem::Version
178
- version: 1.9.3
188
+ version: 2.0.0
179
189
  required_rubygems_version: !ruby/object:Gem::Requirement
180
190
  requirements:
181
- - - ">="
191
+ - - ">"
182
192
  - !ruby/object:Gem::Version
183
- version: '0'
193
+ version: 1.3.1
184
194
  requirements: []
185
195
  rubyforge_project: rdf-n3
186
- rubygems_version: 2.4.5.1
196
+ rubygems_version: 2.5.1
187
197
  signing_key:
188
198
  specification_version: 4
189
199
  summary: Notation3 reader/writer for RDF.rb.