-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #191 from kba/agent-on-save
Add agent for processors on save
- Loading branch information
Showing
13 changed files
with
195 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# import os | ||
from ocrd.constants import NAMESPACES as NS, TAG_METS_AGENT, TAG_METS_NAME | ||
|
||
from .ocrd_xml_base import ET | ||
|
||
class OcrdAgent(object): | ||
""" | ||
Represents a <mets:agent> | ||
""" | ||
|
||
# @staticmethod | ||
# from_el(el): | ||
# role = el_agent.get('ROLE') | ||
# _type = el_agent.get('TYPE') | ||
# otherrole = el_agent.get('OTHERROLE') | ||
# name_parts = string.split(el.find('mets:name', NS).text, ' ', 2) | ||
# # name = name_parts[0] | ||
# # version = name_parts[1][1:] # v0.0.1 => 0.0.1 | ||
# return OcrdAgent(el, name, role, _type, otherrole) | ||
|
||
def __init__(self, el=None, name=None, _type=None, othertype=None, role=None, otherrole=None): | ||
if el is None: | ||
el = ET.Element(TAG_METS_AGENT) | ||
self._el = el | ||
self.name = name | ||
self.type = _type | ||
self.othertype = othertype | ||
self.role = role | ||
self.otherrole = otherrole | ||
|
||
def __str__(self): | ||
props = ', '.join([ | ||
'='.join([k, getattr(self, k) if getattr(self, k) else '---']) | ||
for k in ['type', 'othertype', 'role', 'otherrole', 'name'] | ||
]) | ||
return '<OcrdAgent [' + props + ']/> ' | ||
|
||
@property | ||
def type(self): | ||
return self._el.get('TYPE') | ||
|
||
@type.setter | ||
def type(self, _type): | ||
if _type is not None: | ||
self._el.set('TYPE', _type) | ||
|
||
@property | ||
def othertype(self): | ||
return self._el.get('OTHERTYPE') | ||
|
||
@othertype.setter | ||
def othertype(self, othertype): | ||
if othertype is not None: | ||
self._el.set('TYPE', 'OTHER') | ||
self._el.set('OTHERTYPE', othertype) | ||
|
||
@property | ||
def role(self): | ||
return self._el.get('ROLE') | ||
|
||
@role.setter | ||
def role(self, role): | ||
if role is not None: | ||
self._el.set('ROLE', role) | ||
|
||
@property | ||
def otherrole(self): | ||
return self._el.get('OTHERROLE') | ||
|
||
@otherrole.setter | ||
def otherrole(self, otherrole): | ||
if otherrole is not None: | ||
self._el.set('ROLE', 'OTHER') | ||
self._el.set('OTHERROLE', otherrole) | ||
|
||
@property | ||
def name(self): | ||
el_name = self._el.find('mets:name', NS) | ||
if el_name is not None: | ||
return el_name.text | ||
|
||
@name.setter | ||
def name(self, name): | ||
if name is not None: | ||
el_name = self._el.find('mets:name', NS) | ||
if el_name is None: | ||
el_name = ET.SubElement(self._el, TAG_METS_NAME) | ||
el_name.text = name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ | |
'Flask', | ||
'Pillow', | ||
'click', | ||
'click >=7<8', | ||
'click >=7', | ||
'jsonschema', | ||
'lxml', | ||
'numpy', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from test.base import TestCase, assets, main # pylint: disable=unused-import | ||
|
||
from ocrd.model import OcrdAgent | ||
|
||
# pylint: disable=no-member | ||
class TestOcrdAgent(TestCase): | ||
|
||
def test_basic1(self): | ||
ag = OcrdAgent(role='FOO') | ||
self.assertEqual(ag.role, 'FOO') | ||
|
||
def test_basic2(self): | ||
ag = OcrdAgent(otherrole='BAR') | ||
self.assertEqual(ag.role, 'OTHER') | ||
self.assertEqual(ag.otherrole, 'BAR') | ||
|
||
def test_basic3(self): | ||
ag = OcrdAgent(name='foobar') | ||
self.assertEqual(ag.name, 'foobar') | ||
ag.name = 'barfoo' | ||
self.assertEqual(ag.name, 'barfoo') | ||
|
||
def test_basic4(self): | ||
ag = OcrdAgent(othertype='foobar') | ||
self.assertEqual(ag.type, 'OTHER') | ||
# print(ag) | ||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters