csensemakers / desci-sense

2 stars 2 forks source link

Generating the TriG template for our nanopub #111

Open ShaRefOh opened 7 months ago

ShaRefOh commented 7 months ago

@pepoospina It seems I have some issues to address on running ts, which I will address. I played a bit on an online playground, and I think I finished the TriG generation, but I can't test the whole thing, of course. I am attaching it here so that I won't be committing to the changes. I can commit to a new branch if it seems better for you. Here is the script with adding triplets orchid and correct prefixes. `import { Nanopub } from '@nanopub/sign';

import { AppPostCreate, AppUserRead } from '../@shared/types';

//reformat the triplets from AppPostCreate to be added as predicate and object
//to the subject :assertion function processTriplets(triplets: string[]): string[] { return triplets.map(triplet => { let firstGreaterIndex = triplet.indexOf('>'); return triplet.substring(firstGreaterIndex + 1).trim() + ';'; }); }

export const constructNanopub = async ( postCreateData: AppPostCreate, user: AppUserRead ): Promise => { // Process the triplets const processedTriplets = processTriplets(postCreateData.semantics?.triplets) // Convert the array of triplets to a single string const tripletsStr = processedTriplets.join('\n ');

const rdfStr = ` @prefix this: https://w3id.org/np/RAuohvU0INLVpmB8kpddnyx5zHOb-NbjoFgYM-AgZU9eY . @prefix sub: https://w3id.org/np/RAuohvU0INLVpmB8kpddnyx5zHOb-NbjoFgYM-AgZU9eY# . @prefix np: http://www.nanopub.org/nschema# . @prefix dct: http://purl.org/dc/terms/ . @prefix nt: https://w3id.org/np/o/ntemplate/ . @prefix npx: http://purl.org/nanopub/x/ . @prefix xsd: http://www.w3.org/2001/XMLSchema# . @prefix rdfs: http://www.w3.org/2000/01/rdf-schema# . @prefix orcid: https://orcid.org/ . @prefix ns1: http://purl.org/np/ . @prefix prov: http://www.w3.org/ns/prov# . @prefix foaf: http://xmlns.com/foaf/0.1/ .

 :Head {
   : np:hasAssertion :assertion ;
     np:hasProvenance :provenance ;
     np:hasPublicationInfo :pubinfo ;
     a np:Nanopublication .
 }

 :assertion {
   :assertion dct:creator orcid:${user.orcid.orcid} ;
     ${tripletsStr}
     rdfs:comment ${postCreateData.content} . 
 }

 :provenance {
   :assertion prov:wasAttributedTo orcid:${user.orcid.orcid} .
 }

 :pubinfo {

 }

`;

const np = new Nanopub(rdfStr); return np; };`

pepoospina commented 7 months ago

This looks good @ShaRefOh I will add it as it is.