# Robust Text-to-Cypher Using Combination of BERT, GraphSAGE, and Transformer (CoBGT) Model
## 2 Background
### Cypher  
In Neo4j, Cypher is a declarative query language used to access the database and specify schema definitions [27]. The following outlines the properties of Cypher query.  
Linear queries: Inputs to the Cypher language are a property graph and the outputs are a table containing patterns found in a graph. Queries are structured linearly, progressing from start to finish. This allows users to think of query processing as starting from the beginning of the query text and then progressing linearly to the end. Each clause in a query is a function that takes a table and outputs a table that can both expand the number of fields and add new tuples [3]. At the end of the query, the RETURN clause specifies the patterns with the desired properties that users want to retrieve--this usage is different from SQL, where the projection is declared at the beginning of the query using the SELECT clause.  
Pattern matching: Graph pattern matching is the central concept of Cypher queries. It is the mechanism for navigating, describing, and extracting data from a graph by applying a declarative pattern. Inside a MATCH clause, you can use graph patterns to define the data you are searching for and the data to return. Patterns in Cypher are expressed in a visual form as \"ASCII art\", such as (a)-[r]->(b). In this notation, a and b are the node types and r represents the relationship type. Influenced by XPath and SPARQL, Cypher patterns express regular path queries and support matching and returning paths.  
Data Modification: Cypher provides clauses for creating (CREATE), deleting (DELETE), and updating (SET) graph entities. MERGE clause matches patterns or creates them if none are found, ensuring uniqueness with database synchronization.  
The basic Cypher query includes MATCH clause, WHERE clause, and RETURN clause. The MATCH clause is used to specify patterns of nodes and relationships to be found in the graph. The WHERE clause filters the matched patterns based on certain criteria and the RETURN clause specifies what to return from the query.  
Example: below is a Cypher query to retrieve the list of all actors in \"The Matrix\" movie, the number of those actors, and the producer of the movie from Figure 1.  
MATCH (a:Actor)-[:ACTED_IN]->(m:Movie), (p:Producer)-[:PRODUCED]->(m)  
WHERE m.title = \"The Matrix'  
RETURN a.name, COUNT(a), p.name  
First, in the MATCH clause, the query searched the graph for patterns where there is a node labeled Actor (alias \(a\)) that has a relationship of type ACTED_IN to a node labeled Movie (alias \(m\)). The relationship (:Actor)-[:ACTED_IN]->(:Movie) is defined in the schema.  
Another pattern is (p: Producer)-[:PRODUCED]->(m); this pattern finds Producer nodes connected to the same Movie nodes (alias _m_) with the Actor node (alias _a_). Next, the WHERE clause specifies the criteria that the Movie's title should be \"The Matrix\". Finally, in the RETURN clause, we obtain the list of actors (a.name), number of actors (COUNT(a)), and name of the producer (p.name).  
From the above properties, we can see that key points for converting natural language questions to Cypher queries are the following factors:  
Extract Key Values: Identify the essential entities or values (e.g., \"The Matrix\" in the example).  
Match Relevant Relationship Patterns: Determine the relevant relationship patterns that define how entities are connected in the graph (e.g., (:Actor)-[:ACTED_IN]->(:Movie)).  
Select Property Nodes for Comparison: Identify which properties to compare using the key values (e.g., comparing the name property of the Person node with \"Alice\").