nanopub.publication

This module holds code for representing the RDF of nanopublications, as well as helper functions to make handling RDF easier.

class nanopub.publication.Publication(rdf: rdflib.graph.ConjunctiveGraph, source_uri: Optional[str] = None)

Representation of the rdf that comprises a nanopublication

rdf

The full RDF graph of this nanopublication

Type

rdflib.ConjunctiveGraph

assertion

The part of the graph describing the assertion.

Type

rdflib.Graph

pubinfo

The part of the graph describing the publication information.

Type

rdflib.Graph

provenance

The part of the graph describing the provenance.

Type

rdflib.Graph

source_uri

The URI of the nanopublication that this Publication represents (if applicable)

Type

str

introduces_concept

The concept that is introduced by this Publication.

signed_with_public_key

The public key that this Publication is signed with.

is_test_publication

Whether this is a test publication

classmethod from_assertion(assertion_rdf: rdflib.graph.Graph, introduces_concept: Optional[rdflib.term.BNode] = None, derived_from=None, assertion_attributed_to=None, publication_attributed_to=None, attribute_assertion_to_profile: bool = False, provenance_rdf: Optional[rdflib.graph.Graph] = None, pubinfo_rdf: Optional[rdflib.graph.Graph] = None)

Construct Nanopub object based on given assertion.

Any blank nodes in the rdf graph are replaced with the nanopub’s URI, with the blank node name as a fragment. For example, if the blank node is called ‘step’, that would result in a URI composed of the nanopub’s (base) URI, followed by #step.

Parameters
  • assertion_rdf (rdflib.Graph) – The assertion RDF graph.

  • introduces_concept (rdflib.term.BNode) – the pubinfo graph will note that this nanopub npx:introduces the concept. The concept should be a blank node (rdflib.term.BNode), and is converted to a URI derived from the nanopub’s URI with a fragment (#) made from the blank node’s name.

  • derived_from (rdflib.URIRef, str, or list) – Add a triple to the provenance graph stating that this nanopub’s assertion prov:wasDerivedFrom the given URI. If a list of URIs is passed, a provenance triple will be generated for each.

  • assertion_attributed_to (rdflib.URIRef or str) – the provenance graph will note that this nanopub’s assertion prov:wasAttributedTo the given URI.

  • publication_attributed_to (rdflib.URIRef or str) – the pubInfo graph will note that this nanopub itself prov:wasAttributedTo the given URI. If ‘None’ then this defaults to using the ORCID id provided in the user’s profile.

  • attribute_assertion_to_profile (bool) – Attribute the assertion to the ORCID iD in the profile

  • provenance_rdf (rdflib.Graph) – RDF triples to be added to provenance graph of the nanopublication. This is optional, for most cases the defaults will be sufficient.

  • pubinfo_rdf (rdflib.Graph) – RDF triples to be added to the publication info graph of the nanopublication. This is optional, for most cases the defaults will be sufficient.

nanopub.publication.replace_in_rdf(rdf: rdflib.graph.Graph, oldvalue, newvalue)

Replace values in RDF.

Replace all subjects or objects matching oldvalue with newvalue. Replaces in place.

Parameters
  • rdf (rdflib.Graph) – The RDF graph in which we want to replace nodes

  • oldvalue – The value to be replaced

  • newvalue – The value to replace with