Skip to content

Commit

Permalink
Update worker.py
Browse files Browse the repository at this point in the history
Field mappings seems to work the same way now in standard apis
  • Loading branch information
DrRSatzteil authored Jan 6, 2024
1 parent 5191d2f commit cadde70
Showing 1 changed file with 2 additions and 19 deletions.
21 changes: 2 additions & 19 deletions mayanmindee/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,6 @@ def is_similar(seq1, seq2, confidence) -> bool:
return fuzz.partial_ratio(seq1.lower(), seq2.lower()) >= confidence


def getattritem(obj, attr: str) -> Any:
steps = list(filter(None, re.split(r"\[(\d+)\]", attr)))
a = iter(steps)
pairs = zip(a, a)
for pair in pairs:
obj = operator.itemgetter(int(pair[1]))(
operator.attrgetter(pair[0].lstrip("."))(obj)
)
if len(steps) % 2 > 0:
obj = operator.attrgetter(steps[-1].lstrip("."))(obj)
return obj


def post_processing(result: Any, parsed_doc, processing_steps: list) -> str:
for step in processing_steps:
result = getattr(postprocess, step["action"])(result, parsed_doc, *step["args"])
Expand Down Expand Up @@ -199,11 +186,7 @@ def process_standard(document_id: int, document_type: str) -> None:
)

for field_name, metadata_mappings in required_fields.items():
try:
result = getattritem(parsed_doc.document, field_name)
except:
print("Could not retrieve property " + field_name)

result = parsed_doc.document.inference.prediction.fields[field_name].contents_string()
for metadata_mapping in metadata_mappings:
if "postprocess" in metadata_mapping[1]:
result = post_processing(
Expand All @@ -227,7 +210,7 @@ def process_standard(document_id: int, document_type: str) -> None:
)

for field_name, tag_mappings in required_fields.items():
result = getattritem(parsed_doc.document, field_name)
result = parsed_doc.document.inference.prediction.fields[field_name].contents_string()
if result:
for tag_mapping in tag_mappings:
if is_similar(
Expand Down

0 comments on commit cadde70

Please sign in to comment.