Skip to content

Commit

Permalink
changed way of storing literals to match latest N3.js attr: @RubenVer…
Browse files Browse the repository at this point in the history
  • Loading branch information
elf Pavlik committed Nov 17, 2014
1 parent e703d83 commit 8508bb4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 25 deletions.
6 changes: 1 addition & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function levelgraphJSONLD(db, jsonldOpts) {
if(triple.object.datatype === 'http://www.w3.org/2001/XMLSchema#string'){
node.value = '"' + triple.object.value + '"';
} else {
node.value = '"' + triple.object.value + '"^^<' + triple.object.datatype + '>';
node.value = '"' + triple.object.value + '"^^' + triple.object.datatype + '';

This comment has been minimized.

Copy link
@RubenVerborgh

RubenVerborgh Nov 18, 2014

You can remove that + '' at the end 😉

This comment has been minimized.

This comment has been minimized.

Copy link
@RubenVerborgh

RubenVerborgh Nov 18, 2014

😄

}
} else if(triple.object.datatype.match(RDFLANGSTRING)){
node.value = '"' + triple.object.value + '"@' + triple.object.language;
Expand Down Expand Up @@ -137,10 +137,6 @@ function levelgraphJSONLD(db, jsonldOpts) {
};
var value = N3Util.getLiteralValue(object);
var type = N3Util.getLiteralType(object);
// get type URI without <>
if(type !== TYPES.STRING && type !== RDFLANGSTRING) {
type = type.slice(1,-1);
}
var coerced = {};
switch (type) {
case TYPES.STRING:
Expand Down
38 changes: 19 additions & 19 deletions test/datatype_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('jsonld.put data type', function() {
db.get({
predicate: 'http://schema.org/isFamilyFriendly'
}, function(err, triples) {
expect(triples[0].object).to.equal('"true"^^<http://www.w3.org/2001/XMLSchema#boolean>');
expect(triples[0].object).to.equal('"true"^^http://www.w3.org/2001/XMLSchema#boolean');
done();
});
});
Expand All @@ -31,7 +31,7 @@ describe('jsonld.put data type', function() {
db.get({
predicate: 'http://schema.org/isFamilyFriendly'
}, function(err, triples) {
expect(triples[0].object).to.equal('"false"^^<http://www.w3.org/2001/XMLSchema#boolean>');
expect(triples[0].object).to.equal('"false"^^http://www.w3.org/2001/XMLSchema#boolean');
done();
});
});
Expand All @@ -43,7 +43,7 @@ describe('jsonld.put data type', function() {
db.get({
predicate: 'http://schema.org/version'
}, function(err, triples) {
expect(triples[0].object).to.equal('"2"^^<http://www.w3.org/2001/XMLSchema#integer>');
expect(triples[0].object).to.equal('"2"^^http://www.w3.org/2001/XMLSchema#integer');
done();
});
});
Expand All @@ -55,7 +55,7 @@ describe('jsonld.put data type', function() {
db.get({
predicate: 'http://schema.org/version'
}, function(err, triples) {
expect(triples[0].object).to.equal('"-2"^^<http://www.w3.org/2001/XMLSchema#integer>');
expect(triples[0].object).to.equal('"-2"^^http://www.w3.org/2001/XMLSchema#integer');
done();
});
});
Expand All @@ -67,7 +67,7 @@ describe('jsonld.put data type', function() {
db.get({
predicate: 'http://schema.org/version'
}, function(err, triples) {
expect(triples[0].object).to.equal('"0"^^<http://www.w3.org/2001/XMLSchema#integer>');
expect(triples[0].object).to.equal('"0"^^http://www.w3.org/2001/XMLSchema#integer');
done();
});
});
Expand All @@ -79,7 +79,7 @@ describe('jsonld.put data type', function() {
db.get({
predicate: 'http://schema.org/version'
}, function(err, triples) {
expect(triples[0].object).to.equal('"1.2345E1"^^<http://www.w3.org/2001/XMLSchema#double>');
expect(triples[0].object).to.equal('"1.2345E1"^^http://www.w3.org/2001/XMLSchema#double');
done();
});
});
Expand All @@ -91,7 +91,7 @@ describe('jsonld.put data type', function() {
db.get({
predicate: 'http://schema.org/version'
}, function(err, triples) {
expect(triples[0].object).to.equal('"-1.2345E1"^^<http://www.w3.org/2001/XMLSchema#double>');
expect(triples[0].object).to.equal('"-1.2345E1"^^http://www.w3.org/2001/XMLSchema#double');
done();
});
});
Expand Down Expand Up @@ -123,7 +123,7 @@ describe('jsonld.put data type', function() {
db.get({
predicate: 'http://schema.org/startTime'
}, function(err, triples) {
expect(triples[0].object).to.equal('"2014-01-28T12:27:54"^^<http://www.w3.org/2001/XMLSchema#dateTime>');
expect(triples[0].object).to.equal('"2014-01-28T12:27:54"^^http://www.w3.org/2001/XMLSchema#dateTime');
done();
});

Expand All @@ -146,7 +146,7 @@ describe('jsonld.put data type', function() {
db.get({
predicate: 'http://schema.org/startTime'
}, function(err, triples) {
expect(triples[0].object).to.equal('"2014-01-28T12:27:54"^^<http://www.w3.org/2001/XMLSchema#dateTime>');
expect(triples[0].object).to.equal('"2014-01-28T12:27:54"^^http://www.w3.org/2001/XMLSchema#dateTime');
done();
});

Expand All @@ -172,7 +172,7 @@ describe('jsonld.get data type', function() {

it('preserves boolean true', function(done) {
triple.predicate = 'http://schema.org/isFamilyFriendly';
triple.object = '"true"^^<http://www.w3.org/2001/XMLSchema#boolean>';
triple.object = '"true"^^http://www.w3.org/2001/XMLSchema#boolean';

db.jsonld.put(bbb, function() {
db.put(triple, function() {
Expand All @@ -186,7 +186,7 @@ describe('jsonld.get data type', function() {

it('preserves boolean false', function(done) {
triple.predicate = 'http://schema.org/isFamilyFriendly';
triple.object = '"false"^^<http://www.w3.org/2001/XMLSchema#boolean>';
triple.object = '"false"^^http://www.w3.org/2001/XMLSchema#boolean';

db.jsonld.put(bbb, function() {
db.put(triple, function() {
Expand All @@ -200,7 +200,7 @@ describe('jsonld.get data type', function() {

it('preserves integer positive', function(done) {
triple.predicate = 'http://schema.org/version';
triple.object = '"2"^^<http://www.w3.org/2001/XMLSchema#integer>';
triple.object = '"2"^^http://www.w3.org/2001/XMLSchema#integer';

db.jsonld.put(bbb, function() {
db.put(triple, function() {
Expand All @@ -214,7 +214,7 @@ describe('jsonld.get data type', function() {

it('preserves integer negative', function(done) {
triple.predicate = 'http://schema.org/version';
triple.object = '"-2"^^<http://www.w3.org/2001/XMLSchema#integer>';
triple.object = '"-2"^^http://www.w3.org/2001/XMLSchema#integer';

db.jsonld.put(bbb, function() {
db.put(triple, function() {
Expand All @@ -228,7 +228,7 @@ describe('jsonld.get data type', function() {

it('preserves integer zero', function(done) {
triple.predicate = 'http://schema.org/version';
triple.object = '"0"^^<http://www.w3.org/2001/XMLSchema#integer>';
triple.object = '"0"^^http://www.w3.org/2001/XMLSchema#integer';

db.jsonld.put(bbb, function() {
db.put(triple, function() {
Expand All @@ -242,7 +242,7 @@ describe('jsonld.get data type', function() {

it('preserves double positive', function(done) {
triple.predicate = 'http://schema.org/version';
triple.object = '"1.2345E1"^^<http://www.w3.org/2001/XMLSchema#double>';
triple.object = '"1.2345E1"^^http://www.w3.org/2001/XMLSchema#double';

db.jsonld.put(bbb, function() {
db.put(triple, function() {
Expand All @@ -256,7 +256,7 @@ describe('jsonld.get data type', function() {

it('preserves double negative', function(done) {
triple.predicate = 'http://schema.org/version';
triple.object = '"-1.2345E1"^^<http://www.w3.org/2001/XMLSchema#double>';
triple.object = '"-1.2345E1"^^http://www.w3.org/2001/XMLSchema#double';

db.jsonld.put(bbb, function() {
db.put(triple, function() {
Expand All @@ -270,7 +270,7 @@ describe('jsonld.get data type', function() {

it('does not preserve string', function(done) {
triple.predicate = 'http://schema.org/contentRating';
triple.object = '"MPAA PG-13"^^<http://www.w3.org/2001/XMLSchema#string>';
triple.object = '"MPAA PG-13"^^http://www.w3.org/2001/XMLSchema#string';

db.jsonld.put(bbb, function() {
db.put(triple, function() {
Expand All @@ -293,7 +293,7 @@ describe('jsonld.get data type', function() {
var triple = {
subject: example['@id'],
predicate: 'http://schema.org/startTime',
object: '"2014-01-28T12:27:54"^^<http://www.w3.org/2001/XMLSchema#dateTime>'
object: '"2014-01-28T12:27:54"^^http://www.w3.org/2001/XMLSchema#dateTime'
};
db.jsonld.put(example, function() {
db.put(triple, function() {
Expand All @@ -318,7 +318,7 @@ describe('jsonld.get data type', function() {
var triple = {
subject: example['@id'],
predicate: 'http://schema.org/startTime',
object: '"2014-01-28T12:27:54"^^<http://www.w3.org/2001/XMLSchema#dateTime>'
object: '"2014-01-28T12:27:54"^^http://www.w3.org/2001/XMLSchema#dateTime'
};
db.jsonld.put(example, function() {
db.put(triple, function() {
Expand Down
2 changes: 1 addition & 1 deletion test/put_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ describe('jsonld.put', function() {
db.get({
subject: 'http://manu.sporny.org#person',
predicate: 'http://xmlns.com/foaf/0.1/age',
object: '"42"^^<http://www.w3.org/2001/XMLSchema#integer>'
object: '"42"^^http://www.w3.org/2001/XMLSchema#integer'
}, function(err, triples) {
expect(triples).to.have.length(1);
done();
Expand Down

0 comments on commit 8508bb4

Please sign in to comment.