Skip to content

Commit

Permalink
Attempt to have native trig support for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
phochste committed Oct 3, 2024
1 parent 8736619 commit 271b553
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 3 deletions.
29 changes: 27 additions & 2 deletions bin/make_examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
const { performance } = require('perf_hooks');
const path = require('path');
const fs = require('fs');
const { error } = require('console');
const { runner } = require('../lib/process');
const { IS_OK , IS_INCOMPLETE , IS_TIMEOUT , IS_LIE , IS_SKIPPED , IS_CRASHED } = require('../lib/errors');

const RED = "\x1b[31m";
Expand Down Expand Up @@ -159,6 +159,8 @@ async function run_tests_one(reasoner,filePath) {
let ok = 0, incomplete= 0, timeout = 0, lie = 0, skipped = 0 , other = 0;
let type = undefined;

const testPath = await test_rewriter(filePath);

if (filePath.match(/_SKIP/)) {
type = `skip`;
}
Expand All @@ -177,7 +179,7 @@ async function run_tests_one(reasoner,filePath) {

try {
config.type = type;
answer = await reasoner(filePath,config);
answer = await reasoner(testPath,config);
}
catch(e) {
console.error(e);
Expand Down Expand Up @@ -209,6 +211,11 @@ async function run_tests_one(reasoner,filePath) {
console.log(`Testing ${filePath} ... OTHER`);
}

if (testPath !== filePath) {
fs.unlinkSync(testPath);
fs.unlinkSync(`${testPath}.out`);
}

return [ ok , incomplete , timeout , lie , skipped , other ];
}

Expand All @@ -230,3 +237,21 @@ function load_library(lib) {
return null;
}
}

async function test_rewriter(filePath) {
if (filePath.endsWith(".n3s")) {
return filePath;
}
else if (filePath.endsWith(".trig")) {
// TODO this is not working yet
const result =
await runner(`eye --quiet --nope --pass --trig ${filePath} lib/gsm.n3`,{
quiet: true
});
fs.writeFileSync("tmp.n3s",result, { encoding: 'utf-8' } );
return 'tmp.n3s';
}
else {
return filePath;
}
}
41 changes: 41 additions & 0 deletions lib/gsm.n3
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# -------------------------------------------
# Graph Statement Machine - GSM -- Jos De Roo
# -------------------------------------------

@prefix graph: <http://www.w3.org/2000/10/swap/graph#>.
@prefix log: <http://www.w3.org/2000/10/swap/log#>.

# create forward rules
{
?A log:implies ?B.
?A graph:statement ?C.
?B graph:statement ?D.
} => {
?C => ?D.
}.

# create backward rules
{
?A log:isImpliedBy ?B.
?A graph:statement ?C.
?B graph:statement ?D.
} => {
?C <= ?D.
}.

# create queries
{
?A log:query ?B.
?A graph:statement ?C.
?B graph:statement ?D.
} => {
?C =^ ?D.
}.

# create rdfsurfaces
{
?A log:onNegativeSurface ?B.
?B graph:statement ?C.
} => {
?A log:onNegativeSurface ?C.
}.
7 changes: 6 additions & 1 deletion lib/process.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ async function runner(command,options) {
});

proc.on('exit', (code, signal) => {
fs.writeFileSync(`${filePath}.out`,output, { encoding: 'utf-8'});
if (options.quiet) {
// don't print output;
}
else {
fs.writeFileSync(`${filePath}.out`,output, { encoding: 'utf-8'});
}
if (signal === 'SIGTERM') {
resolve(null);
}
Expand Down

0 comments on commit 271b553

Please sign in to comment.