Skip to content

Commit

Permalink
edited order
Browse files Browse the repository at this point in the history
  • Loading branch information
arinkulshi committed Jun 21, 2024
1 parent 9652039 commit 2941d7d
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions OCR/ocr/services/metrics_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,6 @@ def levenshtein_distance(ocr_text, ground_truth):
return SequenceMatcher(None, ocr_text, ground_truth).ratio()


def extract_values_from_json(json_data):
extracted_values = {}
for item in json_data:
if isinstance(item, dict) and "key" in item and "value" in item:
key = normalize(item["key"])
value = normalize(item["value"])
extracted_values[key] = value
else:
raise ValueError("Invalid JSON format")
return extracted_values


def precision(ocr_text, ground_truth):
tp = sum(1 for o, g in zip(ocr_text, ground_truth) if o == g)
fp = len(ocr_text) - tp
Expand All @@ -58,6 +46,18 @@ def recall(ocr_text, ground_truth):
return tp / (tp + fn) if (tp + fn) > 0 else 0


def extract_values_from_json(json_data):
extracted_values = {}
for item in json_data:
if isinstance(item, dict) and "key" in item and "value" in item:
key = normalize(item["key"])
value = normalize(item["value"])
extracted_values[key] = value
else:
raise ValueError("Invalid JSON format")
return extracted_values


def calculate_metrics(ocr_json, ground_truth_json):
ocr_values = extract_values_from_json(ocr_json)
ground_truth_values = extract_values_from_json(ground_truth_json)
Expand Down

0 comments on commit 2941d7d

Please sign in to comment.