|
List Info
Thread: Declaring non-existant resources by default
|
|
| Declaring non-existant resources by
default |

|
2008-03-19 15:21:20 |
Hello!
Could anyone shed some light on a certain behaviour of
ActiveRDF? Why is
it OK to transparently "construct" a missing class
or a method when one
is referred to in a namespace? For example, if I refer to a
certain
non-existant "PIZZA::MartianPizza" (which fires a
"const_missing" in
Namespace), ObjectManager creates a brand-new class
PIZZA::MartianPizza.
A typo could lead to a whole new tree of concepts Why not
the good
old and default "NameError: uninitialized constant
PIZZA::MartianPizza"?
The same things occurs in Ruby bindings for Redland, so I
wonder if I'm
missing something from a bigger picture.
Slava
_______________________________________________
ActiveRDF mailing list
ActiveRDF lists.deri.org
http
://lists.deri.org/mailman/listinfo/activerdf
|
|
| Example of how Namespaces really work
in ActiveRDF |

|
2008-03-21 06:04:01 |
On 19.03.2008, at 21:21, Slava Kravchenko wrote:
> Could anyone shed some light on a certain behaviour of
ActiveRDF?
sure.
> Why is
> it OK to transparently "construct" a missing
class or a method when
> one
> is referred to in a namespace?
The behaviour which you describe is not what ActiveRDF
actually does.
> For example, if I refer to a certain
> non-existant "PIZZA::MartianPizza" (which
fires a "const_missing" in
> Namespace), ObjectManager creates a brand-new class
> PIZZA::MartianPizza.
> A typo could lead to a whole new tree of concepts Why not
the good
> old and default "NameError: uninitialized constant
> PIZZA::MartianPizza"?
As this is not what actually happens, I have to assume that
you just
made up that example without testing it in irb.
No problem. The stuff that happens there was actually one of
the
hardest things to understand when I started
with activerdf. I have grappled with ideas of how to
simplify this,
but there are just some special things
to the RDF data model which can not be abstracted away in an
easy
manner.
> The same things occurs in Ruby bindings for Redland, so
I wonder if
> I'm
> missing something from a bigger picture.
Redland is written in C, which does not allow it to mirror
the open
world model of RDF semantics.
Instead it has to really on the classical object oriented /
structured object centric programming, which implements the
semantics
of the closed world model.
And because Redland implements closed world semantics, all
the
Redland bindings exhibit this behaviour too.
For more background check out:
E. Oren, R. Delbru, S. Gerke, A. Haller, and S. Decker.
ActiveRDF:
Object-oriented semantic web programming. In Proceedings of
the
International World-Wide Web Conference, pp. 817-823. May
2007.
http://eyaloren.
org/pubs/www2007.pdf
Now how does this work in activerdf ? (the schema is
provided as
attachment)
In the example I try to construct p =
SIOC::Person.new("http://
me.org/me") in different ways.
At first without the schema in the db -> does not work
Second without the name space declaration but after running
the
object manager
-> does not work
Third after declaring the namespace URL, but without running
the
object manager
-> works.
its probably a good idea to try to run the example commands
on your
own machine.
benjamin srvgal44:~/cwe-sioc-explorer/data$ irb
irb(main):001:0> require "rubygems"
=> true
irb(main):002:0> require "active_rdf"
=> true
irb(main):003:0> db = ConnectionPool.add :type =>
:rdflite
=> #<RDFLite:0x2b26be1c6e60 writes=true, reads=true,
db=#<SQLite3: atabase:
0x2b26be1c6cd0 closed=false,
translator=nil, type_translation=false,
driver=#<SQLite3: river::N
ative: river:0x
2b26be1b4710 authorizer=
{}, callback_data={}, trace={}, busy_handler={}>,
statement_factory=SQLite3::Statement, results_as_hash=false,
handle=#<SWIG::TYPE_p_sqlite3:0x2b26be1b45f8>,
transaction_active=false>, keyword_search=false, reasoning=false>
irb(main):004:0> p = SIOC::Person.new("http://me.org/me")
NameError: uninitialized constant SIOC
from (irb):4
irb(main):005:0>
db.load("sioc-schema-as-ntriples.nt")
=> #<SQLite3: atabase:
0x2b26be1c6cd0 closed=false, translator=nil,
type_translation=false, driver=#<SQLite3: river::N
ative: river:
0x2b26be1b4710 authorizer={}, callback_data={}, trace={},
busy_handler={}>, statement_factory=SQLite3::Statement,
results_as_hash=false,
handle=#<SWIG::TYPE_p_sqlite3:0x2b26be1b45f8>,
transaction_active=false>
irb(main):006:0> p = SIOC::Person.new("http://me.org/me")
NameError: uninitialized constant SIOC
from (irb):6
irb(main):007:0> ObjectManager.construct_classes
=> [HTTP_RDFS_ORG_SIOC_NS::Forum,
HTTP_RDFS_ORG_SIOC_NS::Post,
HTTP_RDFS_ORG_SIOC_NS::Role, HTTP_RDFS_ORG_SIOC_NS::Site,
HTTP_RDFS_ORG_SIOC_NS::User,
HTTP_RDFS_ORG_SIOC_NS::Usergroup]
irb(main):008:0> p = SIOC::Person.new("http://me.org/me")
NameError: uninitialized constant SIOC
from (irb):8
irb(main):009:0> Namespace.register(:sioc, 'http://rdfs.org/sioc/ns#
')
=> SIOC
irb(main):010:0> p = SIOC::Person.new("http://me.org/me")
=> #<SIOC::Person:0x2b26be0e7f30 predicates={}, uri="http://me.org/
me">
irb(main):011:0>
_______________________________________________
ActiveRDF mailing list
ActiveRDF lists.deri.org
http
://lists.deri.org/mailman/listinfo/activerdf
|
|
|
| Re: Example of how Namespaces really
work in ActiveRDF |

|
2008-03-21 13:01:19 |
Thanks for the detailed explanation, Benjamin!
Actually, I did tested it firsthand with irb I meant
something a bit
different from what you demonstrated though. Here's the irb
output that
I'm talking about ("pizza.owl" is the 'classic'
Pizza OWL example):
irb(main):003:0> require 'rubygems'
=> true
irb(main):004:0> require 'active_rdf'
=> true
irb(main):005:0> adapter =
ConnectionPool.add_data_source(:type
=> :redland, :location => :memory)
=> #<RedlandAdapter:0xb6d3b380 writes=true,
store=#<Redland::HashStore:0xb6d3b31c dir="", store_type="hashes",
name=".", hash_type="memory",
store=#<SWIG::TYPE_p_librdf_storage_s:0xb6d3b204&g
t;>, reads=true,
model=#<Redland::Model:0xb6d3b18c
store=#<Redland::HashStore:0xb6d3b31c dir="", store_type="hashes",
name=".", hash_type="memory",
store=#<SWIG::TYPE_p_librdf_storage_s:0xb6d3b204&g
t;>,
model=#<SWIG::TYPE_p_librdf_model_s:0xb6d3b13c>
, statements=[]>>
irb(main):006:0> adapter.load('pizza.owl', 'rdfxml')
=> 0
irb(main):007:0> Namespace.register :pizza,
'http://www.co-ode.org/ontologies/pizza/2005/10/18/pi
zza.owl#'
=> PIZZA
irb(main):008:0> ObjectManager.construct_classes
=> [PIZZA::Country, PIZZA::Cheeseyvegetabletopping,
PIZZA::Thinandcrispypizza, PIZZA::Pinekernels,
PIZZA::Sultanatopping,
PIZZA::Tobascopeppersauce, PIZZA::Medium,
PIZZA::Realitalianpizza,
PIZZA::Nonvegetarianpizza, ...
[...]
And here it goes:
irb(main):011:0> PIZZA::Country.ancestors
=> [PIZZA::Country, RDFS::Resource, Object, Kernel]
irb(main):013:0> PIZZA::Abcdefg.ancestors
=> [PIZZA::Abcdefg, RDFS::Resource, Object, Kernel]
As you may notice, PIZZA::Country is listed among the
classes
constructed by ObjectManager. However
"PIZZA::Abcdefg" is missing from
that list (it's not a complete dump, but believe me, it's
not there
How come we get to see this:
irb(main):013:0> PIZZA::Abcdefg.ancestors
=> [PIZZA::Abcdefg, RDFS::Resource, Object, Kernel]
And here's the part of
"objectmanager/namespace.rb" that does it:
class Namespace
[...skipped...]
# registers a namespace prefix and its associated expansion
(full URI)
# e.g. :rdf and 'http://ww
w.w3.org/1999/02/22-rdf-syntax-ns#'
def self.register(prefix, fullURI)
[...]
# catch FOAF::name or all other lookups
class << ns
def method_missing(method, *args)
Namespace.lookup(self.to_s.downcase.to_sym, method)
end
def const_missing(klass)
ObjectManager.construct_class(Namespace.lookup(self.to_s.dow
ncase.to_sym, klass))
end
# make some builtin methods private because lookup
doesn't work
otherwise
# on e.g. RDF::type and FOAF::name
[:type, :name, :id].each {|m| private(m) }
end
# return the namespace proxy object
ns
end
# returns a resource whose URI is formed by concatenation
of prefix
and localname
def self.lookup(prefix, localname)
full_resource = expand(prefix, localname)
RDFS::Resource.new(expand(prefix, localname))
end
[...]
Best regards,
Slava Kravchenko
On Fri, 2008-03-21 at 12:04 +0100, Benjamin Heitmann wrote:
> On 19.03.2008, at 21:21, Slava Kravchenko wrote:
> > Could anyone shed some light on a certain
behaviour of ActiveRDF?
>
> sure.
>
> > Why is
> > it OK to transparently "construct" a
missing class or a method when
> > one
> > is referred to in a namespace?
>
> The behaviour which you describe is not what ActiveRDF
actually does.
>
>
> > For example, if I refer to a certain
> > non-existant "PIZZA::MartianPizza"
(which fires a "const_missing" in
> > Namespace), ObjectManager creates a brand-new
class
> > PIZZA::MartianPizza.
> > A typo could lead to a whole new tree of concepts
Why
not the good
> > old and default "NameError: uninitialized
constant
> > PIZZA::MartianPizza"?
>
> As this is not what actually happens, I have to assume
that you just
> made up that example without testing it in irb.
>
> No problem. The stuff that happens there was actually
one of the
> hardest things to understand when I started
> with activerdf. I have grappled with ideas of how to
simplify this,
> but there are just some special things
> to the RDF data model which can not be abstracted away
in an easy
> manner.
>
> > The same things occurs in Ruby bindings for
Redland, so I wonder if
> > I'm
> > missing something from a bigger picture.
>
> Redland is written in C, which does not allow it to
mirror the open
> world model of RDF semantics.
> Instead it has to really on the classical object
oriented /
> structured object centric programming, which implements
the semantics
> of the closed world model.
>
> And because Redland implements closed world semantics,
all the
> Redland bindings exhibit this behaviour too.
>
> For more background check out:
>
> E. Oren, R. Delbru, S. Gerke, A. Haller, and S. Decker.
ActiveRDF:
> Object-oriented semantic web programming. In
Proceedings of the
> International World-Wide Web Conference, pp. 817-823.
May 2007.
> http://eyaloren.
org/pubs/www2007.pdf
>
>
> Now how does this work in activerdf ? (the schema is
provided as
> attachment)
>
> In the example I try to construct p =
SIOC::Person.new("http://
> me.org/me") in different ways.
>
> At first without the schema in the db -> does not
work
> Second without the name space declaration but after
running the
> object manager
> -> does not work
> Third after declaring the namespace URL, but without
running the
> object manager
> -> works.
>
> its probably a good idea to try to run the example
commands on your
> own machine.
>
> benjamin srvgal44:~/cwe-sioc-explorer/data$ irb
> irb(main):001:0> require "rubygems"
> => true
> irb(main):002:0> require "active_rdf"
> => true
> irb(main):003:0> db = ConnectionPool.add :type
=> :rdflite
[...]
> irb(main):004:0> p = SIOC::Person.new("http://me.org/me")
> NameError: uninitialized constant SIOC
> from (irb):4
> irb(main):005:0>
db.load("sioc-schema-as-ntriples.nt")
[...]
> irb(main):006:0> p = SIOC::Person.new("http://me.org/me")
> NameError: uninitialized constant SIOC
> from (irb):6
> irb(main):007:0> ObjectManager.construct_classes
[...]
> irb(main):008:0> p = SIOC::Person.new("http://me.org/me")
> NameError: uninitialized constant SIOC
> from (irb):8
> irb(main):009:0> Namespace.register(:sioc, 'http://rdfs.org/sioc/ns#
')
> => SIOC
> irb(main):010:0> p = SIOC::Person.new("http://me.org/me")
> => #<SIOC::Person:0x2b26be0e7f30 predicates={}, uri="http://me.org/
> me">
> irb(main):011:0>
_______________________________________________
ActiveRDF mailing list
ActiveRDF lists.deri.org
http
://lists.deri.org/mailman/listinfo/activerdf
|
|
| Re: Example of how Namespaces really
work in ActiveRDF |
  Netherlands |
2008-03-22 07:14:13 |
On 03/21/08/03/08 20:01 +0200, Slava Kravchenko wrote:
>As you may notice, PIZZA::Country is listed among the
classes
>constructed by ObjectManager. However
"PIZZA::Abcdefg" is missing from
>that list (it's not a complete dump, but believe me,
it's not there
>How come we get to see this:
>
>irb(main):013:0> PIZZA::Abcdefg.ancestors
>=> [PIZZA::Abcdefg, RDFS::Resource, Object, Kernel]
Slava, you're right, and we added such behaviour on purpose
for things
like: "puts eyal.foaf::knows".
Of course, we could also only add those predicate/classes
that are defined
in the FOAF schema (so in this example, foaf::knows would
work but
foaf::test wouldn't) but that's very close-world thinking.
First, the
schema is often not available (so we don't even know what
has been defined
in the foaf schema) and also it would be very restrictive.
The same
mechanism is used for arbitrary URIs, not just for
predicates:
Namespace.register :deripeople, "http://deri.org/rdf
/people/"
DERIPEOPLE::eyal.foaf::knows << DERIPEOPLE::benjamin
That wouldn't be possible if we wouldn't allow such URI
abbreviations.
-eyal
_______________________________________________
ActiveRDF mailing list
ActiveRDF lists.deri.org
http
://lists.deri.org/mailman/listinfo/activerdf
|
|
| Re: Example of how Namespaces really
work in ActiveRDF |

|
2008-03-22 12:50:17 |
On Sat, 2008-03-22 at 13:14 +0100, Eyal Oren wrote:
> On 03/21/08/03/08 20:01 +0200, Slava Kravchenko wrote:
> >As you may notice, PIZZA::Country is listed among
the classes
> >constructed by ObjectManager. However
"PIZZA::Abcdefg" is missing from
> >that list (it's not a complete dump, but believe
me, it's not there
> >How come we get to see this:
> >
> >irb(main):013:0> PIZZA::Abcdefg.ancestors
> >=> [PIZZA::Abcdefg, RDFS::Resource, Object,
Kernel]
> Slava, you're right, and we added such behaviour on
purpose for things
> like: "puts eyal.foaf::knows".
I see. So it's a choice of the design. I was wondering if
this had been
an expected behaviour for any RDF library out there, but
couldn't find
any "specifications" or recommendations.
Thanks for the answers!
> Of course, we could also only add those
predicate/classes that are defined
> in the FOAF schema (so in this example, foaf::knows
would work but
> foaf::test wouldn't) but that's very close-world
thinking. First, the
> schema is often not available (so we don't even know
what has been defined
> in the foaf schema) and also it would be very
restrictive. The same
> mechanism is used for arbitrary URIs, not just for
predicates:
>
> Namespace.register :deripeople, "http://deri.org/rdf
/people/"
> DERIPEOPLE::eyal.foaf::knows <<
DERIPEOPLE::benjamin
>
> That wouldn't be possible if we wouldn't allow such URI
abbreviations.
>
> -eyal
> _______________________________________________
> ActiveRDF mailing list
> ActiveRDF lists.deri.org
> http
://lists.deri.org/mailman/listinfo/activerdf
_______________________________________________
ActiveRDF mailing list
ActiveRDF lists.deri.org
http
://lists.deri.org/mailman/listinfo/activerdf
|
|
[1-5]
|
|