Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Readme Persistence example differs from actual behaviour #209

Closed
eocarragain opened this issue Apr 19, 2016 · 0 comments
Closed

Readme Persistence example differs from actual behaviour #209

eocarragain opened this issue Apr 19, 2016 · 0 comments

Comments

@eocarragain
Copy link
Contributor

When following the README in irb, the output I get differs from the documentation. Specifically, the Person-related triples are persisted to :default rather than :people

Output (c.f. README)

# Registers in-memory repositories. Other implementations of
# RDF::Repository support persistence to (e.g.) triplestores & NoSQL
# databases.
ActiveTriples::Repositories.add_repository :default, RDF::Repository.new
ActiveTriples::Repositories.add_repository :people, RDF::Repository.new

class Person
  include  ActiveTriples::RDFSource
  configure :type => RDF::FOAF.Person, :base_uri => 'http://example.org/people#', :repository => :people
  property :name, :predicate => RDF::FOAF.name
end

class Thing
  include  ActiveTriples::RDFSource
  configure :type => RDF::OWL.Thing, :base_uri => 'http://example.org/things#', :repository => :default
  property :title, :predicate => RDF::DC.title
  property :description, :predicate => RDF::DC.description
  property :creator, :predicate => RDF::DC.creator, :class_name => 'Person'
end

t = Thing.new('1')
t.title = 'A Thing'
t.creator = Person.new('1')
t.persisted? # => false
t.creator.first.name = 'Tove'
t.persist!

ActiveTriples::Repositories.repositories[:default].dump :ntriples
# => "<http://example.org/things#1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Thing> .\n<http://example.org/things#1> <http://purl.org/dc/terms/title> \"A Thing\" .\n<http://example.org/things#1> <http://purl.org/dc/terms/creator> <http://example.org/people#1> .\n<http://example.org/people#1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> .\n<http://example.org/people#1> <http://xmlns.com/foaf/0.1/name> \"Tove\" .\n"

t.creator.first.persisted? # => true
t.creator.first.persist! # => true

ActiveTriples::Repositories.repositories[:people].dump :ntriples
# => ""

If i create and persist a Person instance without associating it with a Thing instance, it works as expected:

p2 = Person.new("2")
# => #<Person:0x4997b6e(#<Person:0x932f6dc>)> 
p2.name ="Nom"
# => "Nom" 
p2.persisted?
# => false 
ActiveTriples::Repositories.repositories[:people].dump :ntriples
# => "" 
p2.persist!
# => true 
p2.persisted?
# => true 
ActiveTriples::Repositories.repositories[:people].dump :ntriples
# => "<http://example.org/people#2> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> .\n<http://example.org/people#2> <http://xmlns.com/foaf/0.1/name> \"Nom\" .\n"
@no-reply no-reply added this to the Documentation milestone Jul 29, 2016
no-reply pushed a commit that referenced this issue Aug 9, 2016
Fixes up README.md for code correctness. Closes #209.
no-reply pushed a commit that referenced this issue Aug 19, 2016
Fixes up README.md for code correctness. Closes #209.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants