bento_meta.model

This module contains Model, a class for managing data models housed in the Bento Metamodel Database. Models are built from bento_meta.Entity subclasses (see bento_meta.objects). A Model can be used with or without a Neo4j database connection.

Module Contents

Classes

Model

class bento_meta.model.Model(handle=None, mdb=None)[source]

Bases: object

property drv

Neo4j database driver from MDB object

property mdb
classmethod versioning(on=None)[source]

Get or set versioning state.

Parameters:

on (boolean) – True, apply versioning. False, do not.

Note: this delegates to Entity.versioning().

classmethod set_version_count(ct)[source]

Set the integer version counter.

Parameters:

ct (int) – Set version counter to this value.

Note: this delegates to Entity.set_version_count().

add_node(node=None)[source]

Add a Node to the model.

Parameters:

node (Node) – A Node instance, a neo4j.graph.Node, or a dict

The model attribute of node is set to Model.handle

add_edge(edge=None)[source]

Add an Edge to the model.

Parameters:

edge (Edge) – A Edge instance, a neo4j.graph.Node, or a dict

The model attribute of edge is set to Model.handle

add_prop(ent, prop=None)[source]

Add a Property to the model.

Parameters:
  • ent (Node|Edge) – Attach prop to this entity

  • prop (Property) – A Property instance, a :class: neo4j.graph.Node, or a dict

  • reuse (boolean) – If True, reuse existing property with same handle

The model attribute of prop is set to Model.handle. Within a model, Property entities are unique with respect to their handle (but can be reused). This method will look for an existing property within the model with the given handle, and add an item to Model.props pointing to it if found.

annotate(ent, term)[source]

Associate a single Term with an Entity. This creates a Concept entity if needed and links both the Entity and the Term to the concept, in keeping with the MDB spec. It supports the Term key in MDF. :param Entity ent: Entity object to annotate :param Term term: Term object to describe the Entity

add_terms(prop, *terms)[source]

Add a list of Term and/or strings to a Property with a value domain of value_set

Parameters:

Term instances are created for strings; Term.value and Term.handle is set to the string.

rm_node(node)[source]

Remove a Node from the Model instance.

Parameters:

node (Node) – Node to be removed

Note: A node can’t be removed if it is participating in an edge (i.e., if the node is some edge’s src or dst attribute)

Clarify what happens in the Model object, in the database when versioning is off, in the database when versioning is on

rm_edge(edge)[source]

Remove an Edge instance from the Model instance.

Parameters:

edge (Edge) – Edge to be removed

Clarify what happens in the Model object, in the database when versioning is off, in the database when versioning is on

rm_prop(prop)[source]

Remove a Property instance from the Model instance.

Parameters:

prop (Property) – Property to be removed

Clarify what happens in the Model object, in the database when versioning is off, in the database when versioning is on

rm_term(term)[source]

Not implemented.

assign_edge_end(edge=None, end=None, node=None)[source]

Move the src or dst of an Edge to a different Node.

Parameters:
  • edge (Edge) – Edge to manipulate

  • end (str) – Edge end to change (src|dst)

  • node (Node) – Node to be connected

Note: Both node and edge must be present in the Model instance (via add_node() and add_edge())

contains(ent)[source]

Ask whether an entity is present in the Model instance.

Parameters:

ent (Entity) – Entity in question

Note: Only works on Nodes, Edges, and Properties

edges_in(node)[source]

Get all Edge that have a given Node as their dst attribute

Parameters:

node (Node) – The node

Returns:

list of Edge

edges_out(node)[source]

Get all Edge that have a given Node as their src attribute

Parameters:

node (Node) – The node

Returns:

list of Edge

edges_by(key, item)[source]
edges_by_src(node)[source]

Get all Edge that have a given Node as their src attribute

Parameters:

node (Node) – The node

Returns:

list of Edge

edges_by_dst(node)[source]

Get all Edge that have a given Node as their dst attribute

Parameters:

node (Node) – The node

Returns:

list of Edge

edges_by_type(edge_handle)[source]

Get all Edge that have a given edge type (i.e., handle)

Parameters:

edge_handle (str) – The edge type

Returns:

list of Edge

dget(refresh=False)[source]

Pull model from MDB into this Model instance, based on its handle

Note: is a noop if Model.mdb is unset.

dput()[source]

Push this Model’s objects to MDB.

Note: is a noop if Model.mdb is unset.