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

RDFC-1.0 rename. #80

Merged
merged 3 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
If `maxDeepIterations` is provided, then `maxWorkFactor` will be ignored.
- **BREAKING**: Check output `format` parameter. Must be omitted, falsy, or
"application/n-quads".
- Add EARL Turtle test result mode.

### Changed
- **BREAKING**: Change algorithm name from "URDNA2015" to "RDFC-1.0" to match
Expand Down
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,21 +189,27 @@ directory you can use the following:

npm run fetch-test-suite

Node.js tests can be run with a simple command:
Node.js tests:

npm test

Browser tests via Karma:

npm run test-karma

If you installed the test suites elsewhere, or wish to run other tests, use
the `TEST_DIR` environment var:

TEST_DIR="/tmp/tests" npm test

To generate earl reports:
To generate EARL reports:

# generate the earl report for node.js
# generate a JSON-LD EARL report with Node.js
EARL=earl-node.jsonld npm test

Browser testing with karma is done indirectly through [jsonld.js][].
# generate a Turtle EARL report with Node.js
# used for official reports
EARL=js-rdf-canonize-earl.ttl npm test

Benchmark
---------
Expand Down
2 changes: 1 addition & 1 deletion lib/URDNA2015.js → lib/RDFC10.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const Permuter = require('./Permuter');
const NQuads = require('./NQuads');
const {setImmediate} = require('./platform');

module.exports = class URDNA2015 {
module.exports = class RDFC10 {
constructor({
createMessageDigest = null,
messageDigestAlgorithm = 'sha256',
Expand Down
2 changes: 1 addition & 1 deletion lib/URDNA2015Sync.js → lib/RDFC10Sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const MessageDigest = require('./MessageDigest');
const Permuter = require('./Permuter');
const NQuads = require('./NQuads');

module.exports = class URDNA2015Sync {
module.exports = class RDFC10Sync {
constructor({
createMessageDigest = null,
messageDigestAlgorithm = 'sha256',
Expand Down
12 changes: 6 additions & 6 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
*/
'use strict';

const URDNA2015 = require('./URDNA2015');
const URDNA2015Sync = require('./URDNA2015Sync');
const RDFC10 = require('./RDFC10');
const RDFC10Sync = require('./RDFC10Sync');

// optional native support
let rdfCanonizeNative;
Expand Down Expand Up @@ -165,12 +165,12 @@ exports.canonize = async function(input, options = {}) {
throw new Error('No RDF Dataset Canonicalization algorithm specified.');
}
if(options.algorithm === 'RDFC-1.0') {
return new URDNA2015(options).main(dataset);
return new RDFC10(options).main(dataset);
}
// URDNA2015 deprecated, handled as alias for RDFC-1.0 if allowed
if(options.algorithm === 'URDNA2015' && !options.rejectURDNA2015) {
_traceURDNA2015();
return new URDNA2015(options).main(dataset);
return new RDFC10(options).main(dataset);
}
throw new Error(
'Invalid RDF Dataset Canonicalization algorithm: ' + options.algorithm);
Expand Down Expand Up @@ -250,12 +250,12 @@ exports._canonizeSync = function(input, options = {}) {
throw new Error('No RDF Dataset Canonicalization algorithm specified.');
}
if(options.algorithm === 'RDFC-1.0') {
return new URDNA2015Sync(options).main(dataset);
return new RDFC10Sync(options).main(dataset);
}
// URDNA2015 deprecated, handled as alias for RDFC-1.0 if allowed
if(options.algorithm === 'URDNA2015' && !options.rejectURDNA2015) {
_traceURDNA2015();
return new URDNA2015Sync(options).main(dataset);
return new RDFC10Sync(options).main(dataset);
}
throw new Error(
'Invalid RDF Dataset Canonicalization algorithm: ' + options.algorithm);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "rdf-canonize",
"version": "3.4.1-0",
"description": "An implementation of the RDF Dataset Normalization Algorithm in JavaScript",
"description": "An implementation of the RDF Dataset Canonicalization algorithm in JavaScript",
"homepage": "https://github.com/digitalbazaar/rdf-canonize",
"author": {
"name": "Digital Bazaar, Inc.",
Expand Down
80 changes: 75 additions & 5 deletions test/EarlReport.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ class EarlReport {
this.now = new Date();
this.now.setMilliseconds(0);
this.env = options.env;
this.format = options.format;
this.version = options.version;
// test environment
this._environment = null;
/* eslint-disable quote-props */
Expand Down Expand Up @@ -104,7 +106,8 @@ class EarlReport {
'doap:homepage': 'https://github.com/digitalbazaar/rdf-canonize',
'doap:license':
'https://github.com/digitalbazaar/rdf-canonize/blob/master/LICENSE',
'doap:description': 'A JSON-LD processor for JavaScript',
'doap:description':
'A RDF Dataset Canonicalization processor for JavaScript',
'doap:programming-language': 'JavaScript',
'dc:creator': 'https://digitalbazaar.com/',
'doap:developer': {
Expand All @@ -117,7 +120,7 @@ class EarlReport {
'foaf:homepage': 'https://digitalbazaar.com/'
},
'doap:release': {
'doap:revision': '',
'doap:revision': `${this.version}`,
'doap:created': today
},
'subjectOf': []
Expand Down Expand Up @@ -154,11 +157,78 @@ class EarlReport {
}

report() {
return this._report;
if(this.format === 'json') {
return JSON.stringify(this._report, null, 2);
} else if(this.format === 'ttl') {
return this.asTurtle(this._report);
} else {
throw new Error(`Unknown report format: "${this.format}".`);
}
}

reportJson() {
return JSON.stringify(this._report, null, 2);
asTurtle() {
console.log(this._report);
console.log(this._report.subjectOf[0]);
const r = this._report;
let report = '';
// add prefixes
report += `\
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix dc: <http://purl.org/dc/terms/> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix doap: <http://usefulinc.com/ns/doap#> .
@prefix earl: <http://www.w3.org/ns/earl#> .
@prefix ex: <http://example.org/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

`;

// add test subject
report += `\
<> foaf:primaryTopic <${r['@id']}> ;
dc:issued "${r['doap:release']['doap:created']}"^^xsd:dateTime ;
foaf:maker <${r['doap:developer']['@id']}> .

<${r['@id']}> a doap:Project, earl:TestSubject, earl:Software ;
doap:name "${r['doap:name']}" ;
doap:release [
doap:name "${r['doap:name']}@${r['doap:release']['doap:revision']}";
doap:revision "${r['doap:release']['doap:revision']}" ;
doap:created "${r['doap:release']['doap:created']}" ;
] ;
doap:developer <${r['doap:developer']['@id']}> ;
doap:homepage <${r['doap:homepage']}> ;
doap:description "${r['doap:description']}"@en ;
doap:programming-language "${r['doap:programming-language']}" .

`;

// add software developer
report += `\
<${r['doap:developer']['@id']}> a foaf:Organization, earl:Assertor;
foaf:name "${r['doap:developer']['foaf:name']}";
foaf:homepage <${r['doap:developer']['foaf:homepage']}>;

`;

// add assertions
for(const a of r.subjectOf) {
report += `\
[ a earl:Assertion;
earl:assertedBy <${r['doap:developer']['@id']}>;
earl:subject <${r['@id']}>;
earl:test <https://w3c.github.io/rdf-canon/tests/${a['earl:test']}>;
earl:result [
a earl:TestResult;
earl:outcome ${a['earl:result']['earl:outcome']};
dc:date "${a['earl:result']['dc:date']}"^^xsd:dateTime];
earl:mode ${a['earl:mode']} ] .

`;
}

return report;
}

// setup @context and environment to handle benchmark data
Expand Down
10 changes: 7 additions & 3 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
* Set dirs, manifests, or js to run:
* TESTS="r1 r2 ..."
* Output an EARL report:
* EARL=filename
* EARL=filename (default: none)
* JSON or Turtle type determined by extension.
* Test environment details for EARL report:
* This is useful for benchmark comparison.
* By default no details are added for privacy reasons.
Expand Down Expand Up @@ -235,7 +236,10 @@ if(options.env.TEST_ENV) {
// create earl report
if(options.earl && options.earl.filename) {
options.earl.report = new EarlReport({
env: testEnv
env: testEnv,
format: options.earl.filename.endsWith('.ttl') ? 'ttl' : 'json',
// FIXME: enable easier override
version: options.testEnvDefaults.version
});
if(benchmarkOptions.enabled) {
options.earl.report.setupForBenchmarks({testEnv});
Expand All @@ -259,7 +263,7 @@ if(options.earl.report) {
const _it = result.hadOnly ? it.only : it;
_it('should print the earl report', function() {
return options.writeFile(
options.earl.filename, options.earl.report.reportJson());
options.earl.filename, options.earl.report.report());
});
});
}
Expand Down