bento_meta.mdb
This module contains MDB
, with machinery for efficiently
querying a Neo4j instance of a Metamodel Database.
Submodules
Classes
Functions
|
Create a random nanoid and return it as a string. |
|
Decorates a query function to run a read transaction based on |
|
Decorates a query function to run a read transaction based on |
|
Decorates a query function to run a read transaction based on |
|
Load an MDF object into an MDB instance |
|
Load a model object into an MDB instance. |
|
Create Cypher statements from a model to load it de novo into an |
Package Contents
- class bento_meta.mdb.MDB(uri=os.environ.get('NEO4J_MDB_URI'), user=os.environ.get('NEO4J_MDB_USER'), password=os.environ.get('NEO4J_MDB_PASS'))[source]
- uri
- user
- password
- driver = None
- models
- latest_version
- _txfns
- register_txfn(name, fn)[source]
Register a transaction function (see https://neo4j.com/docs/api/python-driver/current/api.html#managed-transactions-transaction-functions) with the class for later use.
- get_model_handles()[source]
Return a simple list of model handles available. Queries Model nodes (not model properties in Entity nodes)
- get_model_versions(model)[source]
Get list of version strings present in database for a given model. Returns [ <string> ].
- get_latest_version(model)[source]
Get the version string from Model node marked is_latest:True for a given model handle. Returns <string>
- get_model_nodes(model=None)[source]
Return a list of dicts representing Model nodes. Returns all versions.
- get_nodes_by_model(model=None, version=None)[source]
Get all nodes for a given model. If :param:model is set but :param:version is None, get nodes from model version marked is_latest:true If :param:model is set and :param:version is ‘*’, get nodes from all model versions. If :param:model is None, get all nodes in database. Returns [ <node> ].
- get_model_nodes_edges(model, version=None)[source]
Get all node-relationship-node paths for a given model and version. If :param:version is None, use version marked is_latest:true for :param:model. If :param:version is ‘*’, retrieve from all versions. Returns [ path ]
- get_node_edges_by_node_id(nanoid)[source]
Get incoming and outgoing relationship information for a node, given its nanoid. Returns [ {id, handle, model, version, near_type, far_type, rln, far_node} ].
- get_node_and_props_by_node_id(nanoid)[source]
Get a node and its properties, given the node nanoid. Returns [ {id, handle, model, version, node, props[]} ].
- get_nodes_and_props_by_model(model=None, version=None)[source]
Get all nodes with associated properties given a model handle. If model is None, get all nodes with their properties. If :param:model is set but :param:version is None, get nodes and props from model version marked is_latest:true If :param:model is set and :param:version is ‘*’, get nodes and props from all model versions.
Returns [ {id, handle, model, version, props[]} ]
- get_prop_node_and_domain_by_prop_id(nanoid)[source]
Get a property, its node, and its value domain or value set of terms, given the property nanoid. Returns [ { id, handle, model, version, value_domain, prop, node, value_set, terms[] } ].
- get_valueset_by_id(nanoid)[source]
Get a valueset with the properties that use it and the terms that constitute it. Returns [ {id, handle, url, terms[], props[]} ]
- get_valuesets_by_model(model=None, version=None)[source]
Get all valuesets that are used by properties in the given model and version (or all valuesets if model is None). Also return list of properties using each valueset. If version is None, get value sets associated with latest model version. If version is ‘*’, get those associated with all versions of given model. Returns [ {value_set, props[]} ].
- get_term_by_id(nanoid)[source]
Get a term having the given nanoid, with its origin. Returns {term, origin}.
- get_props_and_terms_by_model(model=None, version=None)[source]
Get terms from valuesets associated with properties in a given model and version (or all such terms if model is None). If version is None, get props and terms from the latest model version. If version is set to ‘*’, get those from all versions of the given model. Returns [ {prop, terms[]} ]
- get_tags_for_entity_by_id(nanoid)[source]
Get all tags attached to an entity, given the entity’s nanoid. Returns [ {model(str), tags[]} ].
- get_tags_and_values(key=None)[source]
Get all tag key/value pairs that are present in database. Returns [ { key(str) : values[] } ]
- bento_meta.mdb.make_nanoid(alphabet='abcdefghijkmnopqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ0123456789', size=6)[source]
Create a random nanoid and return it as a string.
- bento_meta.mdb.read_txn(func)[source]
Decorates a query function to run a read transaction based on its query. Query function should return a tuple (qry_string, param_dict). Returns list of driver Records.
- bento_meta.mdb.read_txn_value(func)[source]
Decorates a query function to run a read transaction based on its query. Query function should return a tuple (qry_string, param_dict, values_key). Returns list of values for key specified by query function.
- bento_meta.mdb.read_txn_data(func)[source]
Decorates a query function to run a read transaction based on its query. Query function should return a tuple (qry_string, param_dict). Returns records as a list of simple dicts.
- class bento_meta.mdb.WriteableMDB(*args, **kwargs)[source]
Bases:
bento_meta.mdb.MDB
- put_term_with_origin(term, commit='', _from=1)[source]
Merge a bento-meta Term object, that has an Origin object set, into an MDB. If a new term is created, assign a random 6-char nanoid to it. The Origin must already be represented in the database. :param Term term: Term object :param str commit: GitHub commit SHA1 associated with the term (if any)
- class bento_meta.mdb.SearchableMDB(*args, **kwargs)[source]
Bases:
bento_meta.mdb.MDB
- ftindexes
- available_indexes()[source]
Fulltext indexes present in database. Returns { <index_name> : { entity_type:<NODE|RELATIONSHIP>, entities:[<labels>], properties:[ [<props>] ] } }
- query_index(index, qstring, skip=None, limit=None)[source]
Query a named fulltext index of nodes or relationships. Returns [ {ent:{}, label:<label>, score:<lucene score>} ].
- bento_meta.mdb.load_model(model, mdb, _commit=None)[source]
Load a model object into an MDB instance.
- bento_meta.mdb.load_model_statements(model, _commit=None)[source]
Create Cypher statements from a model to load it de novo into an MDB instance.
:param
mdb.Model
model: Model instance for loading :param str _commit: ‘Commit string’ for marking entities in DB. If set, this will override _commit attributes already existing on Model entities.