API reference

generic functions (funs) module

graphbrain.funs.atom_parts()

Splits an atom into its parts.

graphbrain.funs.atoms()

Returns set of atoms contained in an entity.

graphbrain.funs.build_atom()

Build an atom from text and other parts.

graphbrain.funs.contains()

Checks if ‘needle’ is contained in entity.

graphbrain.funs.depth()

Returns maximal depth of an entity, an atom has depth 0.

graphbrain.funs.edges2str()

Convert a collection of edges to a string representation (no outer parenthesis).

graphbrain.funs.ent2str()

Convert an entity to its string representation.

graphbrain.funs.is_atom()

Checks if entity is an atom.

graphbrain.funs.is_edge()

Checks if entity is an edge.

graphbrain.funs.label()

Converts an atom into a string representation.

graphbrain.funs.root()

Extracts the root of an atom (e.g. the root of graphbrain/c/1 is graphbrain).

graphbrain.funs.roots()

Returns entity with root-only atoms.

graphbrain.funs.size()

Size of an entity, atom size is 1.

graphbrain.funs.split_edge_str()

Shallow split into tokens of a string representation of an edge, without outer parenthesis.

graphbrain.funs.str2atom()

Converts a string into a valid atom.

graphbrain.funs.str2ent()

Convert a string representation of an entity to an entity.

graphbrain.funs.subedges()

Returns all the subedges contained in the edge, including atoms and itself.

hypergraph module

class graphbrain.hypergraph.HyperGraph(params)[source]

Hypergraph operations.

add(edge, timestamp=-1)[source]

Adds and edge to the hypergraph if it does not exist yet.

add_belief(source, edge, timestamp=-1)[source]

A belif is a fact with a source. The fact is created as a normal edge if it does not exist yet. Another edge is created to assign the fact to the source.

all()[source]

Returns a lazy sequence of all the vertices in the hypergraph.

all_attributes()[source]

Returns a lazy sequence with a tuple for each vertex in the hypergraph. The first element of the tuple is the vertex itself, the second is a dictionary of attribute values (as strings).

dec_attribute(vertex, attribute)[source]

Increments an attribute of a vertex.

degree(vertex)[source]

Returns the degree of a vertex.

destroy()[source]

Erase the hypergraph.

edge_count()[source]

Total number of edge in the hypergraph

edges_with_symbols(symbols, root=None)[source]

Find all edges containing the given edge_symbols, and optionally a given root

ego(center)[source]

Returns all atoms directly connected to centre by hyperedges.

exists(vertex)[source]

Checks if the given edge exists in the hypergraph.

get_float_attribute(vertex, attribute, or_else=None)[source]

Returns attribute as float value.

get_int_attribute(vertex, attribute, or_else=None)[source]

Returns attribute as integer value.

get_str_attribute(vertex, attribute, or_else=None)[source]

Returns attribute as string.

inc_attribute(vertex, attribute)[source]

Increments an attribute of a vertex.

is_belief(edge)[source]

Check if hyperedge is a belief (has sources).

pattern2edges(pattern, open_ended=False)[source]

Return all the edges that match a pattern. A pattern is a collection of entity ids and wildcards (None).

remove(edge)[source]

Removes and edge from the hypergraph.

remove_belief(source, edge)[source]

A belif is a fact with a source. The link from the source to the fact is removed. If no more sources support the fact, then the fact is also removed.

remove_by_pattern(pattern)[source]

Removes from the hypergraph all edges that match the pattern.

set_attribute(vertex, attribute, value)[source]

Sets the value of an attribute.

sources(edge)[source]

Set of sources (nodes) that support a statement (edge).

star(center, limit=None)[source]

Return all the edges that contain a given entity. Entity can be atomic or an edge.

symbol_count()[source]

Total number of edge_symbols in the hypergraph

symbols_with_root(root)[source]

Find all edge_symbols with the given root.

timestamp(vertex)[source]

Returns the timestamp of a vertex.

total_degree()[source]

Total degree of the hypergraph

class graphbrain.hypergraph.HyperGraph(params)[source]

Hypergraph operations.

add(edge, timestamp=-1)[source]

Adds and edge to the hypergraph if it does not exist yet.

add_belief(source, edge, timestamp=-1)[source]

A belif is a fact with a source. The fact is created as a normal edge if it does not exist yet. Another edge is created to assign the fact to the source.

all()[source]

Returns a lazy sequence of all the vertices in the hypergraph.

all_attributes()[source]

Returns a lazy sequence with a tuple for each vertex in the hypergraph. The first element of the tuple is the vertex itself, the second is a dictionary of attribute values (as strings).

dec_attribute(vertex, attribute)[source]

Increments an attribute of a vertex.

degree(vertex)[source]

Returns the degree of a vertex.

destroy()[source]

Erase the hypergraph.

edge_count()[source]

Total number of edge in the hypergraph

edges_with_symbols(symbols, root=None)[source]

Find all edges containing the given edge_symbols, and optionally a given root

ego(center)[source]

Returns all atoms directly connected to centre by hyperedges.

exists(vertex)[source]

Checks if the given edge exists in the hypergraph.

get_float_attribute(vertex, attribute, or_else=None)[source]

Returns attribute as float value.

get_int_attribute(vertex, attribute, or_else=None)[source]

Returns attribute as integer value.

get_str_attribute(vertex, attribute, or_else=None)[source]

Returns attribute as string.

inc_attribute(vertex, attribute)[source]

Increments an attribute of a vertex.

is_belief(edge)[source]

Check if hyperedge is a belief (has sources).

pattern2edges(pattern, open_ended=False)[source]

Return all the edges that match a pattern. A pattern is a collection of entity ids and wildcards (None).

remove(edge)[source]

Removes and edge from the hypergraph.

remove_belief(source, edge)[source]

A belif is a fact with a source. The link from the source to the fact is removed. If no more sources support the fact, then the fact is also removed.

remove_by_pattern(pattern)[source]

Removes from the hypergraph all edges that match the pattern.

set_attribute(vertex, attribute, value)[source]

Sets the value of an attribute.

sources(edge)[source]

Set of sources (nodes) that support a statement (edge).

star(center, limit=None)[source]

Return all the edges that contain a given entity. Entity can be atomic or an edge.

symbol_count()[source]

Total number of edge_symbols in the hypergraph

symbols_with_root(root)[source]

Find all edge_symbols with the given root.

timestamp(vertex)[source]

Returns the timestamp of a vertex.

total_degree()[source]

Total degree of the hypergraph

backends package

Backend class

class graphbrain.backends.backend.Backend[source]

Hypergraph low-level operations.

add(edge, timestamp=-1)[source]

Adds an edges to the hypergraph if it does not exist yet.

all()[source]

Returns a lazy sequence of all the vertices in the hypergraph.

all_attributes()[source]

Returns a lazy sequence with a tuple for each vertex in the hypergraph. The first element of the tuple is the vertex itself, the second is a dictionary of attribute values (as strings).

dec_attribute(vertex, attribute)[source]

Decrements an attribute of a vertex.

degree(vertex)[source]

Returns the degree of a vertex.

destroy()[source]

Erase the hypergraph.

edge_count()[source]

Total number of edge in the hypergraph

edges_with_symbols(symbols, root=None)[source]

Find all edges containing the given edge_symbols, and optionally a given root

exists(vertex)[source]

Checks if the given edge exists in the hypergraph.

get_float_attribute(vertex, attribute, or_else=None)[source]

Returns attribute as float value.

get_int_attribute(vertex, attribute, or_else=None)[source]

Returns attribute as integer value.

get_str_attribute(vertex, attribute, or_else=None)[source]

Returns attribute as string.

inc_attribute(vertex, attribute)[source]

Increments an attribute of a vertex.

pattern2edges(pattern, open_ended)[source]

Return all the edges that match a pattern. A pattern is a collection of entity ids and wildcards (None).

remove(edge)[source]

Removes an edges from the hypergraph.

set_attribute(vertex, attribute, value)[source]

Sets the value of an attribute.

star(center)[source]

Return all the edges that contain a given entity. Entity can be atomic or an edge.

symbol_count()[source]

Total number of edge_symbols in the hypergraph

symbols_with_root(root)[source]

Find all edge_symbols with the given root.

timestamp(vertex)[source]

Returns the timestamp of a vertex.

total_degree()[source]

Total degree of the hypergraph

LevelDB class

class graphbrain.backends.leveldb.LevelDB

Implements LevelDB hypergraph storage.

add

Adds an edge to the hypergraph if it does not exist yet.

add_key

Adds the given vertex, given its key.

all

Returns a lazy sequence of all the vertices in the hypergraph.

all_attributes

Returns a lazy sequence with a tuple for each vertex in the hypergraph. The first element of the tuple is the vertex itself, the second is a dictionary of attribute values (as strings).

dec_attribute

Decrements an attribute of a vertex.

dec_attribute_key

Decrements an attribute of a vertex.

dec_counter

Decrements a counter.

degree

Returns the degree of a vertex.

destroy

Erase the hypergraph.

edge_count

Total number of edge in the hypergraph

edges_with_symbols

Find all edges containing the given edge_symbols, and optionally a given root

exists

Checks if the given vertex exists in the hypergraph.

exists_key

Checks if the given vertex exists in the hypergraph.

inc_attribute

Increments an attribute of a vertex.

inc_attribute_key

Increments an attribute of a vertex.

inc_counter

Increments a counter.

pattern2edges

Return all the edges that match a pattern. A pattern is a collection of entity ids and wildcards (None).

read_counter

Reads a counter by name.

read_counter_key

Reads a counter by key.

remove

Removes an edge from the hypergraph.

remove_edge_permutations

Removes all permutations of the given edge.

remove_key

Removes a vertex, given its key.

set_attribute

Sets the value of an attribute.

set_attribute_key

Sets the value of an attribute by vertex_key.

star

Return all the edges that contain a given entity. Entity can be atomic or an edge.

str2perms

Query database for all the edge permutations that contain a given entity, represented as a string.

symbol_count

Total number of edge_symbols in the hypergraph

symbols_with_root

Find all edge_symbols with the given root.

timestamp

Returns the timestamp of a vertex.

total_degree

Total degree of the hypergraph

write_edge_permutations

Writes all permutations of the given edge.

Null class

class graphbrain.backends.null.Null[source]

Hypergraph low-level operations.

add(edge, timestamp=-1)[source]

Adds an edges to the hypergraph if it does not exist yet.

all()[source]

Returns a lazy sequence of all the vertices in the hypergraph.

all_attributes()[source]

Returns a lazy sequence with a tuple for each vertex in the hypergraph. The first element of the tuple is the vertex itself, the second is a dictionary of attribute values (as strings).

dec_attribute(vertex, attribute)[source]

Decrements attribute of a vertex.

degree(vertex)[source]

Returns the degree of a vertex.

destroy()[source]

Erase the hypergraph.

edge_count()[source]

Total number of edge in the hypergraph

edges_with_symbols(symbols, root=None)[source]

Find all edges containing the given edge_symbols, and optionally a given root

exists(vertex)[source]

Checks if the given edge exists in the hypergraph.

get_float_attribute(vertex, attribute, or_else=None)[source]

Returns attribute as float value.

get_int_attribute(vertex, attribute, or_else=None)[source]

Returns attribute as integer value.

get_str_attribute(vertex, attribute, or_else=None)[source]

Returns attribute as string.

inc_attribute(vertex, attribute)[source]

Increments attribute of a vertex.

pattern2edges(pattern, open_ended)[source]

Return all the edges that match a pattern. A pattern is a collection of entity ids and wildcards (None).

remove(edge)[source]

Removes an edges from the hypergraph.

set_attribute(vertex, attribute, value)[source]

Sets the value of an attribute.

star(center, limit=None)[source]

Return all the edges that contain a given entity. Entity can be atomic or an edge.

symbol_count()[source]

Total number of edge_symbols in the hypergraph

symbols_with_root(root)[source]

Find all edge_symbols with the given root.

timestamp(vertex)[source]

Returns the timestamp of a vertex.

total_degree()[source]

Total degree of the hypergraph

meaning package

Parser class

class graphbrain.meaning.Parser(lang, pos=False)[source]