Skip to content

Commit d2c182a

Browse files
authored
Merge pull request #42 from FalkorDB/validation-fixes
Cypher validation fix and add lists to the attribute types
2 parents 12a9d97 + a97352f commit d2c182a

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

graphrag_sdk/attribute.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class AttributeType:
1414
STRING = "string"
1515
NUMBER = "number"
1616
BOOLEAN = "boolean"
17+
LIST = "list"
1718

1819
@staticmethod
1920
def from_string(txt: str):
@@ -35,6 +36,8 @@ def from_string(txt: str):
3536
return AttributeType.NUMBER
3637
if txt.lower() == AttributeType.BOOLEAN:
3738
return AttributeType.BOOLEAN
39+
if txt.lower() == AttributeType.LIST:
40+
return AttributeType.LIST
3841
raise Exception(f"Invalid attribute type: {txt}")
3942

4043

@@ -121,6 +124,7 @@ def from_string(txt: str):
121124
AttributeType.STRING,
122125
AttributeType.NUMBER,
123126
AttributeType.BOOLEAN,
127+
AttributeType.LIST,
124128
]:
125129
raise Exception(f"Invalid attribute type: {attr_type}")
126130

graphrag_sdk/helpers.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,16 @@ def validate_cypher_relations_exist(cypher: str, ontology: graphrag_sdk.Ontology
123123
# Check if relations exist in ontology
124124
not_found_relation_labels = []
125125
relation_labels = re.findall(r"\[:(.*?)\]", cypher)
126-
for label in relation_labels:
127-
label = label.split(":")[1] if ":" in label else label
128-
label = label.split("{")[0].strip() if "{" in label else label
129-
if label not in [relation.label for relation in ontology.relations]:
130-
not_found_relation_labels.append(label)
126+
for relation in relation_labels:
127+
for label in relation.split("|"):
128+
max_idx = min(
129+
label.index("*") if "*" in label else len(label),
130+
label.index("{") if "{" in label else len(label),
131+
label.index("]") if "]" in label else len(label),
132+
)
133+
label = label[:max_idx]
134+
if label not in [relation.label for relation in ontology.relations]:
135+
not_found_relation_labels.append(label)
131136

132137
return [
133138
f"Relation {label} not found in ontology" for label in not_found_relation_labels
@@ -144,7 +149,7 @@ def validate_cypher_relation_directions(
144149
for relation in relations:
145150
try:
146151
relation_label = (
147-
re.search(r"(?:\[)(?:\w)*(?:\:)([^{\]]+)", relation.group(0))
152+
re.search(r"(?:\[)(?:\w)*(?:\:)([^\d\{\]\*\.\:]+)", relation.group(0))
148153
.group(1)
149154
.strip()
150155
)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "graphrag_sdk"
3-
version = "0.3.2"
3+
version = "0.3.3"
44
license = "MIT"
55
description = ""
66
authors = ["FalkorDB <[email protected]>"]

0 commit comments

Comments
 (0)