Is it possible to use a variable when making a call to
n10s.rdf.import.fetch(, 'Turtle')?
As can be seen from the code below, hard-coding the absolute path into the call
works perfectly. Problem is I want to load a number of rdf files into the same graph.
The call is the same except for the filename. Writing a new function for every different rdf file
is not really workable. Moving the project to another directory would require rewriting all
the hard coded calls, again not really workable.
The problem is in the line
"call n10s.rdf.import.fetch(${param}
, 'Turtle');
${param}
is not defined
everywhere else it is defined and evaluates to the expected string
// This is usingParam.js
// how to get n10s to work with a parameter
const loadFromFileMajorMap = ( session, filename ) =>
{
let directoryPath = path.join( __dirname, '../rdf_src');
directoryPath = directoryPath.replaceAll('\', '\\\\');
let param = "";
// first check that the file name ends in .ttl
if( filename.endsWith(".ttl"))
{
param = 'file:///' + directoryPath + '\\\\' + filename;
console.log('\nvalue of param is = ' + ${param}
);
// If there is a hard coded path then the call works correctly
// How to get it to work with a parameter?
session
.run
(
/* ***************************************************************
* This works!. *
* "call n10s.rdf.import.fetch('file:/// *
* E:\\\\Graph_Databases\\\\Student_Admin_System\\\\rdf_src *
* \\\\Software_Engineering_Major_Map.ttl', 'Turtle')" *
* *
* ***************************************************************/
"call n10s.rdf.import.fetch(`${param}`, 'Turtle')"
)
.then( ( ) =>
{
console.log('\nin .then() param is: ' + `${param}`);
})
.catch( (error) =>
{
console.log('error = ' + error);
});
}
else
{
console.log('file name must end in .ttl');
}
}
module.exports = loadFromFileMajorMap
thanks
Richard Tresider