Storing/Retrieving RDF URIs

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Storing/Retrieving RDF URIs

"neil.stansbury () redbacksystems ! com"
Hi all,

I am in dire need of an elegant solution storing & retrieving
potentially hundreds of RDF reference URIs. I started out with constants
in my code but this is really starting to get unwieldy and unmanageable.

What I really need is some form of dynamically loadable lookup/hash
table that I can get the correct URI from but without resorting to loads
of keys declared as constants.

One potential way I can see would be to load the RDF schemas themselves
into a datasource, which has the advantage of them being dynamic but
doesn't really help me retrieve them.

The only solution I can come up with is as a class of getters but again
makes it difficult to overload the base class, something like:

dcTable = New DublinCoreTable()
uri = dcTable.getTitle()


Just wondered if anyone else has crossed and solved this problem?

Cheers,

Neil
_______________________________________________
dev-tech-rdf mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-rdf
Reply | Threaded
Open this post in threaded view
|

Re: Storing/Retrieving RDF URIs

Axel Hecht-2
neil.stansbury () redbacksystems ! com wrote:

> Hi all,
>
> I am in dire need of an elegant solution storing & retrieving
> potentially hundreds of RDF reference URIs. I started out with constants
> in my code but this is really starting to get unwieldy and unmanageable.
>
> What I really need is some form of dynamically loadable lookup/hash
> table that I can get the correct URI from but without resorting to loads
> of keys declared as constants.
>
> One potential way I can see would be to load the RDF schemas themselves
> into a datasource, which has the advantage of them being dynamic but
> doesn't really help me retrieve them.
>
> The only solution I can come up with is as a class of getters but again
> makes it difficult to overload the base class, something like:
>
> dcTable = New DublinCoreTable()
> uri = dcTable.getTitle()
>
>
> Just wondered if anyone else has crossed and solved this problem?
>

Something like

var dc =
   new Vocabulary("http://purl.org/dc/elements/1.1/",
                  ['title', 'creator', 'subject', 'description',
                   'publisher', 'contributor', 'date', 'type', 'format',
                   'identifier', 'source', 'language', 'relation',
'coverage',
                   'rights']);


with

function Vocabulary(basepath, leafs) {
   for each (leaf in leafs) {
     this[leaf] = RDFS.GetResource(basepath + leaf);
   };
   this.__contains__ = function(url) {
     var bpl = basepath.length;
     if (url.substr(0, bpl) != basepath) {
       return false;
     }
     return url.substr(bpl) in this;
   };
   this.toString = function() {
     return basepath;
   };
};
Vocabulary.prototype = {};


might do the trick for you.

There isn't a lot to improve here, sadly. Parsing schemas fails badly,
because the Mozilla RDF/XML parser is broken on xml:base, and using js
magic fails as regular js doesn't have default lookup hooks. You could
write one in C++, but that seemed overkill to me. I hope js2 will have
those hooks, really.

You could use __defineGetter__, too, if you want to be dead sure about
the const'ness.

Axel
_______________________________________________
dev-tech-rdf mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-rdf
Reply | Threaded
Open this post in threaded view
|

Re: Storing/Retrieving RDF URIs

"neil.stansbury () redbacksystems ! com"
Axel Hecht wrote:

>
> Something like
>
> var dc =
>   new Vocabulary("http://purl.org/dc/elements/1.1/",
>                  ['title', 'creator', 'subject', 'description',
>                   'publisher', 'contributor', 'date', 'type', 'format',
>                   'identifier', 'source', 'language', 'relation',
> 'coverage',
>                   'rights']);
>
>
> with
>
> function Vocabulary(basepath, leafs) {
>   for each (leaf in leafs) {
>     this[leaf] = RDFS.GetResource(basepath + leaf);
>   };
>   this.__contains__ = function(url) {
>     var bpl = basepath.length;
>     if (url.substr(0, bpl) != basepath) {
>       return false;
>     }
>     return url.substr(bpl) in this;
>   };
>   this.toString = function() {
>     return basepath;
>   };
> };
> Vocabulary.prototype = {};


Oh cool, cheers Axel and now I can access it directly as 'dc.title',
that's slick - perfect thanks!


Neil
_______________________________________________
dev-tech-rdf mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-rdf