Skip to content

Commit d6a7702

Browse files
Validator fixed
1 parent 8578bf1 commit d6a7702

File tree

3 files changed

+19
-32
lines changed

3 files changed

+19
-32
lines changed

requirements-dev.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ mdurl==0.1.2
238238
minify-html==0.15.0
239239
# via scrapegraphai
240240
mistral-common==1.4.1
241-
241+
# via scrapegraphai
242242
mpire==2.10.2
243243
# via semchunk
244244
multidict==6.0.5

requirements.lock

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ marshmallow==3.21.3
166166
minify-html==0.15.0
167167
# via scrapegraphai
168168
mistral-common==1.4.1
169+
# via scrapegraphai
169170
mpire==2.10.2
170171
# via semchunk
171172
multidict==6.0.5
@@ -255,7 +256,6 @@ pyyaml==6.0.1
255256
referencing==0.35.1
256257
# via jsonschema
257258
# via jsonschema-specifications
258-
259259
regex==2024.5.15
260260
# via tiktoken
261261
# via transformers
@@ -279,10 +279,9 @@ s3transfer==0.10.2
279279
safetensors==0.4.5
280280
# via transformers
281281
semchunk==2.2.0
282-
# via scrapegraphai
282+
# via scrapegraphai
283283
sentencepiece==0.2.0
284284
# via mistral-common
285-
286285
six==1.16.0
287286
# via python-dateutil
288287
sniffio==1.3.1

scrapegraphai/nodes/generate_code_node.py

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -608,42 +608,30 @@ def extract_code(self, code: str) -> str:
608608

609609
return match.group(1) if match else code
610610

611-
def normalize_string(s: str) -> str:
612-
return ''.join(c for c in s.lower().strip() if c not in string.punctuation)
613611

614-
def normalize_string(s: str) -> str:
615-
"""Normalize a string by converting to lowercase and stripping spaces."""
616-
return s.lower().strip()
617612

618-
def normalize_dict(d: dict) -> dict:
619-
"""
620-
Normalize the dictionary by:
621-
- Converting all string values to lowercase and stripping spaces.
622-
- Recursively normalizing nested dictionaries.
623-
- Sorting lists of primitives and creating sorted list of normalized dicts for lists of dicts.
624-
"""
613+
def normalize_dict(d: Dict[str, Any]) -> Dict[str, Any]:
625614
normalized = {}
626615
for key, value in d.items():
627616
if isinstance(value, str):
628-
normalized[key] = normalize_string(value)
617+
normalized[key] = value.lower().strip()
629618
elif isinstance(value, dict):
630619
normalized[key] = normalize_dict(value)
631620
elif isinstance(value, list):
632-
if all(isinstance(v, dict) for v in value):
633-
normalized[key] = sorted(
634-
normalize_dict(v) for v in value
635-
)
636-
else:
637-
normalized[key] = sorted(
638-
normalize_dict(v) if isinstance(v, dict)
639-
else normalize_string(v) if isinstance(v, str)
640-
else v
641-
for v in value
642-
)
621+
normalized[key] = normalize_list(value)
643622
else:
644623
normalized[key] = value
645-
return dict(sorted(normalized.items()))
646-
647-
def are_content_equal(generated_result: dict, reference_result: dict) -> bool:
624+
return normalized
625+
626+
def normalize_list(lst: List[Any]) -> List[Any]:
627+
return [
628+
normalize_dict(item) if isinstance(item, dict)
629+
else normalize_list(item) if isinstance(item, list)
630+
else item.lower().strip() if isinstance(item, str)
631+
else item
632+
for item in lst
633+
]
634+
635+
def are_content_equal(generated_result: Dict[str, Any], reference_result: Dict[str, Any]) -> bool:
648636
"""Compare two dictionaries for semantic equality."""
649-
return normalize_dict(generated_result) == normalize_dict(reference_result)
637+
return normalize_dict(generated_result) == normalize_dict(reference_result)

0 commit comments

Comments
 (0)