Created
December 29, 2024 11:03
-
-
Save egonw/53b8aa52bee0c939f0d4a04704e8ebdb to your computer and use it in GitHub Desktop.
Making NanoPub Template NanoPubs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Grab(group='org.nanopub', module='nanopub', version='1.66') | |
import org.nanopub.Nanopub; | |
import org.nanopub.NanopubCreator; | |
import org.nanopub.NanopubUtils; | |
import org.eclipse.rdf4j.model.impl.SimpleValueFactory; | |
import org.eclipse.rdf4j.model.vocabulary.FOAF; | |
import org.eclipse.rdf4j.model.vocabulary.RDF; | |
import org.eclipse.rdf4j.model.vocabulary.RDFS; | |
import org.eclipse.rdf4j.model.vocabulary.SKOS; | |
import org.eclipse.rdf4j.model.vocabulary.OWL; | |
import org.eclipse.rdf4j.rio.RDFFormat; | |
factory = SimpleValueFactory.getInstance() | |
externalUriPlaceholder = factory.createIRI("https://w3id.org/np/o/ntemplate/ExternalUriPlaceholder") | |
assertionTemplate = factory.createIRI("https://w3id.org/np/o/ntemplate/AssertionTemplate") | |
restrictedChoicePlaceholder = factory.createIRI("https://w3id.org/np/o/ntemplate/RestrictedChoicePlaceholder") | |
repeatableStatement = factory.createIRI("https://w3id.org/np/o/ntemplate/RepeatableStatement") | |
hasNanopubLabelPattern = factory.createIRI("https://w3id.org/np/o/ntemplate/hasNanopubLabelPattern") | |
hasStatement = factory.createIRI("https://w3id.org/np/o/ntemplate/hasStatement") | |
hasTag = factory.createIRI("https://w3id.org/np/o/ntemplate/hasTag") | |
hasTargetNanopubType = factory.createIRI("https://w3id.org/np/o/ntemplate/hasTargetNanopubType") | |
possibleValuesFrom = factory.createIRI("https://w3id.org/np/o/ntemplate/possibleValuesFrom") | |
wasAttributedTo = factory.createIRI("http://www.w3.org/ns/prov#wasAttributedTo") | |
description = factory.createIRI("http://purl.org/dc/terms/description") | |
license = factory.createIRI("http://purl.org/dc/terms/license") | |
citesIRI = factory.createIRI("http://purl.org/spar/cito/cites") | |
name = factory.createIRI("http://xmlns.com/foaf/0.1/name") | |
rdfObject = factory.createIRI("http://www.w3.org/1999/02/22-rdf-syntax-ns#object") | |
rdfPredicate = factory.createIRI("http://www.w3.org/1999/02/22-rdf-syntax-ns#predicate") | |
rdfSubject = factory.createIRI("http://www.w3.org/1999/02/22-rdf-syntax-ns#subject") | |
nanopubIRI = "http://purl.org/nanopub/temp/np1#" | |
creator = new NanopubCreator(nanopubIRI) | |
creator.addTimestamp(new Date()) | |
creator.addNamespace("np", "http://www.nanopub.org/nschema#") | |
creator.addNamespace("dct", "http://purl.org/dc/terms/") | |
creator.addNamespace("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#") | |
creator.addNamespace("nt", "https://w3id.org/np/o/ntemplate/") | |
creator.addNamespace("npx", "http://purl.org/nanopub/x/") | |
creator.addNamespace("xsd", "http://www.w3.org/2001/XMLSchema#") | |
creator.addNamespace("rdfs", "http://www.w3.org/2000/01/rdf-schema#") | |
creator.addNamespace("orcid", "https://orcid.org/") | |
creator.addNamespace("ns1", "http://purl.org/np/") | |
creator.addNamespace("prov", "http://www.w3.org/ns/prov#") | |
creator.addNamespace("foaf", "http://xmlns.com/foaf/0.1/") | |
creator.addNamespace("owl", "http://www.w3.org/2002/07/owl#") | |
creator.addNamespace("pav", "http://purl.org/pav/") | |
creator.addNamespace("skos", "http://www.w3.org/2004/02/skos/core#") | |
creativeWork = factory.createIRI("http://purl.org/spar/fabio/ScholarlyWork") | |
creator.addAssertionStatement(creativeWork, RDFS.LABEL, | |
factory.createLiteral("scholarly paper - any kind of scholarly work, such as an article, book, etc.") | |
) | |
creator.addAssertionStatement(RDF.TYPE, RDFS.LABEL, factory.createLiteral("is a")) | |
articleIRI = factory.createIRI("http://purl.org/nanopub/temp/np1#article") | |
creator.addAssertionStatement(articleIRI, RDF.TYPE, externalUriPlaceholder) | |
creator.addAssertionStatement(articleIRI, RDFS.LABEL, | |
factory.createLiteral("DOI (https://doi.org/10...) or other URL of the citing article") | |
) | |
assertionIRI = creator.getAssertionUri() | |
creator.addAssertionStatement(assertionIRI, description, | |
factory.createLiteral("Such a nanopublication expresses citation relations of a given article based on the CiTO relation types.") | |
) | |
creator.addAssertionStatement(assertionIRI, RDF.TYPE, assertionTemplate) | |
creator.addAssertionStatement(assertionIRI, RDFS.LABEL, factory.createLiteral("Declare citations with CiTO")) | |
creator.addAssertionStatement(assertionIRI, hasNanopubLabelPattern, factory.createLiteral("Citations for: \${article}")) | |
creator.addAssertionStatement(assertionIRI, hasTag, factory.createLiteral("Journals")) | |
creator.addAssertionStatement(assertionIRI, hasTargetNanopubType, citesIRI) | |
creator.addAssertionStatement(assertionIRI, hasTargetNanopubType, creativeWork) | |
st01IRI = factory.createIRI("http://purl.org/nanopub/temp/np1#st01") | |
st02IRI = factory.createIRI("http://purl.org/nanopub/temp/np1#st02") | |
creator.addAssertionStatement(assertionIRI, hasStatement, st01IRI) | |
creator.addAssertionStatement(assertionIRI, hasStatement, st02IRI) | |
citedIRI = factory.createIRI("http://purl.org/nanopub/temp/np1#cited") | |
creator.addAssertionStatement(citedIRI, RDF.TYPE, externalUriPlaceholder) | |
creator.addAssertionStatement(citedIRI, RDFS.LABEL, | |
factory.createLiteral("DOI (https://doi.org/10...) or other URL of the cited article") | |
) | |
citesIRI = factory.createIRI("http://purl.org/nanopub/temp/np1#cites") | |
creator.addAssertionStatement(citesIRI, RDF.TYPE, restrictedChoicePlaceholder) | |
creator.addAssertionStatement(citesIRI, RDFS.LABEL, factory.createLiteral("select the citation type")) | |
creator.addAssertionStatement(citesIRI, possibleValuesFrom, factory.createIRI("https://w3id.org/np/RAZt5kzfoJg2m4dMRdMm2SP6JeUDD_GMzSq9xyRPMgP5k")) | |
creator.addAssertionStatement(st01IRI, rdfSubject, articleIRI) | |
creator.addAssertionStatement(st01IRI, rdfPredicate, RDF.TYPE) | |
creator.addAssertionStatement(st01IRI, rdfObject, creativeWork) | |
creator.addAssertionStatement(st02IRI, rdfSubject, articleIRI) | |
creator.addAssertionStatement(st02IRI, rdfPredicate, citesIRI) | |
creator.addAssertionStatement(st02IRI, rdfObject, citedIRI) | |
creator.addAssertionStatement(st02IRI, RDF.TYPE, repeatableStatement) | |
theCreator = factory.createIRI("https://orcid.org/0000-0002-1267-0234") | |
creator.addCreator(theCreator) | |
creator.addProvenanceStatement(assertionIRI, wasAttributedTo, theCreator) | |
nanopubIRI = creator.getNanopubUri() | |
creator.addPubinfoStatement(theCreator, name, factory.createLiteral("Tobias Kuhn")) | |
creator.addPubinfoStatement(nanopubIRI, RDFS.LABEL, factory.createLiteral("Template: Declare citations with CiTO")) | |
creator.addPubinfoStatement(nanopubIRI, license, factory.createIRI("https://creativecommons.org/licenses/by/4.0/")) | |
creator.addPubinfoStatement(nanopubIRI, factory.createIRI("http://purl.org/nanopub/x/supersedes"), factory.createIRI("https://w3id.org/np/RA6TJFuEfARzqg5NhFdhv-tE8q6v0DoY9rKYhw5WUMhTA")) | |
creator.addPubinfoStatement(nanopubIRI, factory.createIRI("http://purl.org/nanopub/x/wasCreatedAt"), factory.createIRI("https://nanodash.knowledgepixels.com/")) | |
creator.addPubinfoStatement(nanopubIRI, factory.createIRI("https://w3id.org/np/o/ntemplate/wasCreatedFromProvenanceTemplate"), factory.createIRI("http://purl.org/np/RANwQa4ICWS5SOjw7gp99nBpXBasapwtZF1fIM3H2gYTM")) | |
creator.addPubinfoStatement(nanopubIRI, factory.createIRI("https://w3id.org/np/o/ntemplate/wasCreatedFromPubinfoTemplate"), factory.createIRI("http://purl.org/np/RAA2MfqdBCzmz9yVWjKLXNbyfBNcwsMmOqcNUxkk1maIM")) | |
creator.addPubinfoStatement(nanopubIRI, factory.createIRI("https://w3id.org/np/o/ntemplate/wasCreatedFromPubinfoTemplate"), factory.createIRI("http://purl.org/np/RAh1gm83JiG5M6kDxXhaYT1l49nCzyrckMvTzcPn-iv90")) | |
creator.addPubinfoStatement(nanopubIRI, factory.createIRI("https://w3id.org/np/o/ntemplate/wasCreatedFromPubinfoTemplate"), factory.createIRI("http://purl.org/np/RAjpBMlw3owYhJUBo3DtsuDlXsNAJ8cnGeWAutDVjuAuI")) | |
creator.addPubinfoStatement(nanopubIRI, factory.createIRI("https://w3id.org/np/o/ntemplate/wasCreatedFromTemplate"), factory.createIRI("http://purl.org/np/RAJwu5sVubRqXY4t2gkSoGxWkMyZqnpkGTCPiTlmvi4so")) | |
// output everything | |
trustedPub = creator.finalizeTrustyNanopub() | |
outputBuffer = new StringBuffer(); | |
outputBuffer.append(NanopubUtils.writeToString(trustedPub, RDFFormat.TRIG)); | |
print outputBuffer.toString() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@prefix this: <https://w3id.org/np/RAFYzuds9uDl0DcLD_T3sbiKDG2y9iL3OMPIg-dy7fOQc> . | |
@prefix sub: <https://w3id.org/np/RAFYzuds9uDl0DcLD_T3sbiKDG2y9iL3OMPIg-dy7fOQc#> . | |
@prefix np: <http://www.nanopub.org/nschema#> . | |
@prefix dct: <http://purl.org/dc/terms/> . | |
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . | |
@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/> . | |
sub:Head { | |
this: a np:Nanopublication; | |
np:hasAssertion sub:assertion; | |
np:hasProvenance sub:provenance; | |
np:hasPublicationInfo sub:pubinfo . | |
} | |
sub:assertion { | |
<http://purl.org/spar/fabio/ScholarlyWork> rdfs:label "scholarly paper - any kind of scholarly work, such as an article, book, etc." . | |
rdf:type rdfs:label "is a" . | |
sub:article a nt:ExternalUriPlaceholder; | |
rdfs:label "DOI (https://doi.org/10...) or other URL of the citing article" . | |
sub:assertion a nt:AssertionTemplate; | |
dct:description "Such a nanopublication expresses citation relations of a given article based on the CiTO relation types."; | |
rdfs:label "Declare citations with CiTO"; | |
nt:hasNanopubLabelPattern "Citations for: ${article}"; | |
nt:hasStatement sub:st01, sub:st02; | |
nt:hasTag "Journals"; | |
nt:hasTargetNanopubType <http://purl.org/spar/cito/cites>, <http://purl.org/spar/fabio/ScholarlyWork> . | |
sub:cited a nt:ExternalUriPlaceholder; | |
rdfs:label "DOI (https://doi.org/10...) or other URL of the cited article" . | |
sub:cites a nt:RestrictedChoicePlaceholder; | |
rdfs:label "select the citation type"; | |
nt:possibleValuesFrom <https://w3id.org/np/RAZt5kzfoJg2m4dMRdMm2SP6JeUDD_GMzSq9xyRPMgP5k> . | |
sub:st01 rdf:object <http://purl.org/spar/fabio/ScholarlyWork>; | |
rdf:predicate rdf:type; | |
rdf:subject sub:article . | |
sub:st02 a nt:RepeatableStatement; | |
rdf:object sub:cited; | |
rdf:predicate sub:cites; | |
rdf:subject sub:article . | |
} | |
sub:provenance { | |
sub:assertion prov:wasAttributedTo orcid:0000-0002-1267-0234 . | |
} | |
sub:pubinfo { | |
orcid:0000-0002-1267-0234 foaf:name "Tobias Kuhn" . | |
this: dct:created "2024-12-29T11:54:06.411+01:00"^^xsd:dateTime; | |
dct:creator orcid:0000-0002-1267-0234; | |
dct:license <https://creativecommons.org/licenses/by/4.0/>; | |
npx:supersedes <https://w3id.org/np/RA6TJFuEfARzqg5NhFdhv-tE8q6v0DoY9rKYhw5WUMhTA>; | |
npx:wasCreatedAt <https://nanodash.knowledgepixels.com/>; | |
rdfs:label "Template: Declare citations with CiTO"; | |
nt:wasCreatedFromProvenanceTemplate ns1:RANwQa4ICWS5SOjw7gp99nBpXBasapwtZF1fIM3H2gYTM; | |
nt:wasCreatedFromPubinfoTemplate ns1:RAA2MfqdBCzmz9yVWjKLXNbyfBNcwsMmOqcNUxkk1maIM, | |
ns1:RAh1gm83JiG5M6kDxXhaYT1l49nCzyrckMvTzcPn-iv90, ns1:RAjpBMlw3owYhJUBo3DtsuDlXsNAJ8cnGeWAutDVjuAuI; | |
nt:wasCreatedFromTemplate ns1:RAJwu5sVubRqXY4t2gkSoGxWkMyZqnpkGTCPiTlmvi4so . | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment