DOAP example code

9 views
Skip to first unread message

cakebread

unread,
Mar 19, 2008, 12:31:44 PM3/19/08
to rdfalchemy-dev
Hi Philip,

I'm getting back to work on using RDFAlchemy for DOAP and FOAF. The
SPARQL endpoint features you've added look pretty nice, can't wait to
try it out.

In the current trunk code, as of rev 109, I can't quite figure out
what is going on in doap.py in the 'samples' directory.

If I comment out 'mapper(Project,Release)' and the Release class, the
code behaves the same, so how is the Release class meant to be used?

I'm trying to get all the file-release URLs. This code works as-is if
the DOAP has only a single 'file-release', but if there are multiple,
I can only get one. I'm adding this line to the 'release in
p.releases' loop:

print " %s" % release[DOAP['file-release']].resUri

(The sample DOAP you fetch only has one file-release per Version, so
try a project like 'nut' instead of 'accs')

Here's an editable pastebin with the code I'm working on:
http://www.collabedit.com/display?id=90701d5bd97a81d7ad5997143ce4b992

Thanks,
Rob

Philip Cooper

unread,
Mar 19, 2008, 3:27:28 PM3/19/08
to rdfalch...@googlegroups.com
cakebread at about 3/19/08 10:31 AM said:
> Hi Philip,


> In the current trunk code, as of rev 109,

I've updated to rev 110 to reflect my comments here

> If I comment out 'mapper(Project,Release)' and the Release class, the
> code behaves the same, so how is the Release class meant to be used?

Sorry, It was left incomplete but is now updated.
mapper uses with optional args of classes to map... blank implies map.
mapper will see :

class Project(rdfSubject):
...
releases = rdfMultiple(DOAP.release, range_type=DOAP.Version)
maintainer = rdfSingle(DOAP.maintainer,range_type=FOAF.Person)

and map the return type of the attribute to the class with type
`rdf_type` that matches the descriptors `range_type`

Project.maintainer -> Person() etc

Without mapper, p.releases returns a list of rdfSubject(s)
With mapper, p.releases returns a list of Release(s)

against former, you can call release[DOAP.revision]
against the latter, you can ALSO call release.name

in relational terms, mapper makes the "join" and allows the correct
class to be returned.

>
> print " %s" % release[DOAP['file-release']].resUri

with the mapper you can now say:

print " %s" % release.file_release.resUri

>
> (The sample DOAP you fetch only has one file-release per Version, so
> try a project like 'nut' instead of 'accs')

Thanks, it's in the new doap.py

Think the pastbin is updated too.

--
Phil

cakebread

unread,
Mar 19, 2008, 3:31:58 PM3/19/08
to rdfalchemy-dev
On Mar 19, 12:27 pm, Philip Cooper <philip.coo...@openvest.com> wrote:
> cakebread at about 3/19/08 10:31 AM said:
>
>
> > If I comment out 'mapper(Project,Release)' and the Release class, the
> > code behaves the same, so how is the Release class meant to be used?
>
> Sorry, It was left incomplete but is now updated.
> mapper uses with optional args of classes to map... blank implies map.
> mapper will see :
>
> class Project(rdfSubject):
> ...
> releases = rdfMultiple(DOAP.release, range_type=DOAP.Version)
> maintainer = rdfSingle(DOAP.maintainer,range_type=FOAF.Person)
>
> and map the return type of the attribute to the class with type
> `rdf_type` that matches the descriptors `range_type`
>
> Project.maintainer -> Person() etc
>
> Without mapper, p.releases returns a list of rdfSubject(s)
> With mapper, p.releases returns a list of Release(s)
>
> against former, you can call release[DOAP.revision]
> against the latter, you can ALSO call release.name
>
> in relational terms, mapper makes the "join" and allows the correct
> class to be returned.
>

Okay, that all makes a lot of sense and I've got my code working great
now.

Thanks, Philip!
Reply all
Reply to author
Forward
0 new messages