langchain.chains.graph_qa.cypher_utils.CypherQueryCorrector

class langchain.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: https://github.com/sakusaku-rich/cypher-direction-competition

Parameters

schemas – list of schemas

Attributes

node_pattern

node_relation_node_pattern

path_pattern

property_pattern

relation_type_pattern

Methods

__init__(schemas)

param schemas

list of schemas

clean_node(node)

param node

node in string format

correct_query(query)

param query

cypher query

detect_labels(str_node, node_variable_dict)

param str_node

node in string format

detect_node_variables(query)

param query

cypher query

detect_relation_types(str_relation)

param str_relation

relation in string format

extract_node_variable(part)

param part

node in string format

extract_paths(query)

param query

cypher query

judge_direction(relation)

param relation

relation in string format

verify_schema(from_node_labels, ...)

param from_node_labels

labels of the from node

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

schemas – list of schemas

clean_node(node: str) str[source]
Parameters

node – node in string format

correct_query(query: str) str[source]
Parameters

query – cypher query

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

  • node_variable_dict – dictionary of node variables

detect_node_variables(query: str) Dict[str, List[str]][source]
Parameters

query – cypher query

detect_relation_types(str_relation: str) Tuple[str, List[str]][source]
Parameters

str_relation – relation in string format

extract_node_variable(part: str) Optional[str][source]
Parameters

part – node in string format

extract_paths(query: str) List[str][source]
Parameters

query – cypher query

judge_direction(relation: str) str[source]
Parameters

relation – relation in string format

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

  • relation_type – type of the relation

  • to_node_labels – labels of the to node