hatchet.query package

Submodules

hatchet.query.compat module

class hatchet.query.compat.AbstractQuery[source]

Bases: ABC

Base class for all ‘old-style’ queries.

abstract apply(gf)[source]
class hatchet.query.compat.AndQuery(*args)[source]

Bases: NaryQuery

Compound query that returns the intersection of the results of the subqueries.

class hatchet.query.compat.CypherQuery(cypher_query)[source]

Bases: QueryMatcher

Processes and applies Strinb-based queries to GraphFrames.

hatchet.query.compat.IntersectionQuery

alias of AndQuery

class hatchet.query.compat.NaryQuery(*args)[source]

Bases: AbstractQuery

Base class for all compound queries that act on and merged N separate subqueries.

apply(gf)[source]

Applies the query to the specified GraphFrame.

Parameters:

gf (GraphFrame) – the GraphFramme on which to apply the query

Results:

(list): A list of nodes representing the result of the query

class hatchet.query.compat.NotQuery(*args)[source]

Bases: NaryQuery

Compound query that returns all nodes in the GraphFrame that are not returned from the subquery.

class hatchet.query.compat.OrQuery(*args)[source]

Bases: NaryQuery

Compound query that returns the union of the results of the subqueries

class hatchet.query.compat.QueryMatcher(query=None)[source]

Bases: AbstractQuery

Processes and applies base syntax queries and Object-based queries to GraphFrames.

apply(gf)[source]

Apply the query to a GraphFrame.

Parameters:

gf (GraphFrame) – the GraphFrame on which to apply the query

Returns:

A list representing the set of nodes from paths that match this query

Return type:

(list)

match(wildcard_spec='.', filter_func=<function QueryMatcher.<lambda>>)[source]

Start a query with a root node described by the arguments.

Parameters:
  • wildcard_spec (str, optional) – the wildcard status of the node

  • filter_func (Callable, optional) – a callable acceepting only a row from a pandas DataFrame that is used to filter this node in the query

Returns:

the instance of the class that called this function

Return type:

(QueryMatcher)

rel(wildcard_spec='.', filter_func=<function QueryMatcher.<lambda>>)[source]

Add another edge and node to the query.

Parameters:
  • wildcard_spec (str, optional) – the wildcard status of the node

  • filter_func (Callable, optional) – a callable acceepting only a row from a pandas DataFrame that is used to filter this node in the query

Returns:

the instance of the class that called this function

Return type:

(QueryMatcher)

hatchet.query.compat.SymDifferenceQuery

alias of XorQuery

hatchet.query.compat.UnionQuery

alias of OrQuery

class hatchet.query.compat.XorQuery(*args)[source]

Bases: NaryQuery

Compound query that returns the symmetric difference (i.e., set-based XOR) of the results of the subqueries

hatchet.query.compat.parse_cypher_query(cypher_query)[source]

Parse all types of String-based queries, including multi-queries that leverage the curly brace delimiters.

Parameters:

cypher_query (str) – the String-based query to be parsed

Returns:

a Hatchet query for this String-based query

Return type:

(CypherQuery)

hatchet.query.compound module

class hatchet.query.compound.CompoundQuery(*queries)[source]

Bases: object

Base class for all types of compound queries.

class hatchet.query.compound.ConjunctionQuery(*queries)[source]

Bases: CompoundQuery

A compound query that combines the results of its subqueries using set conjunction.

class hatchet.query.compound.DisjunctionQuery(*queries)[source]

Bases: CompoundQuery

A compound query that combines the results of its subqueries using set disjunction.

class hatchet.query.compound.ExclusiveDisjunctionQuery(*queries)[source]

Bases: CompoundQuery

A compound query that combines the results of its subqueries using exclusive set disjunction.

class hatchet.query.compound.NegationQuery(*queries)[source]

Bases: CompoundQuery

A compound query that inverts/negates the result of its single subquery.

hatchet.query.engine module

class hatchet.query.engine.QueryEngine[source]

Bases: object

Class for applying queries to GraphFrames.

apply(query, graph, dframe)[source]

Apply the query to a GraphFrame.

Parameters:
  • query (Query or CompoundQuery) – the query being applied

  • graph (Graph) – the Graph to which the query is being applied

  • dframe (pandas.DataFrame) – the DataFrame associated with the graph

Returns:

A list representing the set of nodes from paths that match the query

Return type:

(list)

reset_cache()[source]

Resets the cache in the QueryEngine.

hatchet.query.errors module

exception hatchet.query.errors.BadNumberNaryQueryArgs[source]

Bases: Exception

Raised when a query filter does not have a valid syntax

exception hatchet.query.errors.InvalidQueryFilter[source]

Bases: Exception

Raised when a query filter does not have a valid syntax

exception hatchet.query.errors.InvalidQueryPath[source]

Bases: Exception

Raised when a query does not have the correct syntax

exception hatchet.query.errors.MultiIndexModeMismatch[source]

Bases: Exception

Raised when an ObjectQuery or StringQuery object is set to use multi-indexed data, but no multi-indexed data is provided

exception hatchet.query.errors.RedundantQueryFilterWarning[source]

Bases: Warning

Warned when a query filter does nothing or is redundant

hatchet.query.object_dialect module

class hatchet.query.object_dialect.ObjectQuery(query, multi_index_mode='off')[source]

Bases: Query

Class for representing and parsing queries using the Object-based dialect.

hatchet.query.query module

class hatchet.query.query.Query[source]

Bases: object

Class for representing and building Hatchet Call Path Queries

match(quantifier='.', predicate=<function Query.<lambda>>)[source]

Start a query with a root node described by the arguments.

Parameters:
  • quantifier (".", "*", "+", or int, optional) – the quantifier for this node (tells how many graph nodes to match)

  • predicate (Callable, optional) – the predicate for this node (used to determine whether a graph node matches this query node)

Returns:

returns self so that this method can be chained with subsequent calls to “rel”/”relation”

Return type:

(Query)

rel(quantifier='.', predicate=<function Query.<lambda>>)[source]

Add a new node to the end of the query.

Parameters:
  • quantifier (".", "*", "+", or int, optional) – the quantifier for this node (tells how many graph nodes to match)

  • predicate (Callable, optional) – the predicate for this node (used to determine whether a graph node matches this query node)

Returns:

returns self so that this method can be chained with subsequent calls to “rel”/”relation”

Return type:

(Query)

relation(quantifer='.', predicate=<function Query.<lambda>>)[source]

Alias to Query.rel. Add a new node to the end of the query.

Parameters:
  • quantifier (".", "*", "+", or int, optional) – the quantifier for this node (tells how many graph nodes to match)

  • predicate (Callable, optional) – the predicate for this node (used to determine whether a graph node matches this query node)

Returns:

returns self so that this method can be chained with subsequent calls to “rel”/”relation”

Return type:

(Query)

hatchet.query.string_dialect module

class hatchet.query.string_dialect.StringQuery(cypher_query, multi_index_mode='off')[source]

Bases: Query

Class for representing and parsing queries using the String-based dialect.

hatchet.query.string_dialect.cname(obj)[source]

Utility function to get the name of the rule represented by the input

hatchet.query.string_dialect.filter_check_types(type_check, df_row, filt_lambda)[source]
Utility function used in String-based predicates

to make sure the node data used in the actual boolean predicate is of the correct type.

Parameters:
  • type_check (str) – a string containing a boolean Python expression used to validate node data typing

  • df_row (pandas.Series or pandas.DataFrame) – the row (or sub-DataFrame) representing the data for the current node being tested

  • filt_lambda (Callable) – the lambda used to actually confirm whether the node satisfies the predicate

Returns:

True if the node satisfies the predicate. False otherwise

Return type:

(bool)

hatchet.query.string_dialect.parse_string_dialect(query_str, multi_index_mode='off')[source]

Parse all types of String-based queries, including multi-queries that leverage the curly brace delimiters.

Parameters:

query_str (str) – the String-based query to be parsed

Returns:

A Hatchet query object representing the String-based query

Return type:

(Query or CompoundQuery)

Module contents

hatchet.query.combine_via_conjunction(query0, query1)[source]
hatchet.query.combine_via_disjunction(query0, query1)[source]
hatchet.query.combine_via_exclusive_disjunction(query0, query1)[source]
hatchet.query.is_hatchet_query(query_obj)[source]
hatchet.query.negate_query(query)[source]