Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix bug that would not use :prefix definitions when writing, if the k…

…ey was a symbol.

This fixes issue #1
  • Loading branch information...
commit 15780623b2b51b1309ec409f20c04932c4942522 1 parent 9ad0497
@gkellogg authored
View
1  Gemfile
@@ -3,6 +3,7 @@ source "http://rubygems.org"
gemspec :name => ""
gem 'rdf', :git => "git://github.com/ruby-rdf/rdf.git"
gem 'backports', :platforms => %w(ruby_18)
+gem "rdf-spec", :path => "../rdf-spec"
group :development do
gem "wirble"
View
29 Gemfile.lock
@@ -1,8 +1,8 @@
GIT
remote: git://github.com/ruby-rdf/rdf.git
- revision: 08fd56617fc6973ce4fc6ae4abed5959c5bec2ac
+ revision: d370dbb82fd0924acc5866fd020205f81ce76704
specs:
- rdf (0.3.5.2)
+ rdf (0.3.6)
addressable (>= 2.2.6)
PATH
@@ -13,6 +13,12 @@ PATH
json (>= 1.6.5)
rdf (>= 0.3.5)
+PATH
+ remote: ../rdf-spec
+ specs:
+ rdf-spec (0.3.6)
+ rspec (>= 2.8.0)
+
GEM
remote: http://rubygems.org/
specs:
@@ -56,16 +62,14 @@ GEM
rdf-xsd (>= 0.3.4)
rdf-n3 (0.3.7)
rdf (>= 0.3.4)
- rdf-rdfa (0.3.12)
- haml (>= 3.0.0)
+ rdf-rdfa (0.3.14)
+ haml (>= 3.1.6)
htmlentities (>= 4.3.0)
- rdf (>= 0.3.3)
- rdf-xsd (>= 0.3.5)
- rdf-rdfxml (0.3.7)
+ rdf (>= 0.3.5)
+ rdf-xsd (>= 0.3.7)
+ rdf-rdfxml (0.3.8)
rdf (>= 0.3.4)
rdf-xsd (>= 0.3.5)
- rdf-spec (0.3.5.1)
- rspec (>= 2.8.0)
rdf-trig (0.1.3)
rdf (>= 0.3.4)
rdf-turtle (>= 0.1.1)
@@ -73,14 +77,15 @@ GEM
rdf (~> 0.3.0)
rdf-turtle (0.1.2)
rdf (>= 0.3.4)
- rdf-xsd (0.3.6)
+ rdf-xsd (0.3.7)
+ backports
nokogiri (>= 1.5.0)
rdf (>= 0.3.4)
rspec (2.10.0)
rspec-core (~> 2.10.0)
rspec-expectations (~> 2.10.0)
rspec-mocks (~> 2.10.0)
- rspec-core (2.10.0)
+ rspec-core (2.10.1)
rspec-expectations (2.10.0)
diff-lcs (~> 1.1.3)
rspec-mocks (2.10.1)
@@ -116,7 +121,7 @@ DEPENDENCIES
open-uri-cached (>= 0.0.5)
rdf!
rdf-isomorphic (>= 0.3.4)
- rdf-spec (>= 0.3.5)
+ rdf-spec!
rdf-trig (>= 0.1.1)
rdf-turtle (>= 0.1.1)
rspec (>= 2.8.0)
View
10 example-files/gm.ttl
@@ -0,0 +1,10 @@
+@prefix dc: <http://purl.org/dc/terms/> .
+@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
+@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+@prefix senet: <https://senet.org/ns#> .
+
+<https://senet.org/gm> a <http://vocab.org/frbr/core#Work>;
+ dc:title "リズム天国"@ja,
+ "Rhythm Paradise"@en;
+ <https://senet.org/ns#unofficialTitle> "Rhythm Tengoku"@en;
+ <https://senet.org/ns#urlkey> "rhythm-tengoku"^^xsd:string .
View
9 lib/json/ld/evaluation_context.rb
@@ -326,17 +326,19 @@ def mapping(term)
##
# Set term mapping
#
- # @param [String] term
+ # @param [#to_s] term
# @param [RDF::URI, String] value
#
# @return [RDF::URI, String]
def set_mapping(term, value)
+ term = term.to_s
+ term_sym = term.empty? ? "" : term.to_sym
# raise InvalidContext::Syntax, "mapping term #{term.inspect} must be a string" unless term.is_a?(String)
# raise InvalidContext::Syntax, "mapping value #{value.inspect} must be an RDF::URI" unless value.nil? || value.to_s[0,1] == '@' || value.is_a?(RDF::URI)
debug {"map #{term.inspect} to #{value.inspect}"}
iri_to_term.delete(@mappings[term].to_s) if @mappings[term]
@mappings[term] = value
- @options[:prefixes][term] = value if @options.has_key?(:prefixes)
+ @options[:prefixes][term_sym] = value if @options.has_key?(:prefixes)
iri_to_term[value.to_s] = term
end
@@ -539,7 +541,10 @@ def compact_iri(iri, options = {})
# @type coercion, @container coercion or @language coercion rules
# along with the iri itself.
if terms.empty?
+ debug("curies") {"mappings: #{mappings.inspect}"}
curies = mappings.keys.map do |k|
+ debug("curies[#{k}]") {"#{mapping(k).inspect}"}
+ #debug("curies[#{k}]") {"#{(mapping(k).to_s.length > 0).inspect}, #{iri.to_s.index(mapping(k).to_s)}"}
iri.to_s.sub(mapping(k).to_s, "#{k}:") if
mapping(k).to_s.length > 0 &&
iri.to_s.index(mapping(k).to_s) == 0 &&
View
2  spec/matchers.rb
@@ -61,7 +61,7 @@ def normalize(graph)
failure_message_for_should do |actual|
"Expected: #{expected.is_a?(String) ? expected : expected.to_json(JSON_STATE)}\n" +
"Actual : #{actual.is_a?(String) ? actual : actual.to_json(JSON_STATE)}\n" +
- (expected.is_a?(Hash) && actual.is_a?(Hash) ? "Diff: #{expected.diff(actual).to_json(JSON_STATE)}\n" : "") +
+ #(expected.is_a?(Hash) && actual.is_a?(Hash) ? "Diff: #{expected.diff(actual).to_json(JSON_STATE)}\n" : "") +
"Processing results:\n#{info.join("\n")}"
end
end
View
28 spec/writer_spec.rb
@@ -34,7 +34,7 @@
}], @debug)
end
- it "should use qname URIs with prefix" do
+ it "should use qname URIs with standard prefix" do
input = %(<http://xmlns.com/foaf/0.1/b> <http://xmlns.com/foaf/0.1/c> <http://xmlns.com/foaf/0.1/d> .)
serialize(input, :standard_prefixes => true).
should produce({
@@ -46,6 +46,32 @@
}, @debug)
end
+ it "should use qname URIs with parsed prefix" do
+ input = %(
+ <https://senet.org/gm> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://vocab.org/frbr/core#Work> .
+ <https://senet.org/gm> <http://purl.org/dc/terms/title> "Rhythm Paradise"@en .
+ <https://senet.org/gm> <https://senet.org/ns#unofficialTitle> "Rhythm Tengoku"@en .
+ <https://senet.org/gm> <https://senet.org/ns#urlkey> "rhythm-tengoku" .
+ )
+ serialize(input, :prefixes => {
+ :dc => "http://purl.org/dc/terms/",
+ :frbr => "http://vocab.org/frbr/core#",
+ :senet => "https://senet.org/ns#",
+ }).
+ should produce({
+ '@context' => {
+ "dc" => "http://purl.org/dc/terms/",
+ "frbr" => "http://vocab.org/frbr/core#",
+ "senet" => "https://senet.org/ns#"
+ },
+ '@id' => "https://senet.org/gm",
+ "@type" => "frbr:Work",
+ "dc:title" => {"@value" => "Rhythm Paradise","@language" => "en"},
+ "senet:unofficialTitle" => {"@value" => "Rhythm Tengoku","@language" => "en"},
+ "senet:urlkey" => "rhythm-tengoku"
+ }, @debug)
+ end
+
it "should use CURIEs with empty prefix" do
input = %(<http://xmlns.com/foaf/0.1/b> <http://xmlns.com/foaf/0.1/c> <http://xmlns.com/foaf/0.1/d> .)
begin
Please sign in to comment.
Something went wrong with that request. Please try again.