rdf_context 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,8 @@
1
+ === 0.5.3
2
+ * Fix bug in XML serializer when type is a BNode.
3
+ * Undo change in 0.5.2 to remove old binding based on equivalent URI to equivalent prefix.
4
+ * Undo change form 0.5.1 to make BNode.new("") a named identifier. Required for RDFa test 0088.
5
+
1
6
  === 0.5.2
2
7
  * Remove old binding for a namespace URI creating a new binding
3
8
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.2
1
+ 0.5.3
data/bin/rdf_context CHANGED
@@ -13,7 +13,7 @@ class Parse
13
13
  output = parser.graph.serialize(:format => $format.to_sym, :base => base_uri)
14
14
  puts output unless $quiet
15
15
 
16
- puts parser.debug.join("\n\t") if $verbose
16
+ puts parser.debug.to_a.join("\n\t") if $verbose
17
17
  rescue RdfException => e
18
18
  puts "Parse failure: #{e.message}"
19
19
  puts parser.debug if $verbose && parser
@@ -16,7 +16,7 @@ module RdfContext
16
16
  # @param [String] identifier:: Legal NCName or nil for a named BNode
17
17
  # @param [Hash] context:: Context used to store named BNodes
18
18
  def initialize(identifier = nil, context = {})
19
- if identifier.to_s.empty?
19
+ if identifier.nil?
20
20
  @identifier = generate_bn_identifier
21
21
  elsif identifier.match(/n?bn\d+[a-z]+(N\w+)?$/)
22
22
  @identifier = context[identifier] || identifier
@@ -50,6 +50,7 @@ module RdfContext
50
50
  add_debug("namesspace", "'#{prefix}' <#{uri}>")
51
51
  uri = @default_ns.uri if uri == '#'
52
52
  @graph.bind(Namespace.new(uri, prefix))
53
+ add_debug("namesspace", "ns = #{@graph.nsbinding.inspect}")
53
54
  end
54
55
 
55
56
  def process_statements(document)
@@ -177,20 +178,26 @@ module RdfContext
177
178
  end
178
179
 
179
180
  def process_expression(expression)
180
- add_debug(*expression.info("process_expression"))
181
181
  if expression.respond_to?(:pathitem) && expression.respond_to?(:expression)
182
+ add_debug(*expression.info("process_expression(pathitem && expression)"))
182
183
  process_path(expression) # Returns last object in chain
183
184
  elsif expression.respond_to?(:uri)
185
+ add_debug(*expression.info("process_expression(uri)"))
184
186
  process_uri(expression.uri)
185
187
  elsif expression.respond_to?(:localname)
188
+ add_debug(*expression.info("process_expression(localname)"))
186
189
  build_uri(expression)
187
190
  elsif expression.respond_to?(:anonnode)
191
+ add_debug(*expression.info("process_expression(anonnode)"))
188
192
  process_anonnode(expression)
189
193
  elsif expression.respond_to?(:literal)
194
+ add_debug(*expression.info("process_expression(literal)"))
190
195
  process_literal(expression)
191
196
  elsif expression.respond_to?(:numericliteral)
197
+ add_debug(*expression.info("process_expression(numericliteral)"))
192
198
  process_numeric_literal(expression)
193
199
  elsif expression.respond_to?(:boolean)
200
+ add_debug(*expression.info("process_expression(boolean)"))
194
201
  barename = expression.text_value.to_s
195
202
  if @keywords && !@keywords.include?(barename)
196
203
  build_uri(barename)
@@ -198,6 +205,7 @@ module RdfContext
198
205
  Literal.typed(barename.delete("@"), XSD_NS.boolean)
199
206
  end
200
207
  elsif expression.respond_to?(:barename)
208
+ add_debug(*expression.info("process_expression(barename)"))
201
209
  barename = expression.text_value.to_s
202
210
 
203
211
  # Should only happen if @keywords is defined, and text_value is not a defined keyword
@@ -210,6 +218,7 @@ module RdfContext
210
218
  build_uri(barename)
211
219
  end
212
220
  else
221
+ add_debug(*expression.info("process_expression(else)"))
213
222
  build_uri(expression)
214
223
  end
215
224
  end
@@ -325,8 +334,13 @@ module RdfContext
325
334
  prefix = expression.respond_to?(:nprefix) ? expression.nprefix.text_value.to_s : ""
326
335
  localname = expression.localname.text_value if expression.respond_to?(:localname)
327
336
  localname ||= (expression.respond_to?(:text_value) ? expression.text_value : expression).to_s.sub(/^:/, "")
337
+ localname = nil if localname.empty? # In N3/Turtle "_:" is not named
328
338
 
329
- # add_debug(*expression.info("build_uri(#{prefix.inspect}, #{localname.inspect})"))
339
+ if expression.respond_to?(:info)
340
+ add_debug(*expression.info("build_uri(#{prefix.inspect}, #{localname.inspect})"))
341
+ else
342
+ add_debug("", "build_uri(#{prefix.inspect}, #{localname.inspect})")
343
+ end
330
344
 
331
345
  uri = if @graph.nsbinding[prefix]
332
346
  @graph.nsbinding[prefix] + localname.to_s.rdf_escape
@@ -35,7 +35,7 @@ module RdfContext
35
35
  preprocess
36
36
 
37
37
  predicates = @graph.predicates.uniq
38
- possible = predicates | @graph.objects.uniq
38
+ possible = predicates + @graph.objects.uniq
39
39
  namespaces = {}
40
40
  required_namespaces = {}
41
41
  possible.each do |res|
@@ -100,10 +100,11 @@ module RdfContext
100
100
  puts "subject: #{subject.to_n3}, props: #{properties.inspect}" if $DEBUG
101
101
 
102
102
  rdf_type, *rest = properties.fetch(RDF_TYPE.to_s, [])
103
- properties[RDF_TYPE.to_s] = rest
104
103
  if rdf_type.is_a?(URIRef)
105
104
  element = get_qname(rdf_type)
105
+ properties[RDF_TYPE.to_s] = rest
106
106
  if rdf_type.namespace && @default_ns && rdf_type.namespace.uri == @default_ns.uri
107
+ properties[RDF_TYPE.to_s] = rest
107
108
  element = rdf_type.short_name
108
109
  end
109
110
  end
@@ -507,7 +507,7 @@ module RdfContext
507
507
  # Bind namespace to store, returns bound namespace
508
508
  def bind(namespace)
509
509
  # Remove existing bindings for the same URI
510
- executeSQL("DELETE FROM #{namespace_binds} WHERE uri=?", namespace.uri)
510
+ executeSQL("DELETE FROM #{namespace_binds} WHERE prefix=?", namespace.prefix)
511
511
  executeSQL("INSERT INTO #{namespace_binds} VALUES (?, ?)", namespace.prefix, namespace.uri)
512
512
  # May throw exception, should be handled in driver-specific class
513
513
 
@@ -35,10 +35,11 @@ module RdfContext
35
35
 
36
36
  # Bind namespace to store, returns bound namespace
37
37
  def bind(namespace)
38
+ puts "bind #{namespace.inspect}"
38
39
  # Over-write an empty prefix
39
40
  uri = namespace.uri.to_s
40
41
  @uri_binding.delete(uri)
41
- @nsbinding.delete_if {|prefix, ns| ns.uri.to_s == uri}
42
+ @nsbinding.delete_if {|prefix, ns| namespace.prefix == prefix}
42
43
 
43
44
  @uri_binding[uri] = namespace
44
45
  @nsbinding[namespace.prefix.to_s] = namespace
data/spec/bnode_spec.rb CHANGED
@@ -44,10 +44,16 @@ describe "Blank nodes" do
44
44
  BNode.new(bn.to_s).should == bn
45
45
  end
46
46
 
47
+ describe "which has a nil identifier" do
48
+ subject { BNode.new("", @context) }
49
+ it "should not be the same as an anonymous identifier" do should_not == BNode.new end
50
+ it "should not be the same as another nil identifier" do should_not == BNode.new(nil, @context) end
51
+ end
52
+
47
53
  describe "which has a blank identifier" do
48
54
  subject { BNode.new("", @context) }
49
55
  it "should not be the same as an anonymous identifier" do should_not == BNode.new end
50
- it "should not be the same as another blank identifier" do should_not == BNode.new("", @context) end
56
+ it "should be the same as another blank identifier" do should == BNode.new("", @context) end
51
57
  end
52
58
 
53
59
  describe "which are anonymous" do
@@ -332,12 +332,20 @@ describe "XML Serializer" do
332
332
  bn = BNode.new("a")
333
333
  @graph.add_triple(bn, DC_NS.title, "foo")
334
334
  @graph.add_triple(bn, OWL_NS.equals, bn)
335
- check_xpaths(
336
- serialize(:attributes => :untyped, :base => "http://release/"),
337
- "/rdf:RDF/rdf:Description/@dc:title" => "foo",
338
- "/rdf:RDF/rdf:Description/@rdf:nodeID" => /Na$/,
339
- "/rdf:RDF/rdf:Description/owl:equals/@rdf:nodeID" => /Na$/
340
- )
335
+ check_xpaths(
336
+ serialize(:attributes => :untyped, :base => "http://release/"),
337
+ "/rdf:RDF/rdf:Description/@dc:title" => "foo",
338
+ "/rdf:RDF/rdf:Description/@rdf:nodeID" => /Na$/,
339
+ "/rdf:RDF/rdf:Description/owl:equals/@rdf:nodeID" => /Na$/
340
+ )
341
+ end
342
+
343
+ it "should replicate rdfcore/rdfms-seq-representation" do
344
+ @graph.parse(%(
345
+ <http://example.org/eg#eric> a [ <http://example.org/eg#intersectionOf> (<http://example.org/eg#Person> <http://example.org/eg#Male>)] .
346
+ ))
347
+ graph2 = Graph.new
348
+ graph2.parse(serialize(:format => :xml)).should be_equivalent_graph(@graph)
341
349
  end
342
350
  end
343
351
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 5
8
- - 2
9
- version: 0.5.2
8
+ - 3
9
+ version: 0.5.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Gregg Kellogg
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-11 00:00:00 -07:00
17
+ date: 2010-04-14 00:00:00 -07:00
18
18
  default_executable: rdf_context
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency