What steps will reproduce the problem?
1. using jquery.rdfquery.rules-1.0.js
2. Here is my test code that demonstrates the problem:
console.log("This will test a problem with databank.describe on a union databank");
var t1 = "<http://example.org/#ex1> a <http://example.org/#Example>";
var t2 = "<http://example.org/#ex2> a <http://example.org/#Example>";
var subjects = '';
var graph1 = $.rdf().add(t1);
graph1.where('?s a ?o').each(function(i) { subjects += this.s.toString()});
console.log("graph1 subjects: "+subjects);
subjects = '';
var graph2 = $.rdf().add(t2);
graph2.where('?s a ?o').each(function(i) { subjects += this.s.toString()});
console.log("graph2 subjects: "+subjects);
subjects = '';
// graph3 will be a union graph
var graph3 = $.rdf().add(graph1).add(graph2);
var g3subjects = '';
graph3.where('?s a ?o').each(function(i) { g3subjects += this.s.toString()});
console.log("graph3 subjects: "+g3subjects);
console.log("graph3.describe will FAIL with the rdfquery 1.0");
graph3.where('?s a ?o').describe(['?s']).forEach(function(v,i,a) { console.log(v.toString())});
Instead of triples I get:
[TypeError: Cannot read property '<http://example.org/#ex1>' of undefined]
I apologize that I can't give a proper patch because I've made a few minor
changes around the lib to make it node.js compatible, however, I fixed my
working version by modifying the databank.describe() function like this:
describe: function (resources) {
var i, r, t, rhash = {}, triples = [];
while (resources.length > 0) {
r = resources.pop();
if (rhash[r] === undefined) {
if (r.value === undefined) {
r = $.rdf.resource(r);
}
if (this.union !== undefined) {
this.union.forEach(function(v,i,a){
eachDatabank.call(v);
});
}
else {
eachDatabank.call(this);
}
function eachDatabank() {
if (this.tripleStore[r] !== undefined) {
for (i = 0; i < this.tripleStore[r].length; i += 1) {
t = this.tripleStore[r][i];
triples.push(t);
if (t.object.type === 'bnode') {
resources.push(t.object);
}
}
}
if (this.objectStore[r] !== undefined) {
for (i = 0; i < this.objectStore[r].length; i += 1) {
t = this.objectStore[r][i];
triples.push(t);
if (t.subject.type === 'bnode') {
resources.push(t.subject);
}
}
}
};
rhash[r] = true;
}
}
return $.unique(triples);
},
Original issue reported on code.google.com by anderson...@gmail.com on 6 Jan 2012 at 9:39
Original issue reported on code.google.com by
anderson...@gmail.com
on 6 Jan 2012 at 9:39