-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rename: transkribus_{fixer,to_prima}, fix #7
- Loading branch information
Showing
10 changed files
with
62 additions
and
62 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
from setuptools import setup | ||
|
||
setup( | ||
name='transkribus_fixer', | ||
name='transkribus-to-prima', | ||
version='0.0.1', | ||
author="kba", | ||
author="kba, bertsky", | ||
author_email="unixprog@gmail.com", | ||
url="https://github.com/kba/transkribus-fixer", | ||
url="https://github.com/kba/transkribus-to_prima", | ||
license='Apache License 2.0', | ||
long_description=open('README.md').read(), | ||
long_description_content_type='text/markdown', | ||
install_requires=open('requirements.txt').read().split('\n'), | ||
packages=['transkribus_fixer'], | ||
packages=['transkribus_to_prima'], | ||
entry_points={ | ||
'console_scripts': [ | ||
'transkribus-fixer=transkribus_fixer.cli:cli', | ||
'page-fix-coordinates=transkribus_fixer.cli_coordinate_fixer:cli', | ||
'page-dimensions-from-image=transkribus_fixer.set_dimensions_from_image:cli' | ||
'transkribus-to_prima=transkribus_to_prima.cli:cli', | ||
'page-fix-coordinates=transkribus_to_prima.cli_coordinate_to_prima:cli', | ||
'page-dimensions-from-image=transkribus_to_prima.set_dimensions_from_image:cli' | ||
] | ||
}, | ||
) |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
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,43 @@ | ||
from pkg_resources import resource_filename | ||
from click import command, Choice, File, argument, option | ||
from lxml import etree as ET | ||
|
||
from .convert import TranskribusToPrima, NS | ||
|
||
CONVERTERS = [func[8:] for func in dir(TranskribusToPrima) | ||
if callable(getattr(TranskribusToPrima, func)) and func.startswith('convert_')] | ||
CONVERTERDOCS = [func + ': ' + getattr(TranskribusToPrima, 'convert_' + func).__doc__ for func in CONVERTERS] | ||
CONVERTERS.append('namespace') | ||
CONVERTERDOCS.append('namespace: Also convert PAGE namespace version from 2013 to 2019.') | ||
|
||
|
||
@command(context_settings={'help_option_names': ['-h', '--help']}) | ||
@option('-f', '--convertes', help="Conversions to apply. Repeatable [default: all].\n\n" + "\n\n".join(CONVERTERDOCS), | ||
default=CONVERTERS, type=Choice(CONVERTERS), multiple=True) | ||
@option('-I', '--prefer-imgurl', help="use TranskribusMetadata/@imgUrl for @imageFilename if available", is_flag=True) | ||
@option('-V', '--validate', help="Validate output against schema.", is_flag=True) | ||
@argument('input-file', type=File('r'), nargs=1) | ||
@argument('output-file', default='-', type=File('w'), nargs=1) | ||
def cli(convertes, prefer_imgurl, validate, input_file, output_file): | ||
""" | ||
Transform (Transkribus PAGE) INPUT_FILE to (PRImA PAGE) OUTPUT_FILE under the chosen convertes. | ||
""" | ||
converter = TranskribusToPrima(ET.parse(input_file), prefer_imgurl) | ||
for convert in [f for f in convertes if f != 'namespace']: | ||
getattr(converter, f'convert_{convert}')() | ||
as_str = converter.tostring() | ||
if 'namespace' in convertes: | ||
as_str = as_str.replace(NS['p2013'], NS['p2019']) | ||
if validate: | ||
if 'namespace' not in convertes and converter.tree.getroot().tag == "{%s}PcGts" % NS['p2013']: | ||
schema = resource_filename(__name__, 'page2013.xsd') | ||
else: | ||
schema = resource_filename(__name__, 'page2019.xsd') | ||
schema = ET.parse(schema) | ||
schema = ET.XMLSchema(schema) | ||
#schema.assertValid(converter.tree) # may need namespace converter | ||
schema.assertValid(ET.fromstring(as_str.encode('utf-8'))) | ||
output_file.write(as_str) | ||
|
||
if __name__ == "__main__": | ||
cli() # pylint: disable=no-value-for-parameter |
2 changes: 1 addition & 1 deletion
2
transkribus_fixer/cli_coordinate_fixer.py → transkribus_to_prima/cli_coordinate_fixer.py
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
File renamed without changes.
File renamed without changes.
File renamed without changes.