provdbconnector.db_adapters.in_memory package

Submodules

provdbconnector.db_adapters.in_memory.simple_in_memory module

class provdbconnector.db_adapters.in_memory.simple_in_memory.SimpleInMemoryAdapter(*args)[source]

Bases: provdbconnector.db_adapters.baseadapter.BaseAdapter

The simple in memory adapter is a reference implementation for a database adapter to save prov information into a graph database

For exmaple to use the simple db_adapter use the following script

 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
from prov.model import ProvDocument
from provdbconnector import ProvDb
from provdbconnector.db_adapters.in_memory import SimpleInMemoryAdapter

prov_api = ProvDb(adapter=SimpleInMemoryAdapter, auth_info=None)

# create the prov document
prov_document = ProvDocument()
prov_document.add_namespace("ex", "http://example.com")

prov_document.agent("ex:Bob")
prov_document.activity("ex:Alice")

prov_document.association("ex:Alice", "ex:Bob")

document_id = prov_api.save_document(prov_document)

print(prov_api.get_document_as_provn(document_id))

# Output:
#
# document
# prefix
# ex < http: // example.com >
#
# agent(ex:Bob)
# activity(ex:Alice, -, -)
# wasAssociatedWith(ex:Alice, ex:Bob, -)
# endDocument
all_nodes = {}

Contains all nodes

all_relations = {}

Contains all relation according to the following structure (start_identifier, (end_identifier,attributes, metadata))`

connect(authentication_info)[source]

This function setups your database connection (auth / service discover)

Parameters:authentication_info (dict or None) – The info to connect to the db
Returns:The result of the connection attempt
Return type:Bool
save_element(attributes, metadata)[source]

Store a single node in the database and if necessary and possible merge the node

Parameters:
  • attributes (dict) – The actual provenance data
  • metadata (dict) – Some metadata that are not PROV-O related
Returns:

id of the record

Return type:

str

save_relation(from_node, to_node, attributes, metadata)[source]

Store a relation between 2 nodes in the database. Merge also the relation if necessary and possible

Parameters:
  • from_node (prov.model.Identifier) – The identifier for the start node
  • to_node (prov.model.Identifier) – The identifier for the end node
  • attributes (dict) – The actual provenance data
  • metadata (dict) – Some metadata that are not PROV-O related
Returns:

The id of the relation

Return type:

str

get_record(record_id)[source]

Get a ProvDocument from the database based on the document id

Parameters:record_id (str) – The id of the node
Returns:A named tuple with (attributes, metadata)
Return type:DbRecord
get_relation(relation_id)[source]

Return the relation behind the relation_id

Parameters:relation_id (str) – The id of the relation
Returns:The namedtuple with (attributes, metadata)
Return type:DbRelation
get_records_by_filter(attributes_dict=None, metadata_dict=None)[source]

Filter all nodes based on the provided attributes and metadata dict The filter is currently defined as follows:

  • The filter is only applied to the start node
  • All connections from the start node are also included in the result set
Parameters:
  • attributes_dict (dict) – A filter dict with a conjunction of all values in the attributes_dict and metadata_dict
  • metadata_dict (dict) – A filter for the metadata with a conjunction of all values (also in the attributes_dict )
Returns:

The list of matching relations and nodes

Return type:

List(DbRecord or Dbrelation)

get_records_tail(attributes_dict=None, metadata_dict=None, depth=None)[source]

Return the provenance based on a filter combination. The filter dicts are only relevant for the start nodes. They describe the params to get the start nodes (for example a filter for a specific identifier ) and from there we want all connected nodes

Parameters:
  • attributes_dict (dict) – A filter dict with a conjunction of all values in the attributes_dict and metadata_dict
  • metadata_dict (dict) – A filter for the metadata with a conjunction of all values (also in the attributes_dict )
  • depth (int) – The level of detail, default to infinite
Returns:

A list of DbRelations and DbRecords

Return type:

list(DbRelation or DbRecord)

get_bundle_records(bundle_identifier)[source]

Get the records for a specific bundle identifier

This include all nodes that have a relation of the prov:type = prov:bundleAssociation and also all relation where the start and end node are in the bundle. Also you should add the prov mentionOf relation where the start node is in the bundle. See https://www.w3.org/TR/prov-links/

Parameters:bundle_identifier (prov.model.Identifier) – The identifier of the bundle
Returns:The list with the bundle nodes and all connections where the start node and end node in the bundle.
Return type:list(DbRelation or DbRecord )
delete_records_by_filter(attributes_dict=None, metadata_dict=None)[source]

Delete a set of records based on filter conditions

Parameters:
  • attributes_dict (dict) – A filter dict with a conjunction of all values in the attributes_dict and metadata_dict
  • metadata_dict (dict) – A filter for the metadata with a conjunction of all values (also in the attributes_dict )
Returns:

The result of the operation

Return type:

Bool

delete_record(record_id)[source]

Delete a single record

Parameters:record_id (str) – The node id
Returns:Result of the delete operation
Return type:Bool
delete_relation(relation_id)[source]

Delete the relation

Parameters:relation_id (str) – The relation id
Returns:Result of the delete operation
Return type:Bool

Module contents