Created
December 29, 2024 11:34
-
-
Save egonw/e01e9a3d5a28cc30116add195921787a to your computer and use it in GitHub Desktop.
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("https://schema.org/CreativeWork") | |
creator.addAssertionStatement(creativeWork, RDFS.LABEL, | |
factory.createLiteral("The most generic kind of creative work, including books, movies, photographs, software programs, 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-0001-7542-0286") | |
creator.addCreator(theCreator) | |
creator.addProvenanceStatement(assertionIRI, wasAttributedTo, theCreator) | |
nanopubIRI = creator.getNanopubUri() | |
creator.addPubinfoStatement(theCreator, name, factory.createLiteral("Egon Willighagen")) | |
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/RAX_4tWTyjFpO6nz63s14ucuejd64t2mK3IBlkwZ7jjLo")) | |
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/RAL69372zOSddFOUuRlaTW_MywjSjms6i4QTZqHeb2YT4> . | |
@prefix sub: <https://w3id.org/np/RAL69372zOSddFOUuRlaTW_MywjSjms6i4QTZqHeb2YT4#> . | |
@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 { | |
rdf:type rdfs:label "is a" . | |
<https://schema.org/CreativeWork> rdfs:label "The most generic kind of creative work, including books, movies, photographs, software programs, etc." . | |
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>, <https://schema.org/CreativeWork> . | |
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 <https://schema.org/CreativeWork>; | |
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-0001-7542-0286 . | |
} | |
sub:pubinfo { | |
orcid:0000-0001-7542-0286 foaf:name "Egon Willighagen" . | |
this: dct:created "2024-12-29T12:29:00.670+01:00"^^xsd:dateTime; | |
dct:creator orcid:0000-0001-7542-0286; | |
dct:license <https://creativecommons.org/licenses/by/4.0/>; | |
npx:supersedes <https://w3id.org/np/RAX_4tWTyjFpO6nz63s14ucuejd64t2mK3IBlkwZ7jjLo>; | |
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