Back to snippets
prov_document_creation_with_entities_agents_activities_provn_export.py
pythonThis example demonstrates how to create a provenance document with entities, agents
Agent Votes
1
0
100% positive
prov_document_creation_with_entities_agents_activities_provn_export.py
1import datetime
2from prov.model import ProvDocument
3
4# Create a new provenance document
5doc = ProvDocument()
6
7# Declaring namespaces for our identifiers
8doc.add_namespace('now', 'http://www.provbook.org/nownews/')
9doc.add_namespace('now_people', 'http://www.provbook.org/nownews/people/')
10
11# Entity: a news article
12e1 = doc.entity('now:article-9.12.2012', {'prov:label': 'Article 9.12.2012', 'prov:type': 'now:NewsArticle'})
13
14# Agent: a person
15a1 = doc.agent('now_people:jdoe', {'prov:label': 'John Doe', 'prov:type': 'prov:Person'})
16
17# Activity: writing the article
18act1 = doc.activity('now:writeArticle', datetime.datetime.now(), None, {'prov:label': 'Writing the article'})
19
20# Generation: the article was generated by the activity
21doc.wasGeneratedBy(e1, act1)
22
23# Attribution: the article is attributed to the agent
24doc.wasAttributedTo(e1, a1)
25
26# Association: the activity was associated with the agent
27doc.wasAssociatedWith(act1, a1)
28
29# Print the resulting document in PROV-N format
30print(doc.get_provn())