Source Code Reference

Contents

Source Code Reference#

class gnfd.DependencySet(iterable=(), /)#

Bases: set[GNFD]

classmethod from_string_list(lst)#

Creates a DependencySet from a list of dependencies encoded as strings.

get_normal_form(session)#
Parameters:

session – A session that is connected to a Neo4J compatible database

Returns:

the normal form of the graph in the Neo4J compatible database under this set of dependencies.

Return type:

str

is_in_global_normal_form()#
Returns:

True when there is no inter-graph dependency, False otherwise.

Return type:

bool

property lp_suitable: bool#
Returns:

True when LP normalization (cf. <https://doi.org/10.1007/s00778-025-00902-2>) could be performed on this graph as its dependencies only target nodes and there are no inter graph dependencies.

class gnfd.Edge(symbol='', labels=None, properties=None, src_pattern=None, tgt_pattern=None)#

Bases: GraphObject, Pattern, ABC

Represents an abstract LPG edge without a direction.

Parameters:
  • symbol – The symbol of the variable of the edge.

  • labels – The labels of the edge.

  • properties – The properties of the edge.

  • src_pattern – The source Node of the edge.

  • tgt_pattern – The target Node of the edge.

contains_property(symbol, key)#

Checks whether the pattern contains a graph object whose variable symbol is symbol and which has a property key.

Parameters:
  • symbol (str) – The symbol which should be looked for in the pattern.

  • key (str) – The key of the property whose existence should be checked.

Returns:

Whether there is a GraphObject having symbol as its symbol.

contains_var(symbol)#

Checks whether the pattern contains a graph object whose variable symbol is symbol.

Parameters:

symbol (str) – The symbol which should be looked for in the pattern.

Returns:

Whether there is a GraphObject having symbol as its symbol.

Return type:

bool

get_graph_object_with_symbol(symbol)#
Returns:

a graph object with the given symbol

Return type:

GraphObject | None

get_graph_objects()#
Returns:

all graph objects, i.e., any Node or Edge.

Return type:

set[GraphObject]

go_equals(other)#
Returns:

Whether 2 graph objects are equivalent

Return type:

bool

minimal_pattern_intersections(other)#

Computes the minimal pattern intersection between this and the other pattern.

Returns:

a list of tuples consisting of (1) the pattern that is the minimal intersection between this and the other pattern and of (2) tuples denote variable correspondences between the patterns.

Return type:

list[tuple[Pattern, set[tuple[str, str]]]]

abstract property src: Node#

:returns the source Node of the edge

abstract property tgt: Node#

:returns the target Node of the edge

to_clingo_tableau(lhs, constants=True)#
Returns:

The pattern represented as clingo facts containing constants or variables.

Return type:

str

to_gql_match_where_tuple()#
Returns:

A tuple where the first value denotes a GQL match and the second denotes a GQL where

Return type:

tuple[str, str]

class gnfd.GNFD(pattern, left, right)#

Bases: object

Denotes a GN-FD that consists of a Pattern and sets of Reference that denote the right and left side of the descriptor of the GN-FD.

static from_string(string)#

Parse a GN-FD from a string.

Parameters:

string – The string representation of the GN-FD to create. Relies on the grammar shown in gnfd.g4.

class gnfd.GraphObject(symbol='', labels=None, properties=None)#

Bases: ABC

Abstract class representing an LPG graph object, i.e., a Edge or a Node.

Parameters:
  • symbol (str) – The symbol of the variable of the graph object.

  • labels (set[str] | None) – The labels of the graph object.

  • properties (set[str] | None) – The properties of the graph object.

clingo_symbol()#

Returns a symbol for use with clingo.

abstractmethod go_equals(other)#
Returns:

Whether 2 graph objects are equivalent

is_anonymous()#

A graph object is anonymous if it has no symbol. Anonymous graph objects cannot be used in the descriptor, i.e., the left and right side, of a GNFD.

class gnfd.LeftEdge(symbol='', labels=None, properties=None, src_pattern=None, tgt_pattern=None)#

Bases: Edge

Represents an LPG edge directed to the left.

property leftmost_node#
Returns:

the left most node of the pattern, i.e., the leaf of always choosing pattern 1

minimal_pattern_intersections(other)#

Computes the minimal pattern intersection between this and the other pattern.

Returns:

a list of tuples consisting of (1) the pattern that is the minimal intersection between this and the other pattern and of (2) tuples denote variable correspondences between the patterns.

property rightmost_node#
Returns:

the right most node of the pattern, i.e., the leaf of always choosing pattern 2

property src#

:returns the source Node of the edge

property tgt#

:returns the target Node of the edge

class gnfd.Node(symbol='', labels=None, properties=None)#

Bases: GraphObject, Pattern

Represents an LPG node.

contains_property(symbol, key)#

Checks whether the pattern contains a graph object whose variable symbol is symbol and which has a property key.

Parameters:
  • symbol (str) – The symbol which should be looked for in the pattern.

  • key (str) – The key of the property whose existence should be checked.

Returns:

Whether there is a GraphObject having symbol as its symbol.

contains_var(symbol)#

Checks whether the pattern contains a graph object whose variable symbol is symbol.

Parameters:

symbol (str) – The symbol which should be looked for in the pattern.

Returns:

Whether there is a GraphObject having symbol as its symbol.

Return type:

bool

equals(other)#

Computes whether the structure of this and the other pattern and their labels and properties are equal.

Returns:

whether the other is equal to this pattern.

Return type:

bool

get_graph_object_with_symbol(symbol)#
Returns:

a graph object with the given symbol

Return type:

GraphObject | None

get_graph_objects()#
Returns:

all graph objects, i.e., any Node or Edge.

Return type:

set[GraphObject]

go_equals(other)#
Returns:

Whether 2 graph objects are equivalent

property leftmost_node#
Returns:

the left most node of the pattern, i.e., the leaf of always choosing pattern 1

minimal_pattern_intersections(other)#

Computes the minimal pattern intersection between this and the other pattern.

Returns:

a list of tuples consisting of (1) the pattern that is the minimal intersection between this and the other pattern and of (2) tuples denote variable correspondences between the patterns.

property rightmost_node#
Returns:

the right most node of the pattern, i.e., the leaf of always choosing pattern 2

to_clingo_tableau(lhs, constants=True)#
Returns:

The pattern represented as clingo facts containing constants or variables.

Return type:

str

to_gql_match_where_tuple()#
Returns:

A tuple where the first value denotes a GQL match and the second denotes a GQL where

Return type:

tuple[str, str]

class gnfd.Pattern(string)#

Bases: ABC

Represents a pattern used for matching in an LPG.

abstractmethod contains_property(symbol, key)#

Checks whether the pattern contains a graph object whose variable symbol is symbol and which has a property key.

Parameters:
  • symbol (str) – The symbol which should be looked for in the pattern.

  • key (str) – The key of the property whose existence should be checked.

Returns:

Whether there is a GraphObject having symbol as its symbol.

abstractmethod contains_var(symbol)#

Checks whether the pattern contains a graph object whose variable symbol is symbol.

Parameters:

symbol (str) – The symbol which should be looked for in the pattern.

Returns:

Whether there is a GraphObject having symbol as its symbol.

Return type:

bool

equals(other)#

Computes whether the structure of this and the other pattern and their labels and properties are equal.

Returns:

whether the other is equal to this pattern.

Return type:

bool

abstractmethod get_graph_object_with_symbol(symbol)#
Returns:

a graph object with the given symbol

Return type:

GraphObject | None

abstractmethod get_graph_objects()#
Returns:

all graph objects, i.e., any Node or Edge.

Return type:

set[GraphObject]

abstract property leftmost_node#
Returns:

the left most node of the pattern, i.e., the leaf of always choosing pattern 1

abstractmethod minimal_pattern_intersections(other)#

Computes the minimal pattern intersection between this and the other pattern.

Returns:

a list of tuples consisting of (1) the pattern that is the minimal intersection between this and the other pattern and of (2) tuples denote variable correspondences between the patterns.

Return type:

list[tuple[Pattern, set[tuple[str, str]]]]

abstract property rightmost_node#
Returns:

the right most node of the pattern, i.e., the leaf of always choosing pattern 2

abstractmethod to_clingo_tableau(lhs, constants=True)#
Returns:

The pattern represented as clingo facts containing constants or variables.

Return type:

str

abstractmethod to_gql_match_where_tuple()#
Returns:

A tuple where the first value denotes a GQL match and the second denotes a GQL where

Return type:

tuple[str, str]

class gnfd.PatternConcat(left, right, string)#

Bases: Pattern

Represents a concatenation of two patterns.

contains_property(symbol, key)#

Checks whether the pattern contains a graph object whose variable symbol is symbol and which has a property key.

Parameters:
  • symbol (str) – The symbol which should be looked for in the pattern.

  • key (str) – The key of the property whose existence should be checked.

Returns:

Whether there is a GraphObject having symbol as its symbol.

contains_var(symbol)#

Checks whether the pattern contains a graph object whose variable symbol is symbol.

Parameters:

symbol (str) – The symbol which should be looked for in the pattern.

Returns:

Whether there is a GraphObject having symbol as its symbol.

Return type:

bool

get_graph_object_with_symbol(symbol)#
Returns:

a graph object with the given symbol

Return type:

GraphObject | None

get_graph_objects()#
Returns:

all graph objects, i.e., any Node or Edge.

Return type:

set[GraphObject]

property leftmost_node#
Returns:

the left most node of the pattern, i.e., the leaf of always choosing pattern 1

minimal_pattern_intersections(other)#

Computes the minimal pattern intersection between this and the other pattern.

Returns:

a list of tuples consisting of (1) the pattern that is the minimal intersection between this and the other pattern and of (2) tuples denote variable correspondences between the patterns.

property rightmost_node#
Returns:

the right most node of the pattern, i.e., the leaf of always choosing pattern 2

to_clingo_tableau()#
Returns:

The pattern represented as clingo facts containing constants or variables.

Return type:

str

to_gql_match_where_tuple()#
Returns:

A tuple where the first value denotes a GQL match and the second denotes a GQL where

Return type:

tuple[str, str]

class gnfd.Reference(reference)#

Bases: object

Represents a reference to a property key contained in a graph object or to the graph object itself.

get_graph_object()#
Returns:

The graph object of the reference.

Return type:

GraphObject

to_query_string(database)#
Returns:

The string representation of the reference that can be used to query the provided database.

Return type:

str

class gnfd.RightEdge(symbol='', labels=None, properties=None, src_pattern=None, tgt_pattern=None)#

Bases: Edge

Represents an LPG edge directed to the right.

property leftmost_node#
Returns:

the left most node of the pattern, i.e., the leaf of always choosing pattern 1

minimal_pattern_intersections(other)#

Computes the minimal pattern intersection between this and the other pattern.

Returns:

a list of tuples consisting of (1) the pattern that is the minimal intersection between this and the other pattern and of (2) tuples denote variable correspondences between the patterns.

property rightmost_node#
Returns:

the right most node of the pattern, i.e., the leaf of always choosing pattern 2

property src#

:returns the source Node of the edge

property tgt#

:returns the target Node of the edge