webr3 / js3

An insane integration of RDF in to ECMAScript-262 V5 (Javascript)
114 stars 9 forks source link

How do you handle namespace collisions? #4

Open ghost opened 4 years ago

ghost commented 4 years ago

Impressive project, but the main reason we use a parser instead because different vocabs/namespaces can use the same names and they can collide.

You could have used a simple object with the properties you generate from the RDF vocab. Another, maybe a little faster solution is using a unique id or a Symbol for property name and adding a Symbol - URI map.

var foaf = {
    age: "http://xmlns.com/foaf/0.1/age"
};
var o = {};
o[foaf.age] = 12;
console.log(o[foaf.age]);

I am thinking on something similar, but I guess something more advanced than your lib. I'd like to generate JS prototypes from RDFs classes and vice-versa. It is just something that requires a lot of work if you want to do it properly. For example I'll need to write a validator that understands OWL and XSD. A lot of ppl worked on this kind of projects in the last 10 years, now we have RDF parsers and even a new JSON based format called JSON-LD, so there is definitely some progress.