Skip to content

Instantly share code, notes, and snippets.

@RickMoynihan
Last active December 27, 2015 11:09
Show Gist options
  • Select an option

  • Save RickMoynihan/7316921 to your computer and use it in GitHub Desktop.

Select an option

Save RickMoynihan/7316921 to your computer and use it in GitHub Desktop.
gem 'rdf', '1.0.10'
gem 'tripod'
~/landfill/rdf-utf8
17:57 $ ruby ./rdf-utf8.rb
Using RDF V1.0.10
File Encoding: UTF-8
Lambdas render as: λ
Set property foo to: bar
Saved #<Foo:0x007fb732f36880 @uri=#<RDF::URI:0x3fdb9979b3f0(http://foobar.com/)>, @repository=#<RDF::Repository:0x3fdb9979b0e4()>, @new_record=false, @graph_uri=#<RDF::URI:0x3fdb9976f228(http://example.org/#encoding)>, @validation_context=nil, @errors=#<ActiveModel::Errors:0x007fb732b4aed8 @base=#<Foo:0x007fb732f36880 ...>, @messages={}>>
using accept header: text/plain; charset=utf-8
<http://foobar.com/> <http://www.w3.org/2000/01/rdf-schema#label> "bar" .
encoding is UTF-8
line is US-ASCII
encoding is UTF-8
Read: bar
Set property foo to: λ
Saved #<Foo:0x007fb732e298c0 @uri=#<RDF::URI:0x3fdb99714c38(http://foobar.com/)>, @repository=#<RDF::Repository:0x3fdb99714954()>, @new_record=false, @graph_uri=#<RDF::URI:0x3fdb99714774(http://example.org/#encoding)>, @validation_context=nil, @errors=#<ActiveModel::Errors:0x007fb732e2d678 @base=#<Foo:0x007fb732e298c0 ...>, @messages={}>>
using accept header: text/plain; charset=utf-8
<http://foobar.com/> <http://www.w3.org/2000/01/rdf-schema#label> "λ" .
encoding is UTF-8
line is ASCII-8BIT
/Users/rick/.rvm/gems/ruby-1.9.3-p448/gems/rdf-1.0.10/lib/rdf/reader.rb:493:in `encode!': "\xCE" from ASCII-8BIT to UTF-8 (Encoding::UndefinedConversionError)
from /Users/rick/.rvm/gems/ruby-1.9.3-p448/gems/rdf-1.0.10/lib/rdf/reader.rb:493:in `readline'
from /Users/rick/.rvm/gems/ruby-1.9.3-p448/gems/rdf-1.0.10/lib/rdf/ntriples/reader.rb:254:in `block in read_triple'
from /Users/rick/.rvm/gems/ruby-1.9.3-p448/gems/rdf-1.0.10/lib/rdf/ntriples/reader.rb:253:in `loop'
from /Users/rick/.rvm/gems/ruby-1.9.3-p448/gems/rdf-1.0.10/lib/rdf/ntriples/reader.rb:253:in `read_triple'
from /Users/rick/.rvm/gems/ruby-1.9.3-p448/gems/rdf-1.0.10/lib/rdf/reader.rb:382:in `read_statement'
from /Users/rick/.rvm/gems/ruby-1.9.3-p448/gems/rdf-1.0.10/lib/rdf/reader.rb:299:in `block in each_statement'
from /Users/rick/.rvm/gems/ruby-1.9.3-p448/gems/rdf-1.0.10/lib/rdf/reader.rb:299:in `loop'
from /Users/rick/.rvm/gems/ruby-1.9.3-p448/gems/rdf-1.0.10/lib/rdf/reader.rb:299:in `each_statement'
from /Users/rick/.rvm/gems/ruby-1.9.3-p448/gems/tripod-0.7.26/lib/tripod/finders.rb:129:in `block in _rdf_graph_from_ntriples_string'
from /Users/rick/.rvm/gems/ruby-1.9.3-p448/gems/rdf-1.0.10/lib/rdf/reader.rb:202:in `call'
from /Users/rick/.rvm/gems/ruby-1.9.3-p448/gems/rdf-1.0.10/lib/rdf/reader.rb:202:in `initialize'
from /Users/rick/.rvm/gems/ruby-1.9.3-p448/gems/tripod-0.7.26/lib/tripod/finders.rb:128:in `new'
from /Users/rick/.rvm/gems/ruby-1.9.3-p448/gems/tripod-0.7.26/lib/tripod/finders.rb:128:in `_rdf_graph_from_ntriples_string'
from /Users/rick/.rvm/gems/ruby-1.9.3-p448/gems/tripod-0.7.26/lib/tripod/finders.rb:151:in `_create_and_hydrate_resources_from_sparql'
from /Users/rick/.rvm/gems/ruby-1.9.3-p448/gems/tripod-0.7.26/lib/tripod/finders.rb:120:in `_resources_from_sparql'
from /Users/rick/.rvm/gems/ruby-1.9.3-p448/gems/tripod-0.7.26/lib/tripod/criteria/execution.rb:15:in `resources'
from ./rdf-utf8.rb:44:in `read_lambda'
from ./rdf-utf8.rb:52:in `<main>'
# -*- coding: utf-8 -*-
require 'rubygems'
require 'bundler/setup'
require 'tripod'
puts "Using RDF V#{RDF::VERSION}"
puts "File Encoding: #{__ENCODING__.name}"
LAMBDA = 'λ'
puts "Lambdas render as: #{LAMBDA}"
Tripod.configure do |config|
config.update_endpoint = 'http://127.0.0.1:3030/encoding_tests/update'
config.query_endpoint = 'http://127.0.0.1:3030/encoding_tests/sparql'
config.timeout_seconds = 30
# e.g memcached -m 1024 -p 11214 -I 5M -u memcache -l 127.0.0.1
config.cache_store = Tripod::CacheStores::MemcachedCacheStore.new('localhost:11211')
end
class Foo
include Tripod::Resource
graph_uri 'http://example.org/#encoding'
field :foo, 'http://www.w3.org/2000/01/rdf-schema#label'
end
def write val
f = Foo.new 'http://foobar.com/'
f.foo = val
puts "Set property foo to: #{f.foo}"
f.save
puts "Saved #{f.inspect}"
end
def read_bar
results = Foo.where("?uri <http://www.w3.org/2000/01/rdf-schema#label> \"bar\"").resources
puts "Read: #{results.first.foo}"
end
def read_lambda
results = Foo.where("?uri <http://www.w3.org/2000/01/rdf-schema#label> \"#{LAMBDA}\"").resources
puts "Read: #{results.first.foo}"
end
write 'bar'
read_bar
write LAMBDA
read_lambda
@RickMoynihan

Copy link
Copy Markdown
Author

Causes about output when using fuseki v1.0.0. Problem does not appear to occur on fuseki 0.2.7 or when using rdf v1.0.8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment