Comments (4)
Hi @tmaier.
Indeed in that example (which should be changed btw since not very clear) each Man would be a cop and a father.
You just need to create a new class FireFighter
actually with the attributes. Then:
uri = 'http://example.org/4563'
person = Man.for(uri)
person.firstName = 'John'
person.save!
person = FireFighter.for(uri)
person.level = 5
person.save!
Each save will add the RDF.type statements into the repository.
from spira.
Think of Spira resources as being "reflections" of your storage - if you have some type declared in the RDF storage, you are expected to have a corresponding Ruby class in Spira, and vice versa. So adding/replacing types is about actually adding/replacing individual Spira types (Ruby classes).
As a side note, I've been pondering the implementation of "automagically" declaring Ruby classes based on the data in the RDF storage, to keep things "synchronized". However, there are certain issues with that, so we've been leaving that to be decided by Spira users' for their projects individually, so to say.
from spira.
(I've deleted a previous commented about manipulating the resource's @types
set as I've since realised this operates on the singleton_class and therefore affects all instances)
I think there are two issues here: setting type(s) at runtime and removing types from instances.
You can set type at runtime with @abrisse's answer and a bit of metaprogramming:
klass = Class.new(Spira::Base) do
type RDF::URI("http://example.org/people/firefighter")
end
klass.for(m.uri).save
Removing types doesn't appear to be possible without modifying the repository graph directly:
Spira.repository.delete([m.uri, RDF::URI.new("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"), RDF::URI.new("http://example.org/people/cop")])
Which will remove the offending statement from the repository, but m.types
will still report it (even after m.reload
), and m.save
will add the statement back into the repository.
If the models have unique types/ predicates then it's possible to remove types with model.destroy
:
class Man < Spira::Base
type RDF::URI.new('http://example.org/people/man')
end
class FireFighter < Spira::Base
type RDF::URI.new('http://example.org/people/fire_fighter')
end
class Cop < Spira::Base
type RDF::URI.new('http://example.org/people/cop')
end
uri = 'http://example.org/4563'
m = Man.for(uri).save # uri a people:man
c = Cop.for(uri).save # uri a people:man, people:cop
# retires
c.destroy # uri a people:man
# new career
f = FireFighter.for(uri).save # uri a people:man, people:fire_fighter
But if the types of predicates overlap then they'll be lost:
class PoliceMan < Spira::Base
type RDF::URI.new('http://example.org/people/man')
type RDF::URI.new('http://example.org/people/cop')
end
another_uri = 'http://example.org/999'
p = PoliceMan.for(uri).save # another_uri a people:man, people:cop
p.destroy # another_uri has no type
Although it's possible to reinstate them, of course
Man.for(another_uri).save # another_uri a people:man
Of course the fact that this sort of manipulation is awkward is probably inevitable given that object and graph models are so very different in the first place!
from spira.
@Robsteranium: You really shouldn't use more than one type per class. You will never find an ontology with an owl:Class which is just a union of 2 others.
I like to compare owl:Classes and Ruby Mixins : they both add new capacities/attributes on an instance.
from spira.
Related Issues (20)
- Forthcoming RDF.rb 1.1 release and use of git-flow HOT 3
- Incompatibility with rdf > 1.0.7 HOT 4
- example Rails with Spira and allegrograph , any? HOT 1
- help for use Spira in Controller Rails HOT 9
- erro user TYPE , HOT 3
- Error use save method with Blank Nodes. HOT 6
- Spira.repository unavailable in Rails controller HOT 5
- Feature Request: Distinguish between serialized properties and reflections HOT 4
- #== should compare attributes HOT 2
- how to create a blank node without BASE URI, since in theory should not have URI HOT 3
- Spira#count counts subjects - should it count instances? HOT 1
- Use of inefficient splat argument methods in Spira codebase HOT 1
- Spira seems incompatible with activesupport >= 5.2.0 HOT 3
- reset_changes in base.rb throwing NilClass error HOT 6
- #new_record? is wrong if any data already exists
- uninitialized constant RDF::Vocab
- Tests failing due to git refs for gems HOT 1
- link style in docs: github vs yard HOT 2
- Update minimum versions for activemodel/support HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spira.