model.js

Summary
model.js
bbop.modelPurpose: Basic edged graph and operations.
Variables
default_predicateThe predicate we’ll use when none other is defined.
bbop.model.node
Functions
nodeContructor for a BBOP graph model node.
idGetter/setter for node id.
typeGetter/setter for node type.
labelGetter/setter for node label.
metadataGetter/setter for node metadata.
cloneGet a fresh new copy of the current node (using bbop.core.clone for metadata object).
bbop.model.edge
Functions
edgeContructor for a BBOP graph model edge.
subject_idGetter/setter for edge subject id.
object_idGetter/setter for edge object id.
predicate_idGetter/setter for edge predicate id.
typeGetter/setter for edge type.
metadataGetter/setter for edge metadata.
cloneGet a fresh new copy of the current edge (using bbop.core.clone for metadata object).
bbop.model.graph
Functions
graphContructor for a BBOP graph model graph.
idGetter/setter for the graph id.
add_nodeAdd a node to the graph.
add_edgeAdd an edge to the graph.
all_nodesReturns an /original/ list of all added nodes.
all_edgesReturns an /original/ list of all added edges.
all_predicatesReturns an /original/ list of all added predicates.
all_danglingList all external nodes by referenced id.
is_completeAny bad parts in graph? 
get_nodeReturn a /copy/ of a node by id (not the original) if extant.
get_edgeReturn a /copy/ of an edge by ids (not the original) if extant.
get_edgesReturn all edges (copies) of given subject and object ids.
get_predicatesReturn all predicates of given subject and object ids.
edges_to_nodesTranslate an edge array into extant (node) bodies, switching on either ‘subject’ or ‘object’.
is_root_nodeRoots are defined as nodes who are the subject of nothing, independent of predicate.
get_root_nodesReturn a list of /copies/ of the root nodes.
is_leaf_nodeLeaves are defined as nodes who are the object of nothing, independent of predicate.
get_leaf_nodesReturn a list of /copies/ of the leaf nodes.
get_singleton_nodesFind nodes that are roots and leaves over all relations.
get_parent_edgesReturn all parent edges; the /originals/.
get_parent_nodesReturn all parent nodes; the /originals/.
get_child_nodesReturn all child nodes; the /originals/.
get_ancestor_subgraphReturn new ancestors subgraph.
merge_inAdd a graph to the current graph, without sharing any of the merged in graph’s structure.
load_jsonLoad the graph from the specified JSON object (not string).
to_jsonDump out the graph into a JSON-able object.

bbop.model

Purpose: Basic edged graph and operations.

NOTE: A model instance may not be the whole graph, just a subgraph--this is the difference between nodes and named_nodes. nodes are real things, while named_nodes are things referenced by edges.

Check TODOs, we would like everything as linear as possible.

TODO: memoize everything but add_*.  Functional enough that it should work if we just empty the caches after every add_* op.

Required: bbop.core (core.js)

Summary
Variables
default_predicateThe predicate we’ll use when none other is defined.

Variables

default_predicate

bbop.model.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.

bbop.model.node

Summary
Functions
nodeContructor for a BBOP graph model node.
idGetter/setter for node id.
typeGetter/setter for node type.
labelGetter/setter for node label.
metadataGetter/setter for node metadata.
cloneGet a fresh new copy of the current node (using bbop.core.clone for metadata object).

Functions

node

bbop.model.node = function(new_id,
new_label)

Contructor for a BBOP graph model node.

Arguments

new_ida unique id for the node
new_label[optional] a user-friendly description of the node

Returns

bbop model node

id

bbop.model.node.prototype.id = function(value)

Getter/setter for node id.

Parameters

value[optional] new value for this property to take

Returns

string

type

bbop.model.node.prototype.type = function(value)

Getter/setter for node type.

Parameters

value[optional] new value for this property to take

Returns

string

label

bbop.model.node.prototype.label = function(value)

Getter/setter for node label.

Parameters

value[optional] new value for this property to take

Returns

string

metadata

bbop.model.node.prototype.metadata = function(value)

Getter/setter for node metadata.

The metadata value does not necessarily have to be an atomic type.

Parameters

value[optional] new value for this property to take

Returns

value

clone

bbop.model.node.prototype.clone = function()

Get a fresh new copy of the current node (using bbop.core.clone for metadata object).

Parameters

n/a

Returns

string

bbop.model.edge

Summary
Functions
edgeContructor for a BBOP graph model edge.
subject_idGetter/setter for edge subject id.
object_idGetter/setter for edge object id.
predicate_idGetter/setter for edge predicate id.
typeGetter/setter for edge type.
metadataGetter/setter for edge metadata.
cloneGet a fresh new copy of the current edge (using bbop.core.clone for metadata object).

Functions

edge

bbop.model.edge = function(subject,
object,
predicate)

Contructor for a BBOP graph model edge.

If no predicate is given, default_predicate is used.  Predicates are currently treated as raw strings.

Arguments

subjectnode id string or node
objectnode id string or node
predicate[optional] a user-friendly description of the node

Returns

bbop model edge

subject_id

bbop.model.edge.prototype.subject_id = function()

Getter/setter for edge subject id.

Parameters

value[optional] new value for this property to take

Returns

string

object_id

bbop.model.edge.prototype.object_id = function()

Getter/setter for edge object id.

Parameters

value[optional] new value for this property to take

Returns

string

predicate_id

bbop.model.edge.prototype.predicate_id = function()

Getter/setter for edge predicate id.

Parameters

value[optional] new value for this property to take

Returns

string

type

bbop.model.edge.prototype.type = function(value)

Getter/setter for edge type.

Parameters

value[optional] new value for this property to take

Returns

string

metadata

bbop.model.edge.prototype.metadata = function(value)

Getter/setter for edge metadata.

The metadata value does not necessarily have to be an atomic type.

Parameters

value[optional] new value for this property to take

Returns

value

clone

bbop.model.edge.prototype.clone = function()

Get a fresh new copy of the current edge (using bbop.core.clone for metadata object).

Parameters

n/a

Returns

string

bbop.model.graph

Summary
Functions
graphContructor for a BBOP graph model graph.
idGetter/setter for the graph id.
add_nodeAdd a node to the graph.
add_edgeAdd an edge to the graph.
all_nodesReturns an /original/ list of all added nodes.
all_edgesReturns an /original/ list of all added edges.
all_predicatesReturns an /original/ list of all added predicates.
all_danglingList all external nodes by referenced id.
is_completeAny bad parts in graph? 
get_nodeReturn a /copy/ of a node by id (not the original) if extant.
get_edgeReturn a /copy/ of an edge by ids (not the original) if extant.
get_edgesReturn all edges (copies) of given subject and object ids.
get_predicatesReturn all predicates of given subject and object ids.
edges_to_nodesTranslate an edge array into extant (node) bodies, switching on either ‘subject’ or ‘object’.
is_root_nodeRoots are defined as nodes who are the subject of nothing, independent of predicate.
get_root_nodesReturn a list of /copies/ of the root nodes.
is_leaf_nodeLeaves are defined as nodes who are the object of nothing, independent of predicate.
get_leaf_nodesReturn a list of /copies/ of the leaf nodes.
get_singleton_nodesFind nodes that are roots and leaves over all relations.
get_parent_edgesReturn all parent edges; the /originals/.
get_parent_nodesReturn all parent nodes; the /originals/.
get_child_nodesReturn all child nodes; the /originals/.
get_ancestor_subgraphReturn new ancestors subgraph.
merge_inAdd a graph to the current graph, without sharing any of the merged in graph’s structure.
load_jsonLoad the graph from the specified JSON object (not string).
to_jsonDump out the graph into a JSON-able object.

Functions

graph

Contructor for a BBOP graph model graph.

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

Arguments

n/a

Returns

bbop model node

id

bbop.model.graph.prototype.id = function(value)

Getter/setter for the graph id.

Parameters

value[optional] new value for this property to take

Returns

string

add_node

bbop.model.graph.prototype.add_node = function(node)

Add a node to the graph.

Parameters

nodenode to add to the graph

Returns

n/a

add_edge

bbop.model.graph.prototype.add_edge = function(edge)

Add an edge to the graph.

Parameters

edgeedge to add to the graph

Returns

n/a

all_nodes

bbop.model.graph.prototype.all_nodes = function()

Returns an /original/ list of all added nodes.

Parameters

n/a

Returns

array of nodes

all_edges

bbop.model.graph.prototype.all_edges = function()

Returns an /original/ list of all added edges.

Parameters

n/a

Returns

array of edges

all_predicates

bbop.model.graph.prototype.all_predicates = function()

Returns an /original/ list of all added predicates.

Parameters

n/a

Returns

array of predicates (strings)

all_dangling

bbop.model.graph.prototype.all_dangling = function()

List all external nodes by referenced id.

Parameters

n/a

Returns

array of extrnal nodes by id

is_complete

bbop.model.graph.prototype.is_complete = function()

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

Parameters

n/a

Returns

boolean

get_node

bbop.model.graph.prototype.get_node = function(nid)

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

Parameters

nidthe id of the node we’re looking for

Returns

bbop.model.node

get_edge

bbop.model.graph.prototype.get_edge = function(sub_id,
obj_id,
pred)

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

Parameters

sub_idthe subject_id of the edge we’re looking for
obj_idthe object_id of the edge we’re looking for
pred[optional] the predicate of the edge we’re looking for

Returns

bbop.model.edge

get_edges

bbop.model.graph.prototype.get_edges = function(sub_id,
obj_id)

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

Parameters

sub_idthe subject_id of the edge we’re looking for
obj_idthe object_id of the edge we’re looking for

Returns

list of bbop.model.edge

get_predicates

bbop.model.graph.prototype.get_predicates = function(sub_id,
obj_id)

Return all predicates of given subject and object ids.

Parameters

sub_idthe subject_id of the edge we’re looking for
obj_idthe object_id of the edge we’re looking for

Returns

list of predicate ids (as strings)

edges_to_nodes

bbop.model.graph.prototype.edges_to_nodes = function(in_edges,
target)

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

in_edgesthe edges we want the subjects or objects of
target’subject’ or ‘object’

Returns

array of bbop.model.node

is_root_node

bbop.model.graph.prototype.is_root_node = function(nb_id)

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

Parameters

nb_idid of the node to check

Returns

boolean

get_root_nodes

bbop.model.graph.prototype.get_root_nodes = function()

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(|#nodes|)

Parameters

n/a

Returns

array of bbop.model.node

is_leaf_node

bbop.model.graph.prototype.is_leaf_node = function(nb_id)

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

Parameters

nb_idid of the node to check

Returns

boolean

get_leaf_nodes

bbop.model.graph.prototype.get_leaf_nodes = function()

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(|#nodes|)

Parameters

n/a

Returns

array of bbop.model.node

get_singleton_nodes

bbop.model.graph.prototype.get_singleton_nodes = function()

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

Throws an error if there is a world issue.

Parameters

n/a

Returns

array of bbop.model.node

get_parent_edges

bbop.model.graph.prototype.get_parent_edges = function(nb_id,
in_pred)

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

nb_idthe node to consider
in_pred[optional] over this predicate

Returns

array of bbop.model.edge

get_parent_nodes

bbop.model.graph.prototype.get_parent_nodes = function(nb_id,
in_pred)

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

Parameters

nb_idthe node to consider
in_pred[optional] over this predicate

Returns

array of bbop.model.node

get_child_nodes

bbop.model.graph.prototype.get_child_nodes = function(nb_id,
in_pred)

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

Parameters

nb_idthe node to consider
in_pred[optional] over this predicate

Returns

array of bbop.model.node

get_ancestor_subgraph

bbop.model.graph.prototype.get_ancestor_subgraph = function(nb_id_or_list,
pid)

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

Parameters

nb_id_or_listthe node id(s) to consider
pid[optional] over this predicate

Returns

bbop.model.graph

merge_in

bbop.model.graph.prototype.merge_in = function(in_graph)

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

TODO: a work in progress ‘type’ not currently imported (just as not exported)

Parameters

bbop.model.graph

Returns

true; side-effects: more graph

load_json

bbop.model.graph.prototype.load_json = function(json_object)

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

TODO: a work in progress ‘type’ not currently imported (just as not exported)

Parameters

JSON object

Returns

true; side-effects: creates the graph internally

to_json

bbop.model.graph.prototype.to_json = function()

Dump out the graph into a JSON-able object.

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

Parameters

n/a

Returns

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

bbop.model.default_predicate
The predicate we’ll use when none other is defined.
bbop.model.node = function(new_id,
new_label)
Contructor for a BBOP graph model node.
bbop.model.node.prototype.id = function(value)
Getter/setter for node id.
bbop.model.node.prototype.type = function(value)
Getter/setter for node type.
bbop.model.node.prototype.label = function(value)
Getter/setter for node label.
bbop.model.node.prototype.metadata = function(value)
Getter/setter for node metadata.
bbop.model.node.prototype.clone = function()
Get a fresh new copy of the current node (using bbop.core.clone for metadata object).
bbop.model.edge = function(subject,
object,
predicate)
Contructor for a BBOP graph model edge.
bbop.model.edge.prototype.subject_id = function()
Getter/setter for edge subject id.
bbop.model.edge.prototype.object_id = function()
Getter/setter for edge object id.
bbop.model.edge.prototype.predicate_id = function()
Getter/setter for edge predicate id.
bbop.model.edge.prototype.type = function(value)
Getter/setter for edge type.
bbop.model.edge.prototype.metadata = function(value)
Getter/setter for edge metadata.
bbop.model.edge.prototype.clone = function()
Get a fresh new copy of the current edge (using bbop.core.clone for metadata object).
bbop.model.graph.prototype.id = function(value)
Getter/setter for the graph id.
bbop.model.graph.prototype.add_node = function(node)
Add a node to the graph.
bbop.model.graph.prototype.add_edge = function(edge)
Add an edge to the graph.
bbop.model.graph.prototype.all_nodes = function()
Returns an /original/ list of all added nodes.
bbop.model.graph.prototype.all_edges = function()
Returns an /original/ list of all added edges.
bbop.model.graph.prototype.all_predicates = function()
Returns an /original/ list of all added predicates.
bbop.model.graph.prototype.all_dangling = function()
List all external nodes by referenced id.
bbop.model.graph.prototype.is_complete = function()
Any bad parts in graph? 
bbop.model.graph.prototype.get_node = function(nid)
Return a /copy/ of a node by id (not the original) if extant.
bbop.model.graph.prototype.get_edge = function(sub_id,
obj_id,
pred)
Return a /copy/ of an edge by ids (not the original) if extant.
bbop.model.graph.prototype.get_edges = function(sub_id,
obj_id)
Return all edges (copies) of given subject and object ids.
bbop.model.graph.prototype.get_predicates = function(sub_id,
obj_id)
Return all predicates of given subject and object ids.
bbop.model.graph.prototype.edges_to_nodes = function(in_edges,
target)
Translate an edge array into extant (node) bodies, switching on either ‘subject’ or ‘object’.
bbop.model.graph.prototype.is_root_node = function(nb_id)
Roots are defined as nodes who are the subject of nothing, independent of predicate.
bbop.model.graph.prototype.get_root_nodes = function()
Return a list of /copies/ of the root nodes.
bbop.model.graph.prototype.is_leaf_node = function(nb_id)
Leaves are defined as nodes who are the object of nothing, independent of predicate.
bbop.model.graph.prototype.get_leaf_nodes = function()
Return a list of /copies/ of the leaf nodes.
bbop.model.graph.prototype.get_singleton_nodes = function()
Find nodes that are roots and leaves over all relations.
bbop.model.graph.prototype.get_parent_edges = function(nb_id,
in_pred)
Return all parent edges; the /originals/.
bbop.model.graph.prototype.get_parent_nodes = function(nb_id,
in_pred)
Return all parent nodes; the /originals/.
bbop.model.graph.prototype.get_child_nodes = function(nb_id,
in_pred)
Return all child nodes; the /originals/.
bbop.model.graph.prototype.get_ancestor_subgraph = function(nb_id_or_list,
pid)
Return new ancestors subgraph.
bbop.model.graph.prototype.merge_in = function(in_graph)
Add a graph to the current graph, without sharing any of the merged in graph’s structure.
bbop.model.graph.prototype.load_json = function(json_object)
Load the graph from the specified JSON object (not string).
bbop.model.graph.prototype.to_json = function()
Dump out the graph into a JSON-able object.
Close