CypherQueryCorrector#

class langchain_community.chains.graph_qa.cypher_utils.CypherQueryCorrector(schemas: List[Schema])[source]#

Used to correct relationship direction in generated Cypher statements. This code is copied from the winner’s submission to the Cypher competition: sakusaku-rich/cypher-direction-competition

Parameters:

schemas (List[Schema]) – list of schemas

Attributes

node_pattern

node_relation_node_pattern

path_pattern

property_pattern

relation_type_pattern

Methods

__init__(schemas)

clean_node(node)

correct_query(query)

detect_labels(str_node,Β node_variable_dict)

detect_node_variables(query)

detect_relation_types(str_relation)

extract_node_variable(part)

extract_paths(query)

judge_direction(relation)

verify_schema(from_node_labels,Β ...)

__init__(schemas: List[Schema])[source]#
Parameters:

schemas (List[Schema]) – list of schemas

clean_node(node: str) β†’ str[source]#
Parameters:

node (str) – node in string format

Return type:

str

correct_query(query: str) β†’ str[source]#
Parameters:

query (str) – cypher query

Return type:

str

detect_labels(str_node: str, node_variable_dict: Dict[str, Any]) β†’ List[str][source]#
Parameters:
  • str_node (str) – node in string format

  • node_variable_dict (Dict[str, Any]) – dictionary of node variables

Return type:

List[str]

detect_node_variables(query: str) β†’ Dict[str, List[str]][source]#
Parameters:

query (str) – cypher query

Return type:

Dict[str, List[str]]

detect_relation_types(str_relation: str) β†’ Tuple[str, List[str]][source]#
Parameters:

str_relation (str) – relation in string format

Return type:

Tuple[str, List[str]]

extract_node_variable(part: str) β†’ str | None[source]#
Parameters:

part (str) – node in string format

Return type:

str | None

extract_paths(query: str) β†’ List[str][source]#
Parameters:

query (str) – cypher query

Return type:

List[str]

judge_direction(relation: str) β†’ str[source]#
Parameters:

relation (str) – relation in string format

Return type:

str

verify_schema(from_node_labels: List[str], relation_types: List[str], to_node_labels: List[str]) β†’ bool[source]#
Parameters:
  • from_node_labels (List[str]) – labels of the from node

  • relation_type – type of the relation

  • to_node_labels (List[str]) – labels of the to node

  • relation_types (List[str])

Return type:

bool

Examples using CypherQueryCorrector