Skip to content

Instantly share code, notes, and snippets.

@zednis
Created May 24, 2016 20:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zednis/c42d07e03955b32879cb876dab96f89a to your computer and use it in GitHub Desktop.
Save zednis/c42d07e03955b32879cb876dab96f89a to your computer and use it in GitHub Desktop.
iPython PROV Test
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 37,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"from kleio import prov\n",
"from rdflib import Literal"
]
},
{
"cell_type": "code",
"execution_count": 38,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"DCT = prov.ns(\"dct\", \"http://purl.org/dc/terms/\")\n",
"FOAF = prov.ns(\"foaf\", \"http://xmlns.com/foaf/0.1/\")\n",
"EX = prov.ns(\"ex\", \"http://www.example.org#\")"
]
},
{
"cell_type": "code",
"execution_count": 39,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"dataset1 = prov.Entity(\"ex:dataset1\")\n",
"dataset1.add(DCT.title, Literal(\"Dataset 1\"))"
]
},
{
"cell_type": "code",
"execution_count": 40,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"activity1 = prov.Activity(\"ex:activity1\")"
]
},
{
"cell_type": "code",
"execution_count": 41,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"researcher1 = prov.Person(\"ex:researcher1\")\n",
"researcher1.set_label(\"Bob the researcher\")\n",
"researcher1.add_type(FOAF.Person)\n",
"researcher1.add(FOAF.givenName, Literal(\"Bob\"))\n",
"activity1.set_was_associated_with(researcher1)"
]
},
{
"cell_type": "code",
"execution_count": 42,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"activity1.set_used(dataset1)"
]
},
{
"cell_type": "code",
"execution_count": 43,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"dataset2 = prov.Entity(\"ex:dataset2\")\n",
"dataset2.add(DCT.title, Literal(\"Dataset 2\"))"
]
},
{
"cell_type": "code",
"execution_count": 44,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"dataset2.set_was_generated_by(activity1)\n",
"dataset2.set_was_derived_from(dataset1)"
]
},
{
"cell_type": "code",
"execution_count": 47,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"@prefix dct: <http://purl.org/dc/terms/> .\n",
"@prefix ex: <http://www.example.org#> .\n",
"@prefix foaf: <http://xmlns.com/foaf/0.1/> .\n",
"@prefix prov: <http://www.w3.org/ns/prov#> .\n",
"@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .\n",
"@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n",
"@prefix xml: <http://www.w3.org/XML/1998/namespace> .\n",
"@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .\n",
"\n",
"<ex:researcher1> a prov:Agent,\n",
" prov:Person,\n",
" foaf:Person ;\n",
" rdfs:label \"Bob the researcher\" ;\n",
" prov:influenced <ex:activity1> ;\n",
" foaf:givenName \"Bob\" .\n",
"\n",
"<ex:dataset2> a prov:Entity ;\n",
" dct:title \"Dataset 2\" ;\n",
" prov:wasDerivedFrom <ex:dataset1> ;\n",
" prov:wasGeneratedBy <ex:activity1> ;\n",
" prov:wasInfluencedBy <ex:activity1>,\n",
" <ex:dataset1> .\n",
"\n",
"<ex:activity1> a prov:Activity ;\n",
" prov:generated <ex:dataset2> ;\n",
" prov:influenced <ex:dataset2> ;\n",
" prov:used <ex:dataset1> ;\n",
" prov:wasAssociatedWith <ex:researcher1> ;\n",
" prov:wasInfluencedBy <ex:dataset1>,\n",
" <ex:researcher1> .\n",
"\n",
"<ex:dataset1> a prov:Entity ;\n",
" dct:title \"Dataset 1\" ;\n",
" prov:influenced <ex:activity1>,\n",
" <ex:dataset2> .\n",
"\n",
"\n"
]
}
],
"source": [
"print(prov.serialize(format=\"turtle\"))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.4.0"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment