Skip to content

Commit

Permalink
Fixed #755
Browse files Browse the repository at this point in the history
  • Loading branch information
enoriega committed Jan 16, 2024
1 parent ea7e2b6 commit fa580a0
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions skema/rest/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ async def get_client():
yield client
# close the client when the request is done


def fn_preprocessor(function_network: Dict[str, Any]):
fn_data = function_network.copy()

Expand Down Expand Up @@ -180,23 +181,32 @@ def compute_text_reading_evaluation(gt_data: list, attributes: AttributeCollecti
page = a["page"]
annotations_by_page[page].append(a)

def annotation_key(a: Dict):
return a['page'], tuple(a['start_xy']), a['text']

# Count the matches
tp, tn, fp, fn = 0, 0, 0, 0
matched_annotations = set()
for e in extractions:
matched = False
for m in e.mentions:
if m.extraction_source is not None:
te = m.extraction_source
if te.page is not None:
e_page = te.page
page_annotations = annotations_by_page[e_page]
matched = False
for a in page_annotations:
if extraction_matches_annotation(m, a, json_contents):
matched = True
tp += 1
break
if not matched:
fp += 1
if not matched:
if m.extraction_source is not None:
te = m.extraction_source
if te.page is not None:
e_page = te.page
page_annotations = annotations_by_page[e_page]

for a in page_annotations:
key = annotation_key(a)
if key not in matched_annotations:
if extraction_matches_annotation(m, a, json_contents):
matched_annotations.add(key)
matched = True
tp += 1
break
if not matched:
fp += 1

recall = tp / len(gt_data)
precision = tp / (tp + fp + 0.00000000001)
Expand Down

0 comments on commit fa580a0

Please sign in to comment.