node-rdf icon indicating copy to clipboard operation
node-rdf copied to clipboard

Print profile

Open felipe-vargas-inrae opened this issue 5 years ago • 2 comments

Hello,

I would like to know if exists some function to print the profile, I want to reconstruct the complete turtle file based on a graph I know how to print the triples and create a string variable, but I don't find the way to print in the top of the file the prefix.

felipe-vargas-inrae avatar Apr 17 '19 07:04 felipe-vargas-inrae

You know, I thought there was a function that does this, because I've done that before, but maybe it disappeared.

If you need a quick workaround, try this:

function getTurtlePrefixes(profile){
    var prefixes = [];
    profile.prefixes.prefixMap.forEach(function(uri, prefix){
        prefixes.push('@prefix '+prefix+': '+(new rdf.NamedNode(uri)).toNT()+' .\n');
    });
    return s.join('');
}

awwright avatar Apr 17 '19 07:04 awwright

Hey @felipexxx, v4.1.0 is out which should fix some of this. Try this:

function getTurtlePrefixes(profile){
    var prefixes = [];
    profile.prefixes.list().forEach(function(prefix){
        var def = new rdf.NamedNode(profile.prefixes.get(prefix));
        prefixes.push('@prefix '+prefix+': '+def.toNT()+' .\n');
    });
    return s.join('');
}

Please let me know if this works for you, or if you have any additional feedback!

awwright avatar Apr 25 '19 02:04 awwright