Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function test_doc_utility() {
const N3Util = N3.Util;
N3Util.isNamedNode(N3.DataFactory.namedNode('http://example.org/cartoons#Mickey')); // true
N3Util.isLiteral(N3.DataFactory.literal('Mickey Mouse')); // true
N3Util.isLiteral(N3.DataFactory.literal('Mickey Mouse', 'en')); // true
N3Util.isLiteral(N3.DataFactory.literal('3', N3.DataFactory.namedNode('http://www.w3.org/2001/XMLSchema#integer'))); // true
N3Util.isLiteral(N3.DataFactory.literal('http://example.org/')); // true
N3Util.isLiteral(N3.DataFactory.literal('This word is "quoted"!')); // true
N3Util.isLiteral(N3.DataFactory.literal('3', N3.DataFactory.namedNode('http://www.w3.org/2001/XMLSchema#integer'))); // true
new N3.Parser().parse('<a> <b> "This word is \\"quoted\\"!".', console.log);
// { subject: 'a', predicate: 'b', object: '"This word is "quoted"!"' }
N3Util.isBlankNode(N3.DataFactory.blankNode('b1')); // true
N3Util.isNamedNode(N3.DataFactory.blankNode('b1')); // false
N3Util.isLiteral(N3.DataFactory.blankNode('b1')); // false
</b></a>
/* eslint-disable no-await-in-loop */
import { promisify } from 'util';
import moment from 'moment';
import N3 from 'n3';
import PgCursor from 'pg-cursor';
import pgFormat from 'pg-format';
import noop from 'lodash/noop';
import config from 'config'
const { literal, namedNode, quad } = N3.DataFactory;
const schema = 'http://schema.org/';
const frf = 'http://freefeed.net/';
const rdfs = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#';
export const prefixes = { schema, rdfs };
const schemaType = (id, typeName) => quad(
namedNode(id),
namedNode(`${rdfs}type`),
namedNode(`${schema}${typeName}`)
);
const intToIso = (timestamp) => moment(parseInt(timestamp)).format();
const fixIso = (badIsoTimestamp) => moment(badIsoTimestamp).format();
function test_doc_from_triples_to_string() {
const writer: N3.N3Writer = new N3.Writer({ prefixes: { c: 'http://example.org/cartoons#' } });
writer.addQuad(N3.DataFactory.quad(
N3.DataFactory.namedNode('http://example.org/cartoons#Tom'),
N3.DataFactory.namedNode('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'),
N3.DataFactory.namedNode('http://example.org/cartoons#Cat')
));
writer.addQuad(N3.DataFactory.quad(
N3.DataFactory.namedNode('http://example.org/cartoons#Tom'),
N3.DataFactory.namedNode('http://example.org/cartoons#name'),
N3.DataFactory.literal('Tom'),
));
writer.end((error, result: string) => { console.log(result); });
const writer1: N3.N3Writer = N3.Writer({ format: 'N-Triples' });
const writer2: N3.N3Writer = N3.Writer({ format: 'application/trig' });
}
'use strict';
const _ = require('../lib/lodash');
const utils = require('../lib/utils');
const should = require('should');
const factory = require('n3').DataFactory;
module.exports = () => {
describe('RdfStore.prototype.del()', () => {
it('Should delete matching quads correctly (callback).', async function () {
const store = this.store;
const quads = [
factory.quad(
factory.namedNode('http://ex.com/s0'),
factory.namedNode('http://ex.com/p0'),
factory.literal('o0', 'en-gb'),
factory.namedNode('http://ex.com/g0')
),
factory.quad(
factory.namedNode('http://ex.com/s0'),
'use strict';
const _ = require('../lib/lodash');
const utils = require('../lib/utils');
const should = require('should');
const factory = require('n3').DataFactory;
module.exports = () => {
describe('RdfStore.prototype.remove()', () => {
it('should remove streamed quads correctly', async function () {
const store = this.store;
const importQuads = [
factory.quad(
factory.namedNode('http://ex.com/s0'),
factory.namedNode('http://ex.com/p0'),
factory.literal('o0', 'en-gb'),
factory.namedNode('http://ex.com/g0')
),
factory.quad(
factory.namedNode('http://ex.com/s1'),
'use strict';
const n3 = require('n3');
const url = require('url');
const should = require('should');
const testUtils = require('./utils');
const { namedNode, literal, defaultGraph, quad } = n3.DataFactory;
const { get, getQuads, postQuads, serializeQuads, deserializerQuads } = testUtils;
module.exports = () => {
describe('RdfStore\'s HTTP endpoints', () => {
describe('RdfStore\'s RDF/JS-equivalent HTTP endpoints', () => {
it('Should import, match and remove quads correctly', async function () {
const store = this.store;
const quads = [
quad(namedNode('ex://s0'), namedNode('ex://p0'), namedNode('ex://o0'), namedNode('ex://g0')),
quad(namedNode('ex://s1'), namedNode('ex://p1'), namedNode('ex://o1'), namedNode('ex://g1')),
quad(namedNode('ex://s2'), namedNode('ex://p2'), namedNode('ex://o2'), namedNode('ex://g2')),
];
await postQuads(`${store._httpBaseUrl}/import`, quads);
'use strict';
const _ = require('../lib/lodash');
const utils = require('../lib/utils');
const should = require('should');
const factory = require('n3').DataFactory;
module.exports = () => {
describe('RdfStore.prototype.import()', () => {
it('should import a single quad correctly', async function () {
const store = this.store;
const quads = [
factory.quad(
factory.namedNode('http://ex.com/s'),
factory.namedNode('http://ex.com/p'),
factory.literal('o', 'en-gb'),
factory.namedNode('http://ex.com/g')
)
];
const source = utils.createArrayStream(quads);
'use strict';
const _ = require('lodash');
const utils = require('../lib/utils');
const should = require('should');
const dataFactory = require('n3').DataFactory;
module.exports = () => {
describe('RdfStore.prototype.sparql()', () => {
it('Shoud return the correct number of entries', async function () {
const ctx = this;
const store = ctx.store;
const quads = [];
for (let i = 0; i < 20; i++) {
quads.push(dataFactory.quad(
dataFactory.namedNode('http://ex.com/s' + i),
dataFactory.namedNode('http://ex.com/p' + i),
dataFactory.namedNode('http://ex.com/o' + i),
dataFactory.namedNode('http://ex.com/g' + i)
));
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
store = new n3_1.Store();
store.addQuad(n3_1.DataFactory.quad(n3_1.DataFactory.namedNode('a'), n3_1.DataFactory.namedNode('b'), n3_1.DataFactory.namedNode('http://dbpedia.org/resource/Belgium')));
store.addQuad(n3_1.DataFactory.quad(n3_1.DataFactory.namedNode('a'), n3_1.DataFactory.namedNode('b'), n3_1.DataFactory.namedNode('http://dbpedia.org/resource/Ghent')));
myEngine = actor_init_sparql_rdfjs_1.newEngine();
return [4 /*yield*/, myEngine.query('SELECT * { ?s ?p . ?s ?p ?o } LIMIT 100', { sources: [{ type: 'rdfjsSource', value: store }] })];
case 1:
result = _a.sent();
result.bindingsStream.on('data', function (data) {
console.log(data);
});
return [2 /*return*/];
}
});
});
'use strict';
const n3 = require('n3');
const fs = require('fs-extra');
const os = require('os');
const path = require('path');
const utils = require('../lib/utils');
const Promise = require('bluebird');
const shortid = require('shortid');
const RdfStore = require('..').RdfStore;
const leveldown = require('leveldown');
const dataFactory = require('n3').DataFactory;
const childProcess = require('child_process');
function du(absPath) {
return new Promise((resolve, reject) => {
childProcess.exec(`du -sm ${absPath}`, (err, stdout) => {
if (err) reject(err);
else resolve(`${stdout.split(/\s+/)[0]} MB`);
});
});
}
const remove = Promise.promisify(fs.remove, { context: 'fs' });
(async () => {
const args = process.argv.slice(2);