File: usage.rst

package info (click to toggle)
python-prov 1.5.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 4,728 kB
  • sloc: python: 5,867; xml: 1,528; makefile: 166
file content (87 lines) | stat: -rw-r--r-- 2,687 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
=====
Usage
=====

Simple PROV document
--------------------

.. code:: python

    import prov.model as prov
    import datetime

    document = prov.ProvDocument()

    document.set_default_namespace('http://anotherexample.org/')
    document.add_namespace('ex', 'http://example.org/')

    e2 = document.entity('e2', (
        (prov.PROV_TYPE, "File"),
        ('ex:path', "/shared/crime.txt"),
        ('ex:creator', "Alice"),
        ('ex:content', "There was a lot of crime in London last month"),
    ))

    a1 = document.activity('a1', datetime.datetime.now(), None, {prov.PROV_TYPE: "edit"})
    # References can be qnames or ProvRecord objects themselves
    document.wasGeneratedBy(e2, a1, None, {'ex:fct': "save"})
    document.wasAssociatedWith('a1', 'ag2', None, None, {prov.PROV_ROLE: "author"})
    document.agent('ag2', {prov.PROV_TYPE: 'prov:Person', 'ex:name': "Bob"})

    document.get_provn() # =>

    # document
    #   default <http://anotherexample.org/>
    #   prefix ex <http://example.org/>
    #   
    #   entity(e2, [prov:type="File", ex:creator="Alice",
    #               ex:content="There was a lot of crime in London last month",
    #               ex:path="/shared/crime.txt"])
    #   activity(a1, 2014-07-09T16:39:38.795839, -, [prov:type="edit"])
    #   wasGeneratedBy(e2, a1, -, [ex:fct="save"])
    #   wasAssociatedWith(a1, ag2, -, [prov:role="author"])
    #   agent(ag2, [prov:type="prov:Person", ex:name="Bob"])
    # endDocument

PROV document with a bundle
---------------------------

.. code:: python

    import prov.model as prov

    document = prov.ProvDocument()

    document.set_default_namespace('http://example.org/0/')
    document.add_namespace('ex1', 'http://example.org/1/')
    document.add_namespace('ex2', 'http://example.org/2/')

    document.entity('e001')

    bundle = document.bundle('e001')
    bundle.set_default_namespace('http://example.org/2/')
    bundle.entity('e001')

    document.get_provn() # =>

    # document
    #   default <http://example.org/0/>
    #   prefix ex2 <http://example.org/2/>
    #   prefix ex1 <http://example.org/1/>
    #   
    #   entity(e001)
    #   bundle e001
    #     default <http://example.org/2/>
    #     
    #     entity(e001)
    #   endBundle
    # endDocument

    document.serialize() # =>

    # {"prefix": {"default": "http://example.org/0/", "ex2": "http://example.org/2/", "ex1": "http://example.org/1/"}, "bundle": {"e001": {"prefix": {"default": "http://example.org/2/"}, "entity": {"e001": {}}}}, "entity": {"e001": {}}}

More examples
-------------

See `prov/tests/examples.py <https://github.com/trungdong/prov/blob/master/prov/tests/examples.py>`_