From 95281f3d29cbc868461695b79654d1cb0f9b457c Mon Sep 17 00:00:00 2001 From: "Gerber, Mike" Date: Thu, 19 Dec 2019 16:24:34 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20metadata=20about=20the=20reco?= =?UTF-8?q?gnition=20operation=20w/=20parameter=20info?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ocrd_calamari/recognize.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/ocrd_calamari/recognize.py b/ocrd_calamari/recognize.py index d633d23..c5a6b12 100644 --- a/ocrd_calamari/recognize.py +++ b/ocrd_calamari/recognize.py @@ -9,8 +9,12 @@ from calamari_ocr.ocr.voting import voter_from_proto from calamari_ocr.proto import VoterParams from ocrd import Processor from ocrd_modelfactory import page_from_file -from ocrd_models.ocrd_page import to_xml -from ocrd_models.ocrd_page_generateds import TextEquivType +from ocrd_models.ocrd_page import ( + LabelType, LabelsType, + MetadataItemType, + TextEquivType, + to_xml +) from ocrd_utils import getLogger, concat_padded, MIMETYPE_PAGE from ocrd_calamari.config import OCRD_TOOL, TF_CPP_MIN_LOG_LEVEL @@ -88,6 +92,20 @@ class CalamariRecognize(Processor): _page_update_higher_textequiv_levels('line', pcgts) + + # Add metadata about this operation and its runtime parameters: + metadata = pcgts.get_Metadata() # ensured by from_file() + metadata.add_MetadataItem( + MetadataItemType(type_="processingStep", + name=self.ocrd_tool['steps'][0], + value=TOOL, + Labels=[LabelsType( + externalModel="ocrd-tool", + externalId="parameters", + Label=[LabelType(type_=name, value=self.parameter[name]) + for name in self.parameter.keys()])])) + + file_id = self._make_file_id(input_file, n) self.workspace.add_file( ID=file_id,