Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not all triples being exposed with .toNT() and .graphify() #1

Open
awwright opened this issue Dec 24, 2010 · 0 comments
Open

Not all triples being exposed with .toNT() and .graphify() #1

awwright opened this issue Dec 24, 2010 · 0 comments

Comments

@awwright
Copy link

As seen in the current webr3/master c79068c on Node.js v0.3.3-pre 1a894b39b3c622e7c7d228c049e68b65e4334ee5 (with a js3.js file as seen below symlinked to js3.node.js, though it doesn't seem to make a difference), and in Chromium 8.0.552.224 (0)
The .toNT() and the .graphify() functions don't seem to output all of the triples that are present within the structure.

Example code:
require('js3');

var data =
    [ { a: "_:song" }
    , { title: "_:song" }
    , { a: "_:song" }
    ].ref('_:songs');

console.log("\nDATA n3");
console.log(data.n3());
console.log("\nDATA NT");
console.log(data.toNT());
console.log("\nDATA GRAPH");
console.log(data.graphify());

Actual Output:
DATA n3
_:songs 0 [ rdf:type _:song ];
1 [ dc:title _:song ];
2 [ rdf:type _:song ] .

DATA NT
_:songs "0" _:b1 .
_:b1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> _:song .
_:songs "1" _:b2 .
_:songs "2" _:b3 .

(Graphify shows the same thing)

In addition to the actual output, NT should be outputting
_:b2 dc:title _:song .
_:b3 rdf:type _:song .
If the object to those triples is modified, the triple is output. I suspect it has something to do with the index thing the functions use.

Also, shouldn't an Array be parsed as an RDF Container? And adding .toList() before or after .ref(...) only adds the triple
_:songs "list" "true"^^http://www.w3.org/2001/XMLSchema#boolean .
which seems to be wrong, replacing .ref(...) with .toList() makes .toNT() and .graphify() non-functional ("no method 'graphify'"). Clearly these functions need work?

The problem lies on node.js3.js:268 (or rather, source/core.js:36 it looks like) where triple.subject.value and triple.property.value is always the string "function () { return this; }". Replacing with triple.property.toString() as seen below appears to fix the problem, though I'm not sure if avoiding that was deliberate.
add: function(triple) {
if(!this.index[triple.subject.toString()]) this.index[triple.subject.toString()] = {};
if(!this.index[triple.subject.toString()][triple.property.toString()]) this.index[triple.subject.toString()][triple.property.toString()] = [];
if(this.index[triple.subject.toString()][triple.property.toString()].some(function(o){return o.equals(triple.object)})) return;
this.length++;
this.index[triple.subject.toString()][triple.property.toString()].push(triple.object);
this.graph.push(triple);
},
Actually, .toString(), .value(), and removing .value entirely all seem to work equally as well. Since .value() just returns this I'll will be taking it out entirely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant