Skip to content

Commit b677967

Browse files
committed
chore: update property graph store tests + format all files
1 parent e117b0d commit b677967

File tree

9 files changed

+4136
-4201
lines changed

9 files changed

+4136
-4201
lines changed

src/llama_index_spanner/graph_retriever.py

Lines changed: 269 additions & 273 deletions
Large diffs are not rendered by default.

src/llama_index_spanner/graph_utils.py

Lines changed: 41 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -18,53 +18,47 @@
1818

1919

2020
def fix_gql_syntax(query: str) -> str:
21-
"""Fixes the syntax of a GQL query.
22-
23-
Example 1:
24-
25-
Input:
26-
MATCH (p:paper {id: 0})-[c:cites*8]->(p2:paper)
27-
Output:
28-
MATCH (p:paper {id: 0})-[c:cites]->{8}(p2:paper)
29-
Example 2:
30-
Input:
31-
MATCH (p:paper {id: 0})-[c:cites*1..8]->(p2:paper)
32-
Output:
33-
MATCH (p:paper {id: 0})-[c:cites]->{1:8}(p2:paper)
34-
35-
Args:
36-
query: The input GQL query.
37-
38-
Returns:
39-
Possibly modified GQL query.
40-
"""
41-
42-
query = re.sub(
43-
r"-\[(.*?):(\w+)\*(\d+)\.\.(\d+)\]->", r"-[\1:\2]->{\3,\4}", query
44-
)
45-
query = re.sub(r"-\[(.*?):(\w+)\*(\d+)\]->", r"-[\1:\2]->{\3}", query)
46-
query = re.sub(
47-
r"<-\[(.*?):(\w+)\*(\d+)\.\.(\d+)\]-", r"<-[\1:\2]-{\3,\4}", query
48-
)
49-
query = re.sub(r"<-\[(.*?):(\w+)\*(\d+)\]-", r"<-[\1:\2]-{\3}", query)
50-
query = re.sub(
51-
r"-\[(.*?):(\w+)\*(\d+)\.\.(\d+)\]-", r"-[\1:\2]-{\3,\4}", query
52-
)
53-
query = re.sub(r"-\[(.*?):(\w+)\*(\d+)\]-", r"-[\1:\2]-{\3}", query)
54-
# print("Fixed query: ", query)
55-
return query
21+
"""Fixes the syntax of a GQL query.
22+
23+
Example 1:
24+
25+
Input:
26+
MATCH (p:paper {id: 0})-[c:cites*8]->(p2:paper)
27+
Output:
28+
MATCH (p:paper {id: 0})-[c:cites]->{8}(p2:paper)
29+
Example 2:
30+
Input:
31+
MATCH (p:paper {id: 0})-[c:cites*1..8]->(p2:paper)
32+
Output:
33+
MATCH (p:paper {id: 0})-[c:cites]->{1:8}(p2:paper)
34+
35+
Args:
36+
query: The input GQL query.
37+
38+
Returns:
39+
Possibly modified GQL query.
40+
"""
41+
42+
query = re.sub(r"-\[(.*?):(\w+)\*(\d+)\.\.(\d+)\]->", r"-[\1:\2]->{\3,\4}", query)
43+
query = re.sub(r"-\[(.*?):(\w+)\*(\d+)\]->", r"-[\1:\2]->{\3}", query)
44+
query = re.sub(r"<-\[(.*?):(\w+)\*(\d+)\.\.(\d+)\]-", r"<-[\1:\2]-{\3,\4}", query)
45+
query = re.sub(r"<-\[(.*?):(\w+)\*(\d+)\]-", r"<-[\1:\2]-{\3}", query)
46+
query = re.sub(r"-\[(.*?):(\w+)\*(\d+)\.\.(\d+)\]-", r"-[\1:\2]-{\3,\4}", query)
47+
query = re.sub(r"-\[(.*?):(\w+)\*(\d+)\]-", r"-[\1:\2]-{\3}", query)
48+
# print("Fixed query: ", query)
49+
return query
5650

5751

5852
def extract_gql(text: str) -> str:
59-
"""Extract GQL query from a text.
60-
61-
Args:
62-
text: Text to extract GQL query from.
63-
64-
Returns:
65-
GQL query extracted from the text.
66-
"""
67-
pattern = r"```(.*?)```"
68-
matches = re.findall(pattern, text, re.DOTALL)
69-
query = matches[0] if matches else text
70-
return fix_gql_syntax(query)
53+
"""Extract GQL query from a text.
54+
55+
Args:
56+
text: Text to extract GQL query from.
57+
58+
Returns:
59+
GQL query extracted from the text.
60+
"""
61+
pattern = r"```(.*?)```"
62+
matches = re.findall(pattern, text, re.DOTALL)
63+
query = matches[0] if matches else text
64+
return fix_gql_syntax(query)

0 commit comments

Comments
 (0)