API reference

generic functions (funs) module

gb.funs.build_symbol()

Build a concept symbol from text and a namespace.

gb.funs.edge2str()

Convert an edge to its string representation.

gb.funs.edge_depth()

Returns maximal depth of the edge, a symbol has depth 0

gb.funs.edge_size()

size of edge, if symbol size is 1

gb.funs.edge_symbols()

Return set of edge_symbols contained in edge.

gb.funs.edges2str()

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

gb.funs.hashed()

Creates an hash code for a string.

gb.funs.is_concept()

Checks if edge represents a concept, i.e. if it is a symbol or if it is an edge that starts with +/gb.

gb.funs.is_edge()

Checks if entity is an edge.

gb.funs.is_root()

Is the symbol the root of itself?

gb.funs.new_meaning()

Creates a new symbol for the given root. If given edge_symbols is not a root, return it unchanged.

gb.funs.split_edge_str()

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

gb.funs.str2edge()

Convert a string representation of an edge to an edge.

gb.funs.str2symbol()

Converts a string into a valid symbol

gb.funs.subedges()

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

gb.funs.symbol2str()

Converts a symbol into a string representation.

gb.funs.symbol_namespace()

Extracts the namespace of a symbol (e.g. the namespace of graphbrain/1 is 1) Returns None if symbol has no namespace.

gb.funs.symbol_parts()

Splits a symbol into its parts. All symbol types except CONCEPT only have one part.

gb.funs.symbol_root()

Extracts the root of a symbol (e.g. the root of graphbrain/1 is graphbrain)

gb.funs.symbol_type()

Type of symbol: CONCEPT, EDGE, INTEGER, FLOAT or URL

gb.funs.without_namespaces()

Returns edge stripped of namespaces

hypergraph module

class gb.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 edge_symbols 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)[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 gb.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 edge_symbols 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)[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 gb.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)[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 gb.backends.leveldb.LevelDB(params)[source]

Implements LevelDB hypergraph storage.

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

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

add_key(vert_key, attributes)[source]

Adds the given vertex, given its key.

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.

dec_attribute_key(vert_key, attribute)[source]

Decrements an attribute of a vertex.

dec_counter(counter, by=1)[source]

Decrements a counter.

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 vertex exists in the hypergraph.

exists_key(vertex_key)[source]

Checks if the given vertex 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.

inc_attribute_key(vert_key, attribute)[source]

Increments an attribute of a vertex.

inc_counter(counter, by=1)[source]

Increments a counter.

pattern2edges(pattern)[source]

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

read_counter(counter)[source]

Reads a counter by name.

read_counter_key(counter_key)[source]

Reads a counter by key.

remove(edge)[source]

Removes an edge from the hypergraph.

remove_edge_permutations(edge)[source]

Removes all permutations of the given edge.

remove_key(vert_key)[source]

Removes a vertex, given its key.

set_attribute(vertex, attribute, value)[source]

Sets the value of an attribute.

set_attribute_key(vert_key, attribute, value)[source]

Sets the value of an attribute by vertex_key.

star(center, limit=None)[source]

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

str2perms(center_id, limit=None)[source]

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

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

write_edge_permutations(edge)[source]

Writes all permutations of the given edge.

Null class

class gb.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)[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

reader package

Reader class

class gb.reader.reader.Reader(hg, stages=('hypergen-forest', 'disamb-naive', 'merge', 'shallow', 'concepts'), show_namespaces=False, lang='en', model_file=None)[source]

Semantic tree module – Tree class

class gb.reader.semantic_tree.Tree(elem=None)[source]

Semantic tree module – Element class

class gb.reader.semantic_tree.Element[source]

Semantic tree module – Leaf class

class gb.reader.semantic_tree.Leaf(token)[source]

Semantic tree module – Node class

class gb.reader.semantic_tree.Node(children_ids=None)[source]

ParserOutput class

class gb.reader.parser_output.ParserOutput(sentence, tree)[source]