Skip to content
Snippets Groups Projects
Commit c4ff8cc2 authored by Valentin Rigal's avatar Valentin Rigal
Browse files

Handle multiple type reporting for elements and transcriptions

parent 8de32fff
No related branches found
Tags 0.3.2-rc6
1 merge request!9Handle multiple type reporting for elements and transcriptions
Pipeline #77878 passed
......@@ -45,13 +45,14 @@ class Reporter(object):
# Just call the element initializer
self._get_element(element_id)
def add_element(self, parent_id, type):
def add_element(self, parent_id, type, type_count=1):
"""
Report creating a single element with a parent.
Multiple elements with the same type and parent can be declared with the type_count parameter.
"""
elements = self._get_element(parent_id)["elements"]
elements.setdefault(type, 0)
elements[type] += 1
elements[type] += type_count
def add_classification(self, element_id, class_name):
"""
......@@ -77,13 +78,14 @@ class Reporter(object):
)
element["classifications"] = dict(counter)
def add_transcription(self, element_id, type):
def add_transcription(self, element_id, type, type_count=1):
"""
Report creating a transcription on an element.
Multiple transcriptions with the same type and parent can be declared with the type_count parameter.
"""
transcriptions = self._get_element(element_id)["transcriptions"]
transcriptions.setdefault(type, 0)
transcriptions[type] += 1
transcriptions[type] += type_count
def add_transcriptions(self, element_id, transcriptions):
"""
......
......@@ -41,6 +41,23 @@ def test_add_element():
}
def test_add_element_count():
"""
Report multiple elements with the same parent and type
"""
reporter = Reporter("worker")
reporter.add_element("myelement", type="text_line", type_count=42)
assert "myelement" in reporter.report_data["elements"]
element_data = reporter.report_data["elements"]["myelement"]
del element_data["started"]
assert element_data == {
"elements": {"text_line": 42},
"transcriptions": {},
"classifications": {},
"errors": [],
}
def test_add_classification():
reporter = Reporter("worker")
reporter.add_classification("myelement", "three")
......@@ -97,6 +114,23 @@ def test_add_transcription():
}
def test_add_transcription_count():
"""
Report multiple transcriptions with the same element and type
"""
reporter = Reporter("worker")
reporter.add_transcription("myelement", "word", type_count=1337)
assert "myelement" in reporter.report_data["elements"]
element_data = reporter.report_data["elements"]["myelement"]
del element_data["started"]
assert element_data == {
"elements": {},
"transcriptions": {"word": 1337},
"classifications": {},
"errors": [],
}
def test_add_transcriptions():
reporter = Reporter("worker")
with pytest.raises(AssertionError):
......
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