rdf_context 0.5.7 → 0.5.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. data/History.rdoc +15 -1
  2. data/README.rdoc +2 -0
  3. data/Rakefile +2 -4
  4. data/VERSION +1 -1
  5. data/bin/rdf_context +5 -54
  6. data/lib/rdf_context.rb +5 -0
  7. data/lib/rdf_context/graph.rb +68 -49
  8. data/lib/rdf_context/n3parser.rb +2 -2
  9. data/lib/rdf_context/namespace.rb +1 -1
  10. data/lib/rdf_context/nokogiri_hacks.rb +7 -0
  11. data/lib/rdf_context/parser.rb +57 -13
  12. data/lib/rdf_context/rdfaparser.rb +200 -130
  13. data/lib/rdf_context/rdfxmlparser.rb +8 -8
  14. data/lib/rdf_context/serializer/recursive_serializer.rb +1 -1
  15. data/lib/rdf_context/serializer/turtle_serializer.rb +15 -15
  16. data/lib/rdf_context/serializer/xml_serializer.rb +8 -8
  17. data/lib/rdf_context/store/memory_store.rb +14 -14
  18. data/lib/rdf_context/store/sqlite3_store.rb +4 -4
  19. data/lib/rdf_context/uriref.rb +11 -4
  20. data/script/console +1 -3
  21. data/script/tc +44 -0
  22. data/spec/.gitignore +1 -0
  23. data/spec/aggregate_graph_spec.rb +1 -0
  24. data/spec/bnode_spec.rb +2 -1
  25. data/spec/conjunctive_graph_spec.rb +1 -0
  26. data/spec/cwm_spec.rb +1 -0
  27. data/spec/duration_spec.rb +1 -0
  28. data/spec/graph_spec.rb +27 -0
  29. data/spec/list_store_spec.rb +1 -0
  30. data/spec/literal_spec.rb +1 -0
  31. data/spec/matchers.rb +1 -1
  32. data/spec/memory_store_spec.rb +1 -0
  33. data/spec/n3parser_spec.rb +1 -0
  34. data/spec/namespaces_spec.rb +1 -0
  35. data/spec/parser_spec.rb +1 -0
  36. data/spec/rdf_helper.rb +4 -4
  37. data/spec/rdfa_helper.rb +24 -0
  38. data/spec/rdfa_parser_spec.rb +6 -36
  39. data/spec/rdfcore/.gitignore +1 -0
  40. data/spec/rdfxml_spec.rb +1 -0
  41. data/spec/sqlite3_store_spec.rb +1 -0
  42. data/spec/string_hacks_spec.rb +2 -0
  43. data/spec/swap_test/.gitignore +1 -0
  44. data/spec/triple_spec.rb +1 -0
  45. data/spec/turtle/.gitignore +1 -0
  46. data/spec/turtle_serializer_spec.rb +3 -2
  47. data/spec/turtle_spec.rb +1 -0
  48. data/spec/uriref_spec.rb +13 -12
  49. data/spec/xml_serializer_spec.rb +7 -6
  50. metadata +26 -61
  51. data/spec/html4-manifest.yml +0 -4937
  52. data/spec/html5-manifest.yml +0 -4937
  53. data/spec/rdfcore/Manifest.yml +0 -6242
  54. data/spec/swap_test/n3parser.yml +0 -773
  55. data/spec/swap_test/regression.yml +0 -902
  56. data/spec/turtle/manifest-bad.yml +0 -807
  57. data/spec/turtle/manifest.yml +0 -807
  58. data/spec/xhtml-manifest.yml +0 -3901
  59. data/spec/xhtml11-manifest.yml +0 -4405
@@ -83,7 +83,7 @@ module RdfContext
83
83
  def extract_from_element(element)
84
84
  b = element.attribute_with_ns("base", XML_NS.uri.to_s)
85
85
  lang = element.attribute_with_ns("lang", XML_NS.uri.to_s)
86
- self.base = URIRef.new(b.to_s.rdf_unescape, self.base, :normalize => false) if b
86
+ self.base = URIRef.intern(b.to_s.rdf_unescape, self.base, :normalize => false) if b
87
87
  self.language = lang if lang
88
88
  self.uri_mappings.merge!(extract_mappings(element))
89
89
  end
@@ -98,7 +98,7 @@ module RdfContext
98
98
  element.namespaces.each do |attr_name,attr_value|
99
99
  abbr, suffix = attr_name.to_s.split(":")
100
100
  if abbr == "xmlns"
101
- attr_value = URIRef.new(attr_value.rdf_unescape, self.base, :normalize => false) if attr_value.match(/^\#/)
101
+ attr_value = URIRef.intern(attr_value.rdf_unescape, self.base, :normalize => false) if attr_value.match(/^\#/)
102
102
  mappings[suffix] = Namespace.new(attr_value, suffix)
103
103
  @graph.bind(mappings[suffix])
104
104
  end
@@ -113,7 +113,7 @@ module RdfContext
113
113
  @li_counter += 1
114
114
  predicate = Addressable::URI.parse(predicate.to_s)
115
115
  predicate.fragment = "_#{@li_counter}"
116
- predicate = URIRef.new(predicate, :normalize => false)
116
+ predicate = URIRef.intern(predicate, :normalize => false)
117
117
  end
118
118
 
119
119
  # Set XML base. Ignore any fragment
@@ -215,7 +215,7 @@ module RdfContext
215
215
  # If there is an attribute a in propertyAttr with a.URI == rdf:type
216
216
  # then u:=uri(identifier:=resolve(a.string-value))
217
217
  # and the following triple is added to the graph:
218
- u = URIRef.new(attr.value.rdf_unescape, ec.base, :normalize => false)
218
+ u = URIRef.intern(attr.value.rdf_unescape, ec.base, :normalize => false)
219
219
  add_triple(attr, subject, RDF_TYPE, u)
220
220
  elsif is_propertyAttr?(attr)
221
221
  # Attributes not RDF_TYPE
@@ -404,7 +404,7 @@ module RdfContext
404
404
  reify(id, child, subject, predicate, literal, child_ec) if id
405
405
  else
406
406
  if resourceAttr
407
- resource = URIRef.new(resourceAttr.rdf_unescape, ec.base, :normalize => false)
407
+ resource = URIRef.intern(resourceAttr.rdf_unescape, ec.base, :normalize => false)
408
408
  elsif nodeID
409
409
  resource = BNode.new(nodeID, @named_bnodes)
410
410
  else
@@ -442,7 +442,7 @@ module RdfContext
442
442
  # Reify subject, predicate, and object given the EvaluationContext (ec) and current XMl element (el)
443
443
  def reify(id, el, subject, predicate, object, ec)
444
444
  add_debug(el, "reify, id: #{id}")
445
- rsubject = URIRef.new("#" + id, ec.base, :normalize => false)
445
+ rsubject = URIRef.intern("#" + id, ec.base, :normalize => false)
446
446
  add_triple(el, rsubject, RDF_NS.subject, subject)
447
447
  add_triple(el, rsubject, RDF_NS.predicate, predicate)
448
448
  add_triple(el, rsubject, RDF_NS.object, object)
@@ -478,7 +478,7 @@ module RdfContext
478
478
  when about
479
479
  about = about.value.rdf_unescape
480
480
  add_debug(el, "parse_subject, about: '#{about}'")
481
- URIRef.new(about, ec.base, :normalize => false)
481
+ URIRef.intern(about, ec.base, :normalize => false)
482
482
  else
483
483
  add_debug(el, "parse_subject, BNode")
484
484
  BNode.new
@@ -490,7 +490,7 @@ module RdfContext
490
490
  if NC_REGEXP.match(id)
491
491
  # ID may only be specified once for the same URI
492
492
  if base
493
- uri = URIRef.new("##{id}", base, :normalize => false)
493
+ uri = URIRef.intern("##{id}", base, :normalize => false)
494
494
  if @id_mapping[id] && @id_mapping[id] == uri
495
495
  warn = "ID addtribute '#{id}' may only be defined once for the same URI"
496
496
  add_debug(el, warn)
@@ -123,7 +123,7 @@ module RdfContext
123
123
  prop_list << prop.to_s
124
124
  end
125
125
 
126
- puts "sort_properties: #{prop_list.to_sentence}" if $DEBUG
126
+ puts "sort_properties: #{prop_list.to_sentence}" if ::RdfContext::debug?
127
127
  prop_list
128
128
  end
129
129
 
@@ -13,7 +13,7 @@ module RdfContext
13
13
  # @option options [URIRef, String] :base (nil) Base URI of graph, used to shorting URI references
14
14
  # @return [void]
15
15
  def serialize(stream, options = {})
16
- puts "\nserialize: #{@graph.inspect}" if $DEBUG
16
+ puts "\nserialize: #{@graph.inspect}" if ::RdfContext::debug?
17
17
  reset
18
18
  @stream = stream
19
19
  @base = options[:base]
@@ -84,23 +84,23 @@ module RdfContext
84
84
  # Checks if l is a valid RDF list, i.e. no nodes have other properties.
85
85
  def is_valid_list(l)
86
86
  props = @graph.properties(l)
87
- #puts "is_valid_list: #{props.inspect}" if $DEBUG
87
+ #puts "is_valid_list: #{props.inspect}" if ::RdfContext::debug?
88
88
  return false unless props.has_key?(RDF_NS.first.to_s) || l == RDF_NS.nil
89
89
  while l && l != RDF_NS.nil do
90
- #puts "is_valid_list(length): #{props.length}" if $DEBUG
90
+ #puts "is_valid_list(length): #{props.length}" if ::RdfContext::debug?
91
91
  return false unless props.has_key?(RDF_NS.first.to_s) && props.has_key?(RDF_NS.rest.to_s)
92
92
  n = props[RDF_NS.rest.to_s]
93
- #puts "is_valid_list(n): #{n.inspect}" if $DEBUG
93
+ #puts "is_valid_list(n): #{n.inspect}" if ::RdfContext::debug?
94
94
  return false unless n.is_a?(Array) && n.length == 1
95
95
  l = n.first
96
96
  props = @graph.properties(l)
97
97
  end
98
- #puts "is_valid_list: valid" if $DEBUG
98
+ #puts "is_valid_list: valid" if ::RdfContext::debug?
99
99
  true
100
100
  end
101
101
 
102
102
  def do_list(l)
103
- puts "do_list: #{l.inspect}" if $DEBUG
103
+ puts "do_list: #{l.inspect}" if ::RdfContext::debug?
104
104
  position = SUBJECT
105
105
  while l do
106
106
  p = @graph.properties(l)
@@ -116,7 +116,7 @@ module RdfContext
116
116
 
117
117
  def p_list(node, position)
118
118
  return false if !is_valid_list(node)
119
- #puts "p_list: #{node.inspect}, #{position}" if $DEBUG
119
+ #puts "p_list: #{node.inspect}, #{position}" if ::RdfContext::debug?
120
120
 
121
121
  write(position == SUBJECT ? "(" : " (")
122
122
  @depth += 2
@@ -134,7 +134,7 @@ module RdfContext
134
134
  def p_squared(node, position)
135
135
  return false unless p_squared?(node, position)
136
136
 
137
- #puts "p_squared: #{node.inspect}, #{position}" if $DEBUG
137
+ #puts "p_squared: #{node.inspect}, #{position}" if ::RdfContext::debug?
138
138
  subject_done(node)
139
139
  write(position == SUBJECT ? '[' : ' [')
140
140
  @depth += 2
@@ -146,18 +146,18 @@ module RdfContext
146
146
  end
147
147
 
148
148
  def p_default(node, position)
149
- #puts "p_default: #{node.inspect}, #{position}" if $DEBUG
149
+ #puts "p_default: #{node.inspect}, #{position}" if ::RdfContext::debug?
150
150
  l = (position == SUBJECT ? "" : " ") + label(node)
151
151
  write(l)
152
152
  end
153
153
 
154
154
  def path(node, position)
155
- puts "path: #{node.inspect}, pos: #{position}, []: #{is_valid_list(node)}, p2?: #{p_squared?(node, position)}, rc: #{ref_count(node)}" if $DEBUG
155
+ puts "path: #{node.inspect}, pos: #{position}, []: #{is_valid_list(node)}, p2?: #{p_squared?(node, position)}, rc: #{ref_count(node)}" if ::RdfContext::debug?
156
156
  raise RdfException, "Cannot serialize node '#{node}'" unless p_list(node, position) || p_squared(node, position) || p_default(node, position)
157
157
  end
158
158
 
159
159
  def verb(node)
160
- puts "verb: #{node.inspect}" if $DEBUG
160
+ puts "verb: #{node.inspect}" if ::RdfContext::debug?
161
161
  if node == RDF_TYPE
162
162
  write(" a")
163
163
  else
@@ -166,11 +166,11 @@ module RdfContext
166
166
  end
167
167
 
168
168
  def object_list(objects)
169
- puts "object_list: #{objects.inspect}" if $DEBUG
169
+ puts "object_list: #{objects.inspect}" if ::RdfContext::debug?
170
170
  return if objects.empty?
171
171
 
172
172
  objects.each_with_index do |obj, i|
173
- write(",\n#{indent(2)}") if i > 0
173
+ write(",\n#{indent(4)}") if i > 0
174
174
  path(obj, OBJECT)
175
175
  end
176
176
  end
@@ -178,7 +178,7 @@ module RdfContext
178
178
  def predicate_list(subject)
179
179
  properties = @graph.properties(subject)
180
180
  prop_list = sort_properties(properties) - [RDF_NS.first.to_s, RDF_NS.rest.to_s]
181
- puts "predicate_list: #{prop_list.inspect}" if $DEBUG
181
+ puts "predicate_list: #{prop_list.inspect}" if ::RdfContext::debug?
182
182
  return if prop_list.empty?
183
183
 
184
184
  prop_list.each_with_index do |prop, i|
@@ -212,7 +212,7 @@ module RdfContext
212
212
  end
213
213
 
214
214
  def statement(subject)
215
- puts "statement: #{subject.inspect}, s2?: #{s_squared(subject)}" if $DEBUG
215
+ puts "statement: #{subject.inspect}, s2?: #{s_squared(subject)}" if ::RdfContext::debug?
216
216
  subject_done(subject)
217
217
  s_squared(subject) || s_default(subject)
218
218
  end
@@ -34,7 +34,7 @@ module RdfContext
34
34
 
35
35
  doc = Nokogiri::XML::Document.new
36
36
 
37
- puts "\nserialize: graph namespaces: #{@graph.nsbinding.inspect}" if $DEBUG
37
+ puts "\nserialize: graph namespaces: #{@graph.nsbinding.inspect}" if ::RdfContext::debug?
38
38
 
39
39
  preprocess
40
40
 
@@ -67,7 +67,7 @@ module RdfContext
67
67
  # Add bindings for predicates not already having bindings
68
68
  tmp_ns = "ns0"
69
69
  required_namespaces.keys.each do |uri|
70
- puts "create namespace definition for #{uri}" if $DEBUG
70
+ puts "create namespace definition for #{uri}" if ::RdfContext::debug?
71
71
  add_namespace(Namespace.new(uri, tmp_ns))
72
72
  tmp_ns = tmp_ns.succ
73
73
  end
@@ -100,7 +100,7 @@ module RdfContext
100
100
  subject_done(subject)
101
101
  properties = @graph.properties(subject)
102
102
  prop_list = sort_properties(properties)
103
- puts "subject: #{subject.to_n3}, props: #{properties.inspect}" if $DEBUG
103
+ puts "subject: #{subject.to_n3}, props: #{properties.inspect}" if ::RdfContext::debug?
104
104
 
105
105
  rdf_type, *rest = properties.fetch(RDF_TYPE.to_s, [])
106
106
  if rdf_type.is_a?(URIRef)
@@ -133,7 +133,7 @@ module RdfContext
133
133
  end
134
134
  end
135
135
  elsif @force_RDF_about.include?(subject)
136
- puts "subject: #{subject.to_n3}, force about" if $DEBUG
136
+ puts "subject: #{subject.to_n3}, force about" if ::RdfContext::debug?
137
137
  node = Nokogiri::XML::Element.new("rdf:Description", parent_node.document)
138
138
  node["rdf:about"] = relativize(subject)
139
139
  @force_RDF_about.delete(subject)
@@ -177,7 +177,7 @@ module RdfContext
177
177
  end
178
178
  end
179
179
 
180
- puts "predicate: #{qname}, as_attr: #{as_attr}, object: #{object.inspect}, done: #{is_done?(object)}, sub: #{@subjects.include?(object)}" if $DEBUG
180
+ puts "predicate: #{qname}, as_attr: #{as_attr}, object: #{object.inspect}, done: #{is_done?(object)}, sub: #{@subjects.include?(object)}" if ::RdfContext::debug?
181
181
  qname = "rdf:li" if qname.match(/rdf:_\d+/)
182
182
  pred_node = Nokogiri::XML::Element.new(qname, node.document)
183
183
 
@@ -185,7 +185,7 @@ module RdfContext
185
185
  # Literals or references to objects that aren't subjects, or that have already been serialized
186
186
 
187
187
  args = object.xml_args
188
- puts "predicate: args=#{args.inspect}" if $DEBUG
188
+ puts "predicate: args=#{args.inspect}" if ::RdfContext::debug?
189
189
  attrs = args.pop
190
190
 
191
191
  if as_attr
@@ -198,10 +198,10 @@ module RdfContext
198
198
  attrs.each_pair do |a, av|
199
199
  next if a == "xml:lang" && av == @lang # Lang already specified, don't repeat
200
200
  av = relativize(object) if a == "#{RDF_NS.prefix}:resource"
201
- puts " elt attr #{a}=#{av}" if $DEBUG
201
+ puts " elt attr #{a}=#{av}" if ::RdfContext::debug?
202
202
  pred_node[a] = av.to_s
203
203
  end
204
- puts " elt #{'xmllit ' if object.is_a?(Literal) && object.xmlliteral?}content=#{args.first}" if $DEBUG && !args.empty?
204
+ puts " elt #{'xmllit ' if object.is_a?(Literal) && object.xmlliteral?}content=#{args.first}" if ::RdfContext::debug? && !args.empty?
205
205
  if object.is_a?(Literal) && object.xmlliteral?
206
206
  pred_node.add_child(Nokogiri::XML::CharacterData.new(args.first, node.document))
207
207
  elsif args.first
@@ -87,7 +87,7 @@ module RdfContext
87
87
  oi = resource_to_int(triple.object) || gen_key(triple.object)
88
88
  ci = resource_to_int(context) || gen_key(context)
89
89
 
90
- puts "add: #{si}=#{triple.subject}, #{pi}=#{triple.predicate}, #{oi}=#{triple.object}, #{ci}=#{context ? context.identifier : 'none'}" if $DEBUG
90
+ puts "add: #{si}=#{triple.subject}, #{pi}=#{triple.predicate}, #{oi}=#{triple.object}, #{ci}=#{context ? context.identifier : 'none'}" if ::RdfContext::debug?
91
91
  set_nested_index(@cspo, ci, si, pi, oi)
92
92
  set_nested_index(@cpos, ci, pi, oi, si)
93
93
  set_nested_index(@cosp, ci, oi, si, pi)
@@ -97,7 +97,7 @@ module RdfContext
97
97
  set_nested_index(@pos, pi, oi, si, ci)
98
98
  set_nested_index(@osp, oi, si, pi, ci)
99
99
  end
100
- #dump if $DEBUG
100
+ #dump if ::RdfContext::debug?
101
101
  end
102
102
 
103
103
  # Remove a triple from the context and store
@@ -155,7 +155,7 @@ module RdfContext
155
155
 
156
156
  results = []
157
157
  si, pi, oi = triple_to_int(triple)
158
- puts "triples? #{si}=#{triple.subject}, #{pi}=#{triple.predicate}, #{oi}=#{triple.object}, #{ci}=#{context ? context.identifier : 'none'}" if $DEBUG
158
+ puts "triples? #{si}=#{triple.subject}, #{pi}=#{triple.predicate}, #{oi}=#{triple.object}, #{ci}=#{context ? context.identifier : 'none'}" if ::RdfContext::debug?
159
159
 
160
160
  def result(v, si, pi, oi, ctx)
161
161
  triple = int_to_triple(si, pi, oi)
@@ -164,22 +164,22 @@ module RdfContext
164
164
  # keys are contexts
165
165
  v.keys.each do |ci|
166
166
  context = int_to_resource(ci)
167
- puts "triples= #{si}=#{triple.subject}, #{pi}=#{triple.predicate}, #{oi}=#{triple.object}, #{ci}=#{context ? context.identifier : 'none'}" if $DEBUG
167
+ puts "triples= #{si}=#{triple.subject}, #{pi}=#{triple.predicate}, #{oi}=#{triple.object}, #{ci}=#{context ? context.identifier : 'none'}" if ::RdfContext::debug?
168
168
  yield triple, context
169
169
  end
170
170
  else
171
- puts "triples= #{si}=#{triple.subject}, #{pi}=#{triple.predicate}, #{oi}=#{triple.object}, #{ctx ? ctx.identifier : 'none'}" if $DEBUG
171
+ puts "triples= #{si}=#{triple.subject}, #{pi}=#{triple.predicate}, #{oi}=#{triple.object}, #{ctx ? ctx.identifier : 'none'}" if ::RdfContext::debug?
172
172
  yield triple, ctx
173
173
  end
174
174
  else
175
- puts "triples= #{si}=#{triple.subject}, #{pi}=#{triple.predicate}, #{oi}=#{triple.object}, #{ctx ? ctx.identifier : 'none'}" if $DEBUG
175
+ puts "triples= #{si}=#{triple.subject}, #{pi}=#{triple.predicate}, #{oi}=#{triple.object}, #{ctx ? ctx.identifier : 'none'}" if ::RdfContext::debug?
176
176
  end
177
177
  triple
178
178
  end
179
179
 
180
180
  if si # subject is given
181
181
  if spo.has_key?(si)
182
- #puts "spo[#{si}] = #{spo[si].inspect}" if $DEBUG
182
+ #puts "spo[#{si}] = #{spo[si].inspect}" if ::RdfContext::debug?
183
183
  if pi # subject+predicate is given
184
184
  if spo[si].has_key?(pi)
185
185
  if oi # subject+predicate+object is given
@@ -194,13 +194,13 @@ module RdfContext
194
194
  end
195
195
  elsif triple.predicate.nil? # subject given, predicate unbound
196
196
  spo[si].keys.each do |pi|
197
- #puts "spo[#{si}][#{pi}] = #{spo[si][pi].inspect}" if $DEBUG
197
+ #puts "spo[#{si}][#{pi}] = #{spo[si][pi].inspect}" if ::RdfContext::debug?
198
198
  if oi # object is given
199
199
  results << result(spo[si][pi][oi], si, pi, oi, context, &block) if spo[si][pi].has_key?(oi)
200
200
  else # object unbound
201
201
  #puts "spo[#{si}][#{pi}] = #{spo[si][pi].inspect}"
202
202
  spo[si][pi].each_pair do |oi, value|
203
- #puts "spo[#{si}][#{pi}][#{oi}] = #{spo[si][pi][oi].inspect}" if $DEBUG
203
+ #puts "spo[#{si}][#{pi}][#{oi}] = #{spo[si][pi][oi].inspect}" if ::RdfContext::debug?
204
204
  results << result(value, si, pi, oi, context, &block)
205
205
  end
206
206
  oi = nil
@@ -240,13 +240,13 @@ module RdfContext
240
240
  elsif !triple.object.nil?
241
241
  # Subject+predicate unspecified, object specified but not found, skip
242
242
  else # subject+predicate+object unbound
243
- #puts "spo = #{spo.inspect}" if $DEBUG
243
+ #puts "spo = #{spo.inspect}" if ::RdfContext::debug?
244
244
  spo.keys.each do |si|
245
- #puts "spo[#{si}] = #{spo[si].inspect}" if $DEBUG
245
+ #puts "spo[#{si}] = #{spo[si].inspect}" if ::RdfContext::debug?
246
246
  spo[si].keys.each do |pi|
247
- #puts "spo[#{si}][#{pi}] = #{spo[si][pi].inspect}" if $DEBUG
247
+ #puts "spo[#{si}][#{pi}] = #{spo[si][pi].inspect}" if ::RdfContext::debug?
248
248
  spo[si][pi].each_pair do |oi, value|
249
- #puts "spo[#{si}][#{pi}][#{oi}] = #{spo[si][pi][oi].inspect}" if $DEBUG
249
+ #puts "spo[#{si}][#{pi}][#{oi}] = #{spo[si][pi][oi].inspect}" if ::RdfContext::debug?
250
250
  results << result(value, si, pi, oi, context, &block)
251
251
  end
252
252
  end
@@ -317,7 +317,7 @@ module RdfContext
317
317
  ndx = ndx[key]
318
318
  end
319
319
 
320
- #puts("set_nested_index: #{index.inspect}, keys: #{keys.inspect}") if $DEBUG
320
+ #puts("set_nested_index: #{index.inspect}, keys: #{keys.inspect}") if ::RdfContext::debug?
321
321
  end
322
322
 
323
323
  # Remove context from the list of contexts in a nested index.
@@ -167,18 +167,18 @@ module RdfContext
167
167
  #@statement_cache[qStr] ||= @db.prepare(qStr)
168
168
  @statement_cache[qStr] ||= qStr
169
169
 
170
- puts "executeSQL: '#{qStr}', '#{params.join("', '")}'" if $DEBUG
170
+ puts "executeSQL: '#{qStr}', '#{params.join("', '")}'" if ::RdfContext::debug?
171
171
  if block_given?
172
172
  @db.execute(@statement_cache[qStr], *params) do |row|
173
- puts "executeSQL res: #{row.inspect}" if $DEBUG
173
+ puts "executeSQL res: #{row.inspect}" if ::RdfContext::debug?
174
174
  yield(row)
175
175
  end
176
176
  else
177
- puts "executeSQL no block given" if $DEBUG
177
+ puts "executeSQL no block given" if ::RdfContext::debug?
178
178
  @db.execute(@statement_cache[qStr], *params)
179
179
  end
180
180
  rescue SQLite3::SQLException => e
181
- puts "SQL Exception (ignored): #{e.message}" if $DEBUG
181
+ puts "SQL Exception (ignored): #{e.message}" if ::RdfContext::debug?
182
182
  end
183
183
 
184
184
  CREATE_ASSERTED_STATEMENTS_TABLE = %(
@@ -24,7 +24,7 @@ module RdfContext
24
24
  if args.size == 1
25
25
  uri = Addressable::URI.parse(args[0].to_s.rdf_unescape.rdf_escape)
26
26
  else
27
- uri = Addressable::URI.join(*args.map{|s| s.to_s.rdf_unescape.rdf_escape}.reverse)
27
+ uri = Addressable::URI.join(*args.compact.map{|s| s.to_s.rdf_unescape.rdf_escape}.reverse)
28
28
  end
29
29
 
30
30
  raise ParserException, "<" + uri.to_s + "> is a relative URI" if uri.relative?
@@ -33,18 +33,25 @@ module RdfContext
33
33
  @@uri_hash ||= {}
34
34
  @uri = @@uri_hash["#{uri}#{@normalize}"] ||= begin
35
35
  # Special case if URI has no path, and the authority ends with a '#'
36
- uri = Addressable::URI.parse($1) if @normalize && uri.to_s.match(/^(.*)\#$/)
36
+ #uri = Addressable::URI.parse($1) if @normalize && uri.to_s.match(/^(.*)\#$/)
37
37
 
38
- @normalize ? uri.normalize : uri
38
+ #@normalize ? uri.normalize : uri
39
+ uri
39
40
  end.freeze
40
41
  end
41
42
 
43
+ # Internalized version of URIRef
44
+ def self.intern(*args)
45
+ @@uri_hash ||= {}
46
+ @@uri_hash[args.to_s] ||= URIRef.new(*args)
47
+ end
48
+
42
49
  # Create a URI, either by appending a fragment, or using the input URI
43
50
  # @param [#to_s] input
44
51
  # @return [URIRef]
45
52
  def + (input)
46
53
  input_uri = Addressable::URI.parse(input.to_s)
47
- return URIRef.new(input_uri, self.to_s)
54
+ return URIRef.intern(input_uri, self.to_s)
48
55
  end
49
56
 
50
57
  # short_name of URI for creating QNames.
data/script/console CHANGED
@@ -3,8 +3,6 @@
3
3
  irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
4
 
5
5
  libs = " -r irb/completion"
6
- # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
- # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
- libs << " -r #{File.dirname(__FILE__) + '/../lib/rdf_context.rb'}"
6
+ libs << " -r #{File.join(File.expand_path(File.dirname(__FILE__)), "..", "lib", "rdf_context.rb")}"
9
7
  puts "Loading rdf_context gem"
10
8
  exec "#{irb} #{libs} --simple-prompt"
data/script/tc ADDED
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env ruby -s
2
+ require 'rubygems'
3
+ $:.unshift(File.join(File.expand_path(File.dirname(__FILE__)), "..", 'lib'))
4
+ require 'rdf_context'
5
+ require 'spec/rdfa_helper'
6
+ require 'getoptlong'
7
+
8
+ def run_tc(tc)
9
+ puts "run #{tc.name}"
10
+ graph = RdfContext::RdfaParser.parse(tc.input, tc.informationResourceInput, :strict => $strict, :version => tc.version)
11
+ puts graph.serialize(:format => $format.to_sym, :base => tc.informationResourceInput) unless $quiet
12
+ end
13
+
14
+ $verbose = false
15
+ $format = :ntriples
16
+ $strict = false
17
+ suite = "xhtml"
18
+ opts = GetoptLong.new(
19
+ ["--debug", GetoptLong::NO_ARGUMENT],
20
+ ["--verbose", GetoptLong::NO_ARGUMENT],
21
+ ["--quiet", GetoptLong::NO_ARGUMENT],
22
+ ["--suite", GetoptLong::OPTIONAL_ARGUMENT],
23
+ ["--strict", GetoptLong::NO_ARGUMENT],
24
+ ["--format", GetoptLong::REQUIRED_ARGUMENT]
25
+ )
26
+ opts.each do |opt, arg|
27
+ case opt
28
+ when '--verbose' then $verbose = true
29
+ when '--quiet' then $quiet = true
30
+ when '--debug' then ::RdfContext::debug = true
31
+ when '--format' then $format = arg
32
+ when '--suite' then suite = arg
33
+ when '--strict' then $strict = true
34
+ end
35
+ end
36
+
37
+ test_cases = RdfaHelper::TestCase.test_cases(suite)
38
+
39
+ puts test_cases.length
40
+
41
+ test_cases = test_cases.detect do |tc|
42
+ next unless ARGV.empty? || ARGV.any? {|n| tc.name.match(/#{n}/)}
43
+ run_tc(tc)
44
+ end