<jupyter_start><jupyter_text>![PPGI_UFRJ](imagens/ppgi-ufrj.png) Fundamentos de Ciência de Dados  Provenance Test  Instalação<jupyter_code>#!pip install prov[dot]
from prov.model import ProvDocument
# Create a new provenance document
d1 = ProvDocument()  # d1 is now an empty provenance document
# Declaring namespaces for various prefixes used in the example
d1.add_namespace('now', 'http://www.provbook.org/nownews/')
d1.add_namespace('nowpeople', 'http://www.provbook.org/nownews/people/')
d1.add_namespace('bk', 'http://www.provbook.org/ns/#')
# Entity: now:employment-article-v1.html
e1 = d1.entity('now:employment-article-v1.html')
# Agent: nowpeople:Bob
d1.agent('nowpeople:Zavaleta')
# Attributing the article to the agent
d1.wasAttributedTo(e1, 'nowpeople:Zavaleta')
# What we have so far (in PROV-N)
print(d1.get_provn())
# add more namespace declarations
d1.add_namespace('govftp', 'ftp://ftp.bls.gov/pub/special.requests/oes/')
d1.add_namespace('void', 'http://vocab.deri.ie/void#')

# 'now:employment-article-v1.html' was derived from at dataset at govftp
d1.entity('govftp:oesm11st.zip', {'prov:label': 'employment-stats-2011', 'prov:type': 'void:Dataset'})
d1.wasDerivedFrom('now:employment-article-v1.html', 'govftp:oesm11st.zip')
print(d1.get_provn())
# Adding an activity
d1.add_namespace('is', 'http://www.provbook.org/nownews/is/#')
d1.activity('is:writeArticle')
# Usage and Generation
d1.used('is:writeArticle', 'govftp:oesm11st.zip')
d1.wasGeneratedBy('now:employment-article-v1.html', 'is:writeArticle')<jupyter_output><empty_output><jupyter_text>Graphics export (PNG and PDF)<jupyter_code># conda install graphviz - CMD
# visualize the graph
from prov.dot import prov_to_dot
dot = prov_to_dot(d1)
dot.write_png('article-prov.png')
from IPython.display import Image
Image('article-prov.png')
# conda install -c anaconda pydot
# conda install -c conda-forge pydotplus
# Or save to a PDF
dot.write_pdf('article-prov.pdf')<jupyter_output><empty_output><jupyter_text>PROV-JSON export<jupyter_code>print(d1.serialize(indent=2))
d1.serialize('article-prov.json')<jupyter_output><empty_output><jupyter_text>XML and RDF Support<jupyter_code>d1.serialize('article-prov.xml', format='xml')
d1.serialize('article-prov.ttl', format='rdf', rdf_format='ttl')<jupyter_output><empty_output><jupyter_text>Store and retrieve provenance documents from ProvStore<jupyter_code># Configure ProvStore API Wrapper with your API Key
from provstore.api import Api
# see your API key at https://openprovenance.org/store/account/developer/
api = Api(base_url='https://openprovenance.org/store/api/v0', username='<your-username>', api_key='<your-API-key>')
# Submit the document to ProvStore
provstore_document = api.document.create(d1, name='article-prov', public=True)

# Generate a nice link to the document on ProvStore so you don't have to find it manually 
from IPython.display import HTML
document_uri = provstore_document.url
HTML('<a href="%s" target="_blank">Open your new provenance document on ProvStore</a>' % document_uri)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14211042143090494, 'fraction_numerical': 0.014047696831100947, 'mean_word_length': 6.994778067885117, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 2, 'lorem ipsum': 0, 'www.': 4, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '389129', 'license': 'CC0-1.0', 'n_tokens_mistral': 1116, 'n_tokens_neox': 1080, 'n_words': 222, 'path': '.ipynb_checkpoints/FCD_M1_3_Provenance-checkpoint.ipynb', 'repo_name': 'zavaleta/Fundamentos_DS', 'size': '3061'}