API reference
main functions
- graphbrain.__init__.hedge(source)
Create a hyperedge.
hyperedge module
- class graphbrain.hyperedge.Atom(edge, parens=False)
Atomic hyperedge.
- all_atoms()
Returns a list of all the atoms contained in the edge. Unlike atoms(), which does not return repeated atoms, all_atoms() does return repeated atoms if they are different objects.
For example, consider the edge: (the/Md (of/Br mayor/Cc (the/Md city/Cs))) in this case, edge.all_atoms() returns: [the/Md, of/Br, mayor/Cc, the/Md, city/Cs]
- argroles()
Returns the argument roles string of the edge, if it exists. Otherwise returns empty string.
Argument roles can be return for the entire edge that they apply to, which can be a relation (R) or a concept (C). For example:
((not/M is/P.sc) bob/C sad/C) has argument roles “sc”, (of/B.ma city/C berlin/C) has argument roles “ma”.
Argument roles can also be returned for the connectors that define the outer edge, which can be of type predicate (P) or builder (B). For example:
(not/M is/P.sc) has argument roles “sc”, of/B.ma has argument roles “ma”.
- property atom
True if edge is an atom.
- atom_with_type(atom_type)
Returns the first atom found in the edge that has the given ‘atom_type’, or whose type starts with ‘atom_type’. If no such atom is found, returns None.
For example, given the edge (+/B a/Cn b/Bp) and the ‘atom_type’ C, this function returns: a/Cn If the ‘atom_type’ is ‘Cp’, the it will return: b/Cp
- atoms()
Returns the set of atoms contained in the edge.
For example, consider the edge: (the/Md (of/Br mayor/Cc (the/Md city/Cs))) in this case, edge.atoms() returns: [the/Md, of/Br, mayor/Cc, city/Cs]
- connector_atom()
The inner atom of the connector.
For example, condider: (does/M (not/M like/P.so) john/C chess/C) The connector atom is: like/P.so
The connector atom of an atom is None.
- connector_type()
Returns the type of the edge’s connector. If the edge has no connector (i.e. it’s an atom), then None is returned.
- contains(needle, deep=False)
Checks if ‘needle’ is contained in edge.
Keyword argument: deep – search recursively (default: False)
- depth()
Returns maximal depth of edge, an atom has depth 0.
- edges_with_argrole(argrole)
Returns the list of edges with the given argument role
- inner_atom()
The inner atom inside of a modifier structure.
For example, condider: (red/M shoes/C) The inner atom is: shoes/C Or, the more complex case: ((and/J slow/M steady/M) go/P) Yields: gp/P
This method should not be used on structures that contain more than one inner atom, for example concepts constructed with builders or relations.
The inner atom of an atom is itself.
- insert_argrole(argrole, pos)
Returns an atom with the given argrole inserted at the specified position. Same restrictions as in replace_argroles() apply.
- insert_first_argument(argument)
Returns an edge built by placing ‘argument’ as the first item after the connector of this edge. If this edge is an atom, then it becomes the connector of the returned edge.
For example, considering the ‘edge’ (a) and the ‘argument’ (b), this function returns: (a b)
Considering the ‘edge’ (a b c) and the ‘argument’ (d e), it returns: (a (d e) b c)
- is_atom()
Deprecated since version 0.6.0: Please use the properties .atom and .not_atom instead.
Checks if edge is an atom.
- label()
Generate human-readable label from entity.
- main_concepts()
Returns the list of main concepts in an concept edge. A main concept is a central concept in a built concept, e.g.: in (‘s/Bp.am zimbabwe/Mp economy/Cn.s), economy/Cn.s is the main concept.
If entity is not an edge, or its connector is not of type builder, or the builder does not contain concept role annotations, or no concept is annotated as the main one, then an empty list is returned.
- property not_atom
True if edge is not an atom.
- parts()
Splits atom into its parts.
- replace_argroles(argroles)
Returns an atom with the argroles replaced with the provided string. Returns same atom if the atom does not contain a role part.
- replace_atom(old, new, unique=False)
Returns edge built by replacing every instance of ‘old’ in this edge with ‘new’.
Keyword argument: unique – match only the exact same instance of the atom, i.e. UniqueAtom(self) == UniqueAtom(old) (default: False)
- replace_atom_part(part_pos, part)
Build a new atom by replacing an atom part in a given atom.
- replace_main_concept(new_main)
TODO: document and test
- role()
Returns the role of this atom as a list of the subrole strings.
The role of an atom is its second part, right after the root. A dot notation is used to separate the subroles. For example, the role of graphbrain/Cp.s/1 is:
Cp.s
For this case, this function returns:
[‘Cp’, ‘s’]
If the atom only has a root, it is assumed to be a conjunction. In this case, this function returns the role with just the generic conjunction type:
[‘J’].
- root()
Extracts the root of an atom (e.g. the root of graphbrain/C/1 is graphbrain).
- roots()
Returns edge with root-only atoms.
- simplify(subtypes=False, argroles=False, namespaces=True)
Returns a simplified version of the atom, for example removing subtypes, subroles or namespaces.
Keyword arguments: subtypes – include subtype (default: False). argroles –include argroles (default: False). namespaces – include namespaces (default: True).
- size()
The size of an edge is its total number of atoms, at all depths.
- subedges()
Returns all the subedges contained in the edge, including atoms and itself.
- to_str(roots_only=False)
Converts atom to its string representation.
Keyword argument: roots_only – only the roots of the atoms will be used to create the string representation.
- type()
Returns the type of the atom.
The type of an atom is its first subrole. For example, the type of graphbrain/Cp.s/1 is ‘Cp’.
If the atom only has a root, it is assumed to be a conjunction. In this case, this function returns the generic conjunction type: ‘J’.
- class graphbrain.hyperedge.Hyperedge(edges)
Non-atomic hyperedge.
- all_atoms()
Returns a list of all the atoms contained in the edge. Unlike atoms(), which does not return repeated atoms, all_atoms() does return repeated atoms if they are different objects.
For example, consider the edge: (the/md (of/br mayor/cc (the/md city/cs))) in this case, edge.all_atoms() returns: [the/md, of/br, mayor/cc, the/md, city/cs]
- argroles()
Returns the argument roles string of the edge, if it exists. Otherwise returns empty string.
Argument roles can be return for the entire edge that they apply to, which can be a relation (R) or a concept (C). For example:
((not/M is/P.sc) bob/C sad/C) has argument roles “sc”, (of/B.ma city/C berlin/C) has argument roles “ma”.
Argument roles can also be returned for the connectors that define the outer edge, which can be of type predicate (P) or builder (B). For example:
(not/M is/P.sc) has argument roles “sc”, of/B.ma has argument roles “ma”.
- property atom
True if edge is an atom.
- atom_with_type(atom_type)
Returns the first atom found in the edge that has the given ‘atom_type’, or whose type starts with ‘atom_type’. If no such atom is found, returns None.
For example, given the edge (+/B a/Cn b/Cp) and the ‘atom_type’ c, this function returns: a/Cn If the ‘atom_type’ is ‘Cp’, the it will return: b/Cp
- atoms()
Returns the set of atoms contained in the edge.
For example, consider the edge: (the/md (of/br mayor/cc (the/md city/cs))) in this case, edge.atoms() returns: [the/md, of/br, mayor/cc, city/cs]
- property cmt
Edge connector main type. (this porperty is a shortcut for Hyperedge.mconnector_type())
- connect(arguments)
Returns an edge built by adding the items in ‘arguments’ to the end of this edge. ‘arguments’ must be a collection.
For example, connecting the edge (a b) with the ‘arguments’ (c d) produces: (a b c d)
- connector_atom()
The inner atom of the connector.
For example, condider: (does/M (not/M like/P.so) john/C chess/C) The connector atom is: like/P.so
The connector atom of an atom is None.
- connector_mtype()
Returns the main type of the edge’s connector. If the edge has no connector (i.e. it’s an atom), then None is returned.
- connector_type()
Returns the type of the edge’s connector. If the edge has no connector (i.e. it’s an atom), then None is returned.
- contains(needle, deep=False)
Checks if ‘needle’ is contained in edge.
Keyword argument: deep – search recursively (default False)
- contains_atom_type(atom_type)
Checks if the edge contains any atom with the given type. The edge is searched recursively, so the atom can appear at any depth.
- property ct
Edge connector type. (this porperty is a shortcut for Hyperedge.connector_type())
- depth()
Returns maximal depth of edge, an atom has depth 0.
- edges_with_argrole(argrole)
Returns the list of edges with the given argument role.
- has_argroles()
Returns True if the edge has argroles, False otherwise.
- inner_atom()
The inner atom inside of a modifier structure.
For example, condider: (red/M shoes/C) The inner atom is: shoes/C Or, the more complex case: ((and/J slow/M steady/M) go/P) Yields: gp/P
This method should not be used on structures that contain more than one inner atom, for example concepts constructed with builders or relations.
The inner atom of an atom is itself.
- insert_argrole(argrole, pos)
Returns an edge with the given argrole inserted at the specified position in the argroles of the connector atom. Same restrictions as in replace_argroles() apply.
- insert_edge_with_argrole(edge, argrole, pos)
Returns a new edge with the provided edge and its argroles inserted at the specified position.
- insert_first_argument(argument)
Returns an edge built by placing ‘argument’ as the first item after the connector of this edge. If this edge is an atom, then it becomes the connector of the returned edge.
For example, considering the ‘edge’ (a) and the ‘argument’ (b), this function returns: (a b)
Considering the ‘edge’ (a b c) and the ‘argument’ (d e), it returns: (a (d e) b c)
- is_atom()
Deprecated since version 0.6.0: Please use the properties .atom and .not_atom instead.
Checks if edge is an atom.
- label()
Generate human-readable label for edge.
- main_concepts()
Returns the list of main concepts in an concept edge. A main concept is a central concept in a built concept, e.g.: in (‘s/Bp.am zimbabwe/Cp economy/Cn.s), economy/Cn.s is the main concept.
If entity is not an edge, or its connector is not of type builder, or the builder does not contain concept role annotations, or no concept is annotated as the main one, then an empty list is returned.
- property mt
Edge main type. (this porperty is a shortcut for Hyperedge.mtype())
- mtype()
Returns the main type of this edge as a string of one character. Type inference is performed.
- property not_atom
True if edge is not an atom.
- replace_argroles(argroles)
Returns an edge with the argroles of the connector atom replaced with the provided string. Returns same edge if the atom does not contain a role part.
- replace_atom(old, new, unique=False)
Returns edge built by replacing every instance of ‘old’ in this edge with ‘new’.
Keyword argument: unique – match only the exact same instance of the atom, i.e. UniqueAtom(self) == UniqueAtom(old) (default: False)
- replace_main_concept(new_main)
TODO: document and test
- roots()
Returns edge with root-only atoms.
- sequence(entity, before, flat=True)
Returns an edge built by sequencing the ‘entity’, if it’s an atom, or the elements of ‘entity’ if it is an edge, either before or after the elements of this edge.
If flat is False, then both this edge and ‘entity’ are treated as self-contained edges when building the new edge.
For example, connecting the edge (a b) and the ‘entity’ c produces, if before is True: (c a b) and if before is False: (a b c) Connecting the edge (a b) and the ‘entity’ (c d) produces, if before is True: (c d a b) and if before is False: (a b c d) This last example, if ‘flat’ is False, becomes respectively: ((c d) (a b)) ((a b) (c d))
- simplify(subtypes=False, argroles=False, namespaces=True)
Returns a version of the edge with simplified atoms, for example removing subtypes, subroles or namespaces.
Keyword arguments: subtypes – include subtypes (default: False). argroles –include argroles (default: False). namespaces – include namespaces (default: True).
- size()
The size of an edge is its total number of atoms, at all depths.
- subedges()
Returns all the subedges contained in the edge, including atoms and itself.
- property t
Edge type. (this porperty is a shortcut for Hyperedge.type())
- to_str(roots_only=False)
Converts edge to its string representation.
Keyword argument: roots_only – only the roots of the atoms will be used to create the string representation.
- type()
Returns the type of this edge as a string. Type inference is performed.
- class graphbrain.hyperedge.UniqueAtom(atom)
- graphbrain.hyperedge.build_atom(text, *parts)
Build an atom from text and other parts.
- graphbrain.hyperedge.hedge(source)
Create a hyperedge.
- graphbrain.hyperedge.split_edge_str(edge_str)
Shallow split into tokens of a string representation of an edge, without outer parenthesis.
- graphbrain.hyperedge.str2atom(s)
Converts a string into a valid atom.
hypergraph module
- class graphbrain.hypergraph.Hypergraph[source]
Hypergraph interface.
- add(edge, primary=True, count=False)[source]
Adds an edge if it does not exist yet, returns same edge. All children are recursively added as non-primary edge, for indexing purposes.
Edges can be passed in both Hyperedge or string format.
Keyword arguments: primary – edge is primary, meaning, for example, that it counts towards degrees. Non-primary edges are used for indexing purposes, for example to make it easy to find the subedges contained in primary edges when performing queries. count – an integer counter attribute is added to the edge. If the edge already exists, the counter is incremented.
- add_with_attributes(edge, attributes)[source]
Adds an edge along with all its attributes, represented as a dictionary of attribute names to values.
- all_attributes()[source]
Returns a generator with a tuple for each edge. The first element of the tuple is the edge itself, the second is a dictionary of attribute values (as strings).
- count(pattern: Hyperedge | str | list | tuple) int [source]
Number of edges that match a pattern. See search() method for an explanation of patterns.
Keyword argument: strict – if True atoms are matched exactly and search is faster. If False, atoms in the pattern can match more specific versions, e.g.: apple/C in the pattern will match apple/Cc.s/en (default: False)
- edges_with_edges(edges, root=None)[source]
Returns generator of all edges containing the given edges, and optionally a given root.
Keyword argument: root – edge must also contain an atom with this root (default None)
- get_float_attribute(edge, attribute, or_else=None)[source]
Returns attribute as float value.
- or_else – value to return if the entity does not have
the give attribute. (default None)
- get_int_attribute(edge, attribute, or_else=None)[source]
Returns attribute as integer value.
- or_else – value to return if the entity does not have
the give attribute. (default None)
- get_str_attribute(edge, attribute, or_else=None)[source]
Returns attribute as string.
Keyword argument: or_else – value to return if the entity does not have the given attribute. (default None)
- inc_attribute(edge, attribute)[source]
Increments an attribute of an entity, sets initial value to 1 if attribute does not exist.
- remove(edge, deep=False)[source]
Removes an edge.
Keyword argument: deep – recursively remove all subedges (default False)
- remove_by_pattern(pattern, strict=False)[source]
Removes all edges that match the pattern.
Keyword argument: strict – if True atoms are matched exactly and search is faster. If False, atoms in the pattern can match more specific versions, e.g.: apple/C in the pattern will match apple/Cc.s/en (default: False)
- root_degrees(edge)[source]
Finds all the atoms that share the same root as the given edge and computes the sum of both their degrees and deep degrees. These two sums are returned.
If the parameter edge is non-atomic, this function simply returns the degree and deep degree of that edge.
- search(pattern: Hyperedge | str | list | tuple, strict: bool = False, ref_edges: list[Hyperedge | str | list | tuple] | None = None) Iterator[Hyperedge] [source]
Returns generator for all the edges that match a pattern.
Patterns are themselves edges. They can match families of edges by employing special atoms: -> ‘*’ represents a general wildcard (matches any edge) -> ‘.’ represents an atomic wildcard (matches any atom) -> ‘(*)’ represents a non-atomic wildcard (matches any non-atom) -> ‘…’ at the end indicates an open-ended pattern.
The pattern can be a string, that must represent an edge. Examples: ‘(is/Pd graphbrain/C .)’ ‘(says/pd * …)’
Atomic patterns can also be used to match all edges in the hypergraph: , all atoms: ., and all non-atoms: ().
Keyword argument: strict – if True atoms are matched exactly and search is faster. If False, atoms in the pattern can match more specific versions, e.g.: apple/C in the pattern will match apple/Cc.s/en (default: False)
- sequence(name)[source]
Returns an iterator for a sequence of hyperedges, given the name of the sequence.
- set_primary(edge, value)[source]
Make edge primary if value is True, make it non-primary otherwise.
- star(center, limit=None)[source]
Returns generator of the edges that contain the center.
Keyword argument: limit – maximum number of results to return, infinite if None
patterns module
- graphbrain.patterns.edge_matches_pattern(edge: Hyperedge | str | list | tuple, pattern: Hyperedge | str | list | tuple, ref_edges: List[Hyperedge | str | list | tuple] | None = None, hg: Hypergraph | None = None)
Check if an edge matches a pattern.
Patterns are themselves edges. They can match families of edges by employing special atoms:
-> ‘*’ represents a general wildcard (matches any entity)
-> ‘.’ represents an atomic wildcard (matches any atom)
-> ‘(*)’ represents an edge wildcard (matches any edge)
-> ‘…’ at the end indicates an open-ended pattern.
The pattern can be any valid hyperedge, including the above special atoms. Examples: (is/Pd graphbrain/C .) (says/Pd * …)
- graphbrain.patterns.is_full_pattern(edge)
Check if every atom is a pattern matcher.
Pattern matcher are: ‘*’, ‘.’, ‘(*)’, ‘…’, variables (atom label starting with an uppercase letter) and functional patterns.
- graphbrain.patterns.is_pattern(edge)
Check if this edge defines a pattern, i.e. if it includes at least one pattern matcher.
Pattern matcher are: - ‘*’, ‘.’, ‘(*)’, ‘…’ - variables (atom label starting with an uppercase letter) - argument role matcher (unordered argument roles surrounded by curly brackets) - functional patterns (var, atoms, lemma, …)
- graphbrain.patterns.is_unordered_pattern(edge)
Check if this edge defines an unordered pattern, i.e. if it includes at least one instance of unordered argument roles surrounded by curly brackets.
- graphbrain.patterns.is_wildcard(atom)
Check if this atom defines a wildcard, i.e. if its root is a pattern matcher. (*, ., …, if it is surrounded by parenthesis or variable label starting with an uppercase letter)
- graphbrain.patterns.match_pattern(edge: Hyperedge | str | list | tuple, pattern: Hyperedge | str | list | tuple, curvars: dict[str, Hyperedge] | None = None, ref_edges: List[Hyperedge | str | list | tuple] | None = None, skip_semsim: bool = True, hg: Hypergraph | None = None) List[Dict]
Matches an edge to a pattern. This means that, if the edge fits the pattern, then a list of dictionaries will be returned. If the pattern specifies variables, then the returned dictionaries will be populated with the values for each pattern variable. There can be more than one dictionary in the list if there are multiple ways of matching the variables. If the pattern specifies no variables but the edge matches it, then a list with a single empty dictionary is returned. If the edge does not match the pattern, an empty list is returned.
Patterns are themselves edges. They can match families of edges by employing special atoms:
-> ‘*’ represents a general wildcard (matches any entity)
-> ‘.’ represents an atomic wildcard (matches any atom)
-> ‘(*)’ represents an edge wildcard (matches any edge)
-> ‘…’ at the end indicates an open-ended pattern.
The wildcards (’*’, ‘.’ and ‘(*)’) can be used to specify variables, for example ‘*x’, ‘(CLAIM)’ or ‘.ACTOR’. In case of a match, these variables are assigned the hyperedge they correspond to. For example,
(1) the edge: (is/Pd (my/Mp name/Cn) mary/Cp) applied to the pattern: (is/Pd (my/Mp name/Cn) *NAME) produces the result: [{‘NAME’, mary/Cp}]
(2) the edge: (is/Pd (my/Mp name/Cn) mary/Cp) applied to the pattern: (is/Pd (my/Mp name/Cn) (NAME)) produces the result: [{}]
(3) the edge: (is/Pd (my/Mp name/Cn) mary/Cp) applied to the pattern: (is/Pd . *NAME) produces the result: []
processor module
memory package
leveldb module
- class graphbrain.memory.leveldb.LevelDB(locator_string)
Implements LevelDB hypergraph storage.
- all()
Returns a generator of all the edges.
- all_attributes()
Returns a generator with a tuple for each edge. The first element of the tuple is the edge itself, the second is a dictionary of attribute values (as strings).
- close()
Closes the hypergraph.
- destroy()
Erase the entire hypergraph.
permutations module
- graphbrain.memory.permutations.do_with_edge_permutations(edge, f)
Applies the function f to all permutations of the given edge.
- graphbrain.memory.permutations.perm2edge(perm_str)
Transforms a permutation string from a database query into an edge.
- graphbrain.memory.permutations.permutate(tokens, nper)
Reorder the tokens vector to perform a permutation, specified by nper.
- graphbrain.memory.permutations.str_plus_1(s)
Increment a string by one, regaring lexicographical ordering.
- graphbrain.memory.permutations.unpermutate(tokens, nper)
Reorder the tokens vector to revert a permutation, specified by nper.
sqlite module
- class graphbrain.memory.sqlite.SQLite(locator_string)
Implements SQLite hypergraph storage.
- all()
Returns a generator of all the edges.
- all_attributes()
Returns a generator with a tuple for each edge. The first element of the tuple is the edge itself, the second is a dictionary of attribute values (as strings).
- close()
Closes the hypergraph.
- destroy()
Erase the entire hypergraph.
parsers package
package functions
- graphbrain.parsers.__init__.create_parser(lang=None, parser_class=None, lemmas=False, corefs=False, beta='repair', normalize=True, post_process=True)[source]
Creates and returns a parser (as an instanceof a subclass of Parser) for the language specified in the parameter. If parser_class is specified, then the parser specified by this class is instantiated instead. Throws exception if language is not implemented.
Available parsers: ‘en’ – English
Keyword argument: parser_class – specify an external parser class. lemmas – if True, lemma edges are generated by the parser. corefs – if True, coreference resolution is performed. (default: False) beta – beta stage mode, current options are ‘strict’ and ‘repair’ (default: ‘repair’) normalize – perform hyperedge normalization (default: True) post_process – perform hyperedge post-processing (default: True)
parser module
- class graphbrain.parsers.parser.Parser(lemmas=True, corefs=True, debug=False)[source]
Defines the common interface for parser objects. Parsers transofrm natural text into graphbrain hyperedges.
- parse(text)[source]
Transforms the given text into hyperedges + aditional information. Returns a dictionary with two fields:
-> parses: a sequence of dictionaries, with one dictionary for each sentence found in the text.
-> inferred_edges: a sequence of edges inferred during by parsing process (e.g. genders, ‘X is Y’ relationships)
Each sentence parse dictionary contains at least the following fields:
-> main_edge: the hyperedge corresponding to the sentence.
-> extra_edges: aditional edges, e.g. connecting atoms that appear in the main_edge to their lemmas.
-> text: the string of natural language text corresponding to the main_edge, i.e.: the sentence itself.
-> edges_text: a dictionary of all edges and subedges to their corresponding text.
-> corefs: resolve coreferences.
readers package
reader module
txt module
dir module
csv module
wikipedia module
reddit module
utils package
concepts module
- graphbrain.utils.concepts.all_concepts(edge)[source]
Recursively search for all concepts contained in the edge, returning a set that can also contain itself.
- graphbrain.utils.concepts.has_common_or_proper_concept(edge)[source]
Check if the concept either is a common/proper edge, or contains one.
- graphbrain.utils.concepts.has_proper_concept(edge)[source]
Check if the concept either is a proper edge, or contains one.
- graphbrain.utils.concepts.strip_concept(edge)[source]
Strip away nesting edges with connectors such as triggers and subpredicates, to expose the outmost and leftmost concept that can be found. May be the edge itself.
For example:
(against/T (the/M (of/B treaty/C paris/C)))
becomes
(the/M (of/B treaty/C paris/C))
conjunctions module
corefs module
- graphbrain.utils.corefs.are_corefs(hg, edge1, edge2, corefs=None)[source]
Checks if the two given edges are coreferences.
- graphbrain.utils.corefs.coref_set(hg, edge, corefs=None)[source]
Returns the set of coreferences that the given edge belongs to.
- graphbrain.utils.corefs.main_coref(hg, edge)[source]
Returns main edge for the coreference set that the given edge belongs to.
lemmas module
- graphbrain.utils.lemmas.deep_lemma(hg, edge, same_if_none=False)[source]
Returns the lemma of an atomic edge, or the lemma of the first atom found by recursively descending the hyperedge, always choosing the subedge immediatly after the connector.
This is useful, for example, to find the lemma of the central verb in a non-atomic predicate edge. For example:
(not/A (is/A going/P))
could return
go/P
Keyword argument: same_if_none – if False, returns None when lemma does not exist. If True, returns atom items when lemma does not exist. (default: False)
- graphbrain.utils.lemmas.lemma(hg, atom, same_if_none=False)[source]
Returns the lemma of the given atom if it exists, None otherwise.
Keyword argument: same_if_none – if False, returns None when lemma does not exist. If True, returns atom items when lemma does not exist. (default: False)
- graphbrain.utils.lemmas.lemma_degrees(hg, edge)[source]
Finds all the atoms that share the same given lemma and computes the sum of both their degrees and deep degrees. These two sums are returned.
If the parameter edge is non-atomic, this function simply returns the degree and deep degree of that edge.