Skip to content
Snippets Groups Projects
Commit 0a628757 authored by Martin's avatar Martin
Browse files

fix linting

parent c5e4f26e
No related branches found
No related tags found
1 merge request!22Add style filter (handwritten, typewritten); support ignored_classes
Pipeline #74328 passed
...@@ -184,10 +184,7 @@ class HTRDataGenerator: ...@@ -184,10 +184,7 @@ class HTRDataGenerator:
for elt in self.api_client.cached_paginate( for elt in self.api_client.cached_paginate(
"ListElementChildren", id=page_id, with_classes=True "ListElementChildren", id=page_id, with_classes=True
): ):
elem_classes = [c elem_classes = [c for c in elt["classes"] if c["state"] != "rejected"]
for c in elt["classes"]
if c["state"] != "rejected"
]
should_accept = True should_accept = True
if self.should_filter_by_class: if self.should_filter_by_class:
...@@ -218,7 +215,9 @@ class HTRDataGenerator: ...@@ -218,7 +215,9 @@ class HTRDataGenerator:
found_class = list(style_counts.keys())[0] found_class = list(style_counts.keys())[0]
found_class = Style(found_class) found_class = Style(found_class)
else: else:
raise ValueError(f"Multiple style classes on the same element! {elt['id']} - {elem_classes}") raise ValueError(
f"Multiple style classes on the same element! {elt['id']} - {elem_classes}"
)
if found_class == self.style: if found_class == self.style:
accepted_zones.append(elt["zone"]["id"]) accepted_zones.append(elt["zone"]["id"])
...@@ -237,7 +236,6 @@ class HTRDataGenerator: ...@@ -237,7 +236,6 @@ class HTRDataGenerator:
) )
raise e raise e
def _validate_transcriptions(self, page_id: str, lines: List[TranscriptionData]): def _validate_transcriptions(self, page_id: str, lines: List[TranscriptionData]):
if not lines: if not lines:
return return
...@@ -296,9 +294,8 @@ class HTRDataGenerator: ...@@ -296,9 +294,8 @@ class HTRDataGenerator:
and res["worker_version_id"] not in self.accepted_worker_version_ids and res["worker_version_id"] not in self.accepted_worker_version_ids
): ):
continue continue
if ( if (self.should_filter_by_class or self.should_filter_by_style) and (
(self.should_filter_by_class or self.should_filter_by_style) res["element"]["zone"]["id"] not in accepted_zones
and res["element"]["zone"]["id"] not in accepted_zones
): ):
continue continue
if res["element"]["type"] != self.transcription_type: if res["element"]["type"] != self.transcription_type:
...@@ -902,8 +899,10 @@ def main(): ...@@ -902,8 +899,10 @@ def main():
if args.style and args.accepted_classes: if args.style and args.accepted_classes:
if any(c in args.accepted_classes for c in STYLE_CLASSES): if any(c in args.accepted_classes for c in STYLE_CLASSES):
parser.error(f"--style class values ({STYLE_CLASSES}) shouldn't be in the accepted_classes list " parser.error(
"if both --style and --accepted_classes are used together.") f"--style class values ({STYLE_CLASSES}) shouldn't be in the accepted_classes list "
"if both --style and --accepted_classes are used together."
)
logger.info(f"ARGS {args} \n") logger.info(f"ARGS {args} \n")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment