rdf-translator
v2.0.0
Published
Convert between rdf formats
Downloads
25
Maintainers
Readme
rdf-translator
Convert between rdf formats
It is a javascript connector for the rdf-translator APIs using Promises.
Install
npm install --save rdf-translator
Usage
- From a string.
var rdfTranslator = require('rdf-translator');
var str = `
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:foaf="http://xmlns.com/foaf/0.1/">
<foaf:Person rdf:about="http://dbpedia.org/page/Spider-Man">
<foaf:name>Peter Parker</foaf:name>
<foaf:mbox rdf:resource="mailto:[email protected]"/>
</foaf:Person>
</rdf:RDF>
`
rdfTranslator(str, 'xml', 'n3')
.then(data => {
console.log(data);
\\ <http://dbpedia.org/page/Spider-Man> <http://xmlns.com/foaf/0.1/name> "Peter Parker" .
\\ <http://dbpedia.org/page/Spider-Man> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> .
\\ <http://dbpedia.org/page/Spider-Man> <http://xmlns.com/foaf/0.1/mbox> <mailto:[email protected]> .
}).catch(err => {
console.error(err);
});
In alternative, with traditional callbacks:
rdfTranslator(str, 'xml', 'n3', function(err, data) {
if (err) return console.error(err);
console.log(data);
});
- From a URI
var rdfTranslator = require('rdf-translator');
let uri = 'https://raw.githubusercontent.com/DOREMUS-ANR/doremus-ontology/master/doremus.ttl';
rdfTranslator(uri, 'n3', 'json-ld')
.then( data => {
var json == JSON.parse(data);
// your code here
});
API
rdfTranslator(str, source, target, [callback])
str
Type: string
Input string (i.e. in xml-rdf or turtle format) -or- URI of the file to convert.
source
Type: string
Format of the input string.
target
Type: string
Format of the desired output string.
callback(err, data)
Type: function
Callback function.
License
MIT