[Activerdf] are the examples supposed to work?
renaud.delbru at deri.org
renaud.delbru at deri.org
Fri Aug 11 06:47:12 IST 2006
Quoting carmen <_ at whats-your.name>:
> im a bit in the dark on how RDF 'classes' are supposed to turn into
> Ruby Classes, i guess i will read the sourc. here's my experience
> trying the examples on the front page:
>
>>> eyal = Person.create 'http://eyaloren.org/#me'
> NameError: uninitialized constant Person
>
> so i gave up and couldnt figure out how to get the Person class
> going. (do i need to load the FOAF spec into the store somehow
> first? maybe the eyaloren URI is unresolvable or doesnt respond with
> a 303 and more info or something?).
Yes, you need to have the RDF schema loaded to have access to the Ruby
class Person.
Normally, if a schema is present in your DB, defining Person as a
class and having Property "name", ActiveRDF will generate and load
automatically the corresponding Ruby class.
RDF DB :
<http://m3pe.org/faceteer/test-person#Person>
<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>
<http://www.w3.org/2000/01/rdf-schema#Class> .
<http://m3pe.org/faceteer/test-person#Person>
<http://www.w3.org/2000/01/rdf-schema#subClassOf>
<http://www.w3.org/2000/01/rdf-schema#Resource> .
Ruby script :
eyal = Person.create 'http://eyaloren.org/#me'
p eyal.inspect
=> "#<Person:0xb7bed1f0 @uri=\"http://eyaloren.org/#me\">"
>
> instead, ive created an IdentifiedResource:
>
>>> eyal = IdentifiedResource.create 'http://eyaloren.org/#me'
>>> eyal.name = 'heh'
> => #<IdentifiedResource:0x2af355279818
> @_attributes={"name"=>[#<Literal:0x2af355247f70 @value="heh",
> @type="Literal type is not yet implemented.">, true]},
> @uri="http://eyaloren.org/#me">
>>> eyal.save
You added the property "name" to the IdentifiedResource, but what is
the URI of this property ?
>
>>> IdentifiedResource.find_by_name("heh")
> ActiveRdfError: method find_by_name not found
Without Property URI, ActiveRDF cannot generate the correct SPARQL query.
>
>>> IdentifiedResource.find(:name => "heh")
> WrongTypeQueryError: String unexpected, wrong type received
'find' takes a Literal. Maybe later we will allow to put directly a string.
>
>>> IdentifiedResource.find(:name => Literal.new("heh"))
> ArgumentError: wrong number of arguments (1 for 2)
Never use the constructor "new" with the core object of ActiveRDF. The
constructor to use is "create", which overload and call itself the
Ruby constructor "new".
=> Literal.create("heh")
But, it is the same problem than before. 'find' cannot find anything,
because ActiveRDF doesn't know the URI of the Property 'name'.
>
> short of dropping down to raw SPARQL, what am i doing wrong?
>
> right now, im using a schema like this, that id like to migrate to ActiveRDF:
>
> class Entity < ActiveRecord::Base
> has_many :entity_links
> end
> class EntityLink < ActiveRecord::Base
> belongs_to :entity
> belongs_to :element, :polymorphic => true
> end
> class TextField < ActiveRecord::Base
> has_many :entity_links, :as => :element, :dependent => true
> has_many :entities, :through => :entity_links
> end
>
> and the database consists of essentially a 'triples' table, but its
> actually quintiples, to get all the rails magic:
>
> +--------------+--------------+------+-----+---------+----------------+
> | Field | Type | Null | Key | Default | Extra |
> +--------------+--------------+------+-----+---------+----------------+
> | id | int(11) | NO | PRI | NULL | auto_increment |
> | entity_id | int(11) | YES | | NULL | |
> | name | varchar(123) | YES | | NULL | |
> | element_id | int(11) | YES | | NULL | |
> | element_type | varchar(32) | YES | | NULL | |
> +--------------+--------------+------+-----+---------+----------------+
>
> mysql> select * from entity_links limit 1;
> +----+-----------+-------+------------+--------------+
> | id | entity_id | name | element_id | element_type |
> +----+-----------+-------+------------+--------------+
> | 1 | 246 | story | 1 | TextField |
> +----+-----------+-------+------------+--------------+
> 1 row in set (0.00 sec)
>
> when the object is a literal, element_Type is TextField, Float, Int,
> etc. when its another object, its an Entity. the 'name' is the
> prediace. presumably this should be a very straightforward migration
> to ActiveRDF, i just wish the examples on the frontpage actualy
> worked :)
>
Yes, normally it is straightforward. Try to define the RDF schema in
your database, then the class model 'Entity' will have the attribute
'name', 'element_type', ...
> finally, have you considered switching to Git for version control?
> it took 15 minutes to do the checkout of ~100 small files. wtf!
>
> c,c
> _______________________________________________
> Activerdf mailing list
> Activerdf at lists.deri.org
> http://lists.deri.org/mailman/listinfo/activerdf
>
--
Renaud Delbru
More information about the Activerdf
mailing list