new graph()

Contructor for a BBOP graph model graph.

TODO: make compilation piecewise with every added node and edge.

Returns

graph bbop model graph

Property

default_predicate

The predicate we'll use when none other is defined. You can probably safely ignore this if all of the edges in your graph are the same.

Methods

add_edge(edge)

Add an edge to the graph.

Parameter

Name Type Optional Description

edge

edge

 

edge to add to the graph

add_node(node)

Add a node to the graph.

Parameter

Name Type Optional Description

node

node

 

node to add to the graph

all_dangling() → Array

List all external nodes by referenced id.

Returns

Array array of strings: external nodes by id

all_edges() → Array

Returns an /original/ list of all added edges.

Returns

Array array of {edge}

all_nodes() → Array

Returns an /original/ list of all added nodes.

Returns

Array array of {node}

all_predicates() → Array

Returns an /original/ list of all added predicates.

Returns

Array array of predicates (strings)

clone() → graph

Create a clone of the graph.

Returns

graph bbop model graph

create_edge(subject, object, predicate) → edge

Create an edge for use in internal operations.

Parameters

Name Type Optional Description

subject

string

 

node id string or node

object

string

 

node id string or node

predicate

string

 

(optional) a user-friendly description of the node

Returns

edge bbop model edge

create_graph() → graph

Create a graph for use in internal operations.

Returns

graph bbop model graph

create_node(new_id, new_label) → node

Create a node for use in internal operations.

Parameters

Name Type Optional Description

new_id

string

 

a unique id for the node

new_label

string

 

(optional) a user-friendly description of the node

Returns

node new bbop model node

edges_to_nodes(in_edges, target) → Array

Translate an edge array into extant (node) bodies, switching on either 'subject' or 'object'.

This will return the /original/ nodes.

This will throw an error on any world issues that crop up.

Parameters

Name Type Optional Description

in_edges

Array

 

list if {edge} we want the subjects or objects of

target

String

 

'subject' or 'object'

Returns

Array list of {node}

get_ancestor_subgraph(nb_id_or_list, pid) → graph

Return new ancestors subgraph. Single id or id list as first argument. Predicate string/id is optional.

Parameters

Name Type Optional Description

nb_id_or_list

(String or Array)

 

the node id(s) to consider

pid

String

 

(optional) over this predicate

Returns

graph new bbop model graph

get_child_edges(nb_id, in_pred) → Array

Return all child edges; the /originals/. If no predicate is given, use the default one.

TODO: it might be nice to memoize this since others depend on it.

Parameters

Name Type Optional Description

nb_id

String

 

the node to consider

in_pred

String

 

(optional) over this predicate, defaults to all

Returns

Array array of

get_child_nodes(nb_id, in_pred) → Array

Return all child nodes; the /originals/. If no predicate is given, use the default one.

Parameters

Name Type Optional Description

nb_id

String

 

the node to consider

in_pred

String

 

(optional) over this predicate, defaults to all

Returns

Array list of {node}

get_descendent_subgraph(nb_id_or_list, pid) → graph

Return new descendents subgraph. Single id or id list as first argument. Predicate string/id is optional.

Parameters

Name Type Optional Description

nb_id_or_list

(String or Array)

 

the node id(s) to consider

pid

String

 

(optional) over this predicate

Returns

graph new bbop model graph

get_edge(sub_id, obj_id, pred) → edge

Return a /copy/ of an edge by ids (not the original) if extant.

Parameters

Name Type Optional Description

sub_id

string

 

the subject_id of the edge we're looking for

obj_id

string

 

the object_id of the edge we're looking for

pred

string

 

(optional) the predicate of the edge we're looking for

Returns

edge - copy of bbop model edge

get_edges(sub_id, obj_id) → Array

Return all edges (copies) of given subject and object ids. Returns entirely new edges.

Parameters

Name Type Optional Description

sub_id

String

 

the subject_id of the edge we're looking for

obj_id

String

 

the object_id of the edge we're looking for

Returns

Array list of

get_edges_by_object(obj_id) → Array

Return all edges (copies) of given object id. Returns entirely new edges.

Parameter

Name Type Optional Description

obj_id

String

 

the object_id of the edge we're looking for

Returns

Array list of

get_edges_by_subject(sub_id) → Array

Return all edges (copies) of given subject id. Returns entirely new edges.

Parameter

Name Type Optional Description

sub_id

String

 

the subject_id of the edge we're looking for

Returns

Array list of

get_leaf_nodes() → Array

Return a list of /copies/ of the leaf nodes.

BUG/TODO: Could I speed this up by my moving some of the calculation into the add_node and add_edge methods? O(|num(nodes)|)

Returns

Array list of {node}

get_node(nid) → node

Return a /copy/ of a node by id (not the original) if extant.

Parameter

Name Type Optional Description

nid

string

 

the id of the node we're looking for

Returns

node - copy of bbop model node

get_parent_edges(nb_id, in_pred) → Array

Return all parent edges; the /originals/. If no predicate is given, use the default one.

TODO: it might be nice to memoize this since others depend on it.

Parameters

Name Type Optional Description

nb_id

String

 

the node to consider

in_pred

String

 

(optional) over this predicate, defaults to all

Returns

Array array of

get_parent_nodes(nb_id, in_pred) → Array

Return all parent nodes; the /originals/. If no predicate is given, use the default one.

Parameters

Name Type Optional Description

nb_id

String

 

the node to consider

in_pred

String

 

(optional) over this predicate, defaults to all

Returns

Array list of {node}

get_predicates(sub_id, obj_id) → Array

Return all predicates of given subject and object ids.

Parameters

Name Type Optional Description

sub_id

String

 

the subject_id of the edge we're looking for

obj_id

String

 

the object_id of the edge we're looking for

Returns

Array list of predicate ids (as strings)

get_root_nodes() → Array

Return a list of /copies/ of the root nodes.

BUG/TODO: Could I speed this up by my moving some of the calculation into the add_node and add_edge methods? O(|num(nodes)|)

Returns

Array list of {node}

get_singleton_nodes() → Array

Find nodes that are roots and leaves over all relations. This returns the /original/ node.

Throws an error if there is a world issue.

Returns

Array array of {node}

id(value) → string

Getter/setter for the graph id.

Parameter

Name Type Optional Description

value

string

 

(optional) new value for this property to take

Returns

string string

is_complete() → Boolean

Any bad parts in graph? Essentially, make sure that there are no weird references and nothing is dangling.

Returns

Boolean boolean

is_leaf_node(nb_id) → boolean

Leaves are defined as nodes who are the object of nothing, independent of predicate.

Parameter

Name Type Optional Description

nb_id

string

 

id of the node to check

Returns

boolean - boolean

is_root_node(nb_id) → boolean

Roots are defined as nodes who are the subject of nothing, independent of predicate.

Parameter

Name Type Optional Description

nb_id

string

 

id of the node to check

Returns

boolean - boolean

is_topologically_equal(comp_graph) → Boolean

True or false on whether or not a graph shares the same structure as the current graph. This means that the (top-level) nodes have the same IDs and every edge connects in the same way.

This does not compare things like meta information, etc.

BUG/TODO: This should probably be moved to the superclass. Would have an easier time optimizing in there too.

Parameter

Name Type Optional Description

comp_graph

graph

 

graph to compare against

Returns

Boolean well is it?

load_base_json(json_object) → boolean

Load the graph from the specified JSON object (not string).

TODO: a work in progress 'type' not currently imported (just as not exported); actually, a lot not imported.

This is meant to be an minimal importer for a minimal format. Subclasses should use something else.

Parameter

Name Type Optional Description

json_object

object

 

JSON object

Returns

boolean - true; side-effects: creates the graph internally

merge_in(in_graph) → boolean

Add a graph to the current graph, without sharing any of the merged in graph's structure.

Parameter

Name Type Optional Description

in_graph

graph

 

graph

Returns

boolean - true; side-effects: more graph

remove_edge(subject_id, object_id, predicate_id) → Boolean

Remove an edge to the graph. The edge as referenced.

Parameters

Name Type Optional Description

subject_id

String

 

subject by ID

object_id

String

 

object by ID

predicate_id

String

 

(Optional) predicate ID or default

Returns

Boolean true if such an edge was found and deleted, false otherwise

remove_node(node_id, clean_p) → Boolean

Remove a node from the graph.

Parameters

Name Type Optional Description

node_id

String

 

the id for a node

clean_p

Boolean

 

(optional) remove all edges connects to node (default false)

Returns

Boolean true if node found and destroyed

to_json() → object

Dump out the graph into a JSON-able object.

TODO: a work in progress; 'type' not currently exported (just as not imported)

Returns

object - an object that can be converted to a JSON string by dumping.

walker(walking_fun, nb_id_or_list, pid) → Array

Return a list with two nested lists, the first is a list of nodes, the second is a list of edges.

The argument function takes a node id and 0 or 1 predicates, returns a list of edges from the node in question.

Parameters

Name Type Optional Description

walking_fun

function()

 

function as described above

nb_id_or_list

(String or Array)

 

the node id(s) to consider

pid

String

 

(optional) over this predicate

Returns

Array as described above