# -*- coding: utf-8 -*-
from setuptools import setup

packages = \
['criticus',
 'criticus.py',
 'criticus.py.cbgm_interface',
 'criticus.py.export_to_docx',
 'criticus.py.md2tei',
 'criticus.py.reformat_collation',
 'criticus.py.serve_tei_transcriptions',
 'criticus.py.tei2json',
 'criticus.py.txt2json',
 'criticus.resources']

package_data = \
{'': ['*']}

install_requires = \
['Markdown==3.2.2',
 'PySimpleGUI>=4.57.0,<5.0.0',
 'lxml>=4.8.0,<5.0.0',
 'markdown-del-ins>=1.0.0,<2.0.0',
 'natsort>=8.1.0,<9.0.0',
 'python-docx>=0.8.11,<0.9.0']

setup_kwargs = {
    'name': 'criticus',
    'version': '0.21.1',
    'description': 'A suite of tools for transcribing, collating and and creating an apparatus criticus.',
    'long_description': '# Criticus\nThis is a collection of computer tools for aiding the text critical workflow from transcription to collation to analysis.\nSome of the tools already exist as CLI\'s that I have made, but here are are collected into one place and converted to user-friendly GUI applications.\n\n(Note: Criticus was formerly known as Tendon. I needed to change the name so that I could publish to PYPI).\n\n## The Problem I\'m trying to Solve\nThe standard tool for transcribing ancient New Testament manuscripts ([ITSEE\'s OTE](https://itsee-wce.birmingham.ac.uk/ote/transcriptiontool)) produces files in an entirely different format from that required by the standard tool for collating these transcriptions ([the WCE Collation Editor](https://github.com/itsee-birmingham/standalone_collation_editor)).\n\nMoving from transcription to collation to analysis requires several steps of intermediate conversion of the data along the way. Criticus is a collection of tools to help \'connect\' these three basic tasks.\n\n## What Criticus Does\nCriticus is a desktop app with ten distinct tools:\n1. Convert a plain text transcription of a chapter or other unit into single-verse JSON files properly formatted for use in the Collation Editor. This is the simplest way to get data into the Collation Editor.\n2. Get a consolidated plain text file from an entire folder of JSON files.\n3. Convert a repurposed superset of Markdown to TEI XML. Included is a graphical user interface (GUI) to my CLI [MarkdownTEI](https://github.com/d-flood/MarkdownTEI). This is presented as simple and offline alternative to the [Online Transcription Editor (OTE)](https://itsee-wce.birmingham.ac.uk/ote/transcriptiontool). MarkdownTEI converted files can even be uploaded to the OTE.\n4. Convert TEI transcriptions (from MarkdownTEI or the OTE) to single-verse JSON files for use in the Collation Editor. This is a GUI version of my [TEI to JSON](https://github.com/d-flood/TEI-to-JSON) CLI.\n5. Combine any number of single-verse collation files produced by the Collation Editor.\n6. Reformat the collation file output of the Collation Editor for use with the [open-cbgm](https://github.com/jjmccollum/open-cbgm-standalone) and with Apparatus Explorer (a [desktop](https://github.com/d-flood/apparatus-explorer) and [web app](https://davidaflood.com/appex/demo/)) for visualization and editing.\n7. Provide a simple way to view TEI XML transcriptions offline using the same styling as the [IGNTP online transcriptions](http://www.itseeweb.bham.ac.uk/epistulae/XML/igntp.xml).\n8. Provide an interface to conveniently edit the project configuration. This is how one chooses which witnesses to collate, and which witness should be the basetext.\n9. A simple graphical interface for the [open-cbgm](https://github.com/jjmccollum/open-cbgm-standalone) CLI application. This tool is windows only right now.\n10. Export the TEI XML output of the ITSEE Collation Editor to a Microsoft Word DOCX file suitable for print publication.\n\n## Installation\n### Windows standalone version\nDownload and install the MSI from the zip file in the latest latest [release](https://github.com/d-flood/Criticus/releases).\n\nI will soon release this as a simple executable instead.\n\n### MacOS standalone version\nDownload and install the DMG from the dmg.zip in the latest latest [release](https://github.com/d-flood/Criticus/releases).\n\nThe standalone version does not work on the new M1 chip. The next easiest way to run Criticus is by installing Python and launching from a terminal (see below).\n\n### Run on any platform with Python 3.8+\n- Install the latest version of Python from https://www.python.org/\n- Open a terminal and type in the following commands, typing Enter/Return after each.\n   - On Windows: \n      - `pip install criticus`\n      - `python -m criticus`\n   - On MacOS: \n      - `pip3 install criticus`\n      - `python3 -m criticus`\n\n### Download and run the source code\n\nDependencies\n- python 3.8+\n- `lxml`\n- `natsort`\n- `PySide2`\n- `PySimpleGUI`\n- `Markdown==3.2.2`\n- `markdown-del-ins`\n- `python-docx`\n\nWith the dependencies installed, go to `<root>/` and call `python -m criticus`\n\n## Brief Tutorial\nPlease [contact](https://www.davidaflood.com/contact/), message me on Twitter, or fill out a GitHub issue for help using these tools and to report bugs. There are certain to be untested edge cases especially when converting TEI to JSON.\n\n![screenshot of Criticus\'s main window](images/Criticus_main_window.png)\n\n### Plain Text to JSON Files\n![screenshot of plain text to json window](images/plain_text_to_json_window.png)\nThe structure of the plain text (.txt) file is important. Criticus assumes:\n- One verse (or other unit) per line\n- Each line begins with the verse number\n- There is no more than one whole chapter (or other complete unit) per file\n\n1. Choose whether to convert all verses in a text file or to convert a range of verses (can be one verse, e.g. \'3 to 3\').\n   - If "Range of verses" is selected, than a first (\'from\') and last (\'to\') verse must be entered. These input values must match verse numbers in the file, e.g. \'7 to 12\' *not* \'1:7 to 1:12\'.\n   - If "All verses in file" is selected, then every verse will be converted to a different JSON file.\n2. Choose whether to provide Criticus with the witness siglum or to have Criticus try and get this information from the input text file name.\n   - If "Manual" is selected, then Criticus will use the user provided siglum and unit prefix.\n     - The siglum is an identifier for the witness, e.g. \'P52\'\n     - The unit prefix is whatever needs to be added to the verse number to make it a full reference. This is normally the book and chapter (*with no spaces*), e.g. "Rom14", "Rom_14", "R14", "B06K14V". With this information, Criticus can create the correct directories and filenames for every verse to be converted.\n   - If "Auto from file name" is selected, then Criticus will get the siglum and unit prefix from the file name *if the following convention is observed:* `<siglum>_<unit prefix>.txt`. That is, the filename should consist of the siglum, followed by an underscore, followed by the book and chapter. E.g., `P46_Rom14.txt`.\n3. Choose the output directory by clicking "Browse" and navigating to the right folder.\n   - If you have downloaded the Collation Editor, go to that folder and to `/collation/data/textrepo/json/`. This is where the Collation Editor expects the transcription files to be.\n4. Finally, click "Convert File".\n   - You will be prompted to select a plain text file.\n   - Upon selecting it Criticus will attempt to convert the specified verses from the file and save them into the chosen output directory.\n   - Criticus creates a folder in the output directory named after the siglum and then deposits the converted verses from that witness into the folder.\n   - Criticus also creates and places a `metadata.json` file that must exist for the Collation Editor to work.\n5. Caution. If you have many plain text transcription files in the same folder, and all adhere to the naming convention required by "auto from file name", then all chapter files can be converted at once by clicking "Convert Directory". \n   - This can easily result in the creation of hundreds or thousands of JSON files (which may be what you want!). So, make sure to test one of the files to ensure that its format is compatible and that the result is satisfactory before converting an entire folder.\n\n### Get Plain Text from JSON Files\n![Get Plain Text from JSON Files window screenshot](images/text_from_json_window.png)\n\nThis is a simple module for extracting the plain text of the first hand of a witness and exporting it as plain text. The output of this feature will produce a single plain text file with one verse per line, each line started with the verse number, and chapter headings.\n1. Select a folder that contains the JSON files from which a plain text version is to be extracted. These JSON files are assumed to have been produced by Criticus.\n2. Click "Get Text".\n3. You will be prompted to save the text file.\n\n### MarkdownTEI\nThis tool began as a [CLI](https://github.com/d-flood/MarkdownTEI) but here it is much more user-friendly as a GUI.\n![MarkdownTEI tool screenshot of window](images/markdown_to_tei_window.png)\n1. Choose how Criticus should format the converted transcription file. All options can be read by a computer but they differ most in human-readability.\n   - "Do not add extra whitespace"\n    ![example of no added whitespace](images/markdown_to_tei/no_extra_whitespace.png)\n   - "Keep transcription lines"\n    ![example of lines kept together](images/markdown_to_tei/keep_lines_example.png)\n   - "Pretty Print"\n    ![example of pretty printed xml](images/markdown_to_tei/pretty_print.png)\n2. Select the Markdown (.md) file to be converted by clicking "Browse".\n   - You will then be prompted to choose the converted file\'s location and name.\n\n### TEI to JSON\nThis is the most difficult task. The TEI XML produced by the WYSIWYG OTE is very flexible and it is difficult to predict all of the possible combinations and nested encodings. Please tell me about bugs and edge cases.\n![screenshot of TEI to JSON window](images/tei_to_json_window.png)\n1. Select the TEI transcription file to be converted.\n   - This can be the output of MarkdownTEI (most reliable) or the OTE.\n2. Choose whether to convert all of the TEI transcription file or one verse.\n   - Converting one verse is useful for correcting errors discovered in transcriptions during the collation process.\n   - When working with TEI transcriptions, the verse reference format follows the IGNTP/INTF style, e.g. "B06K13V1" (B06 = Romans, K13 = chapter 13, V1 = verse 1).\n3. Select the output folder where chapter folders and verse files are created and saved.\n   - This should be located by going to the root folder of the Collation Editor and navigating to `/collation/data/textrepo/json/`.\n4. Then click "Convert".\n\n### Combine Collation Files\nI\'ve found that the Collation Editor fails to process more than a dozen verses at one time and it is best used one verse at a time. For analysis, these individual verse collation files should be combined into chapter and book length files.\n![screenshot of Combine Collation Files window](images/combine_xml_collation_files_window.png)\n1. Navigate to the folder that contains all of the files you want to combine by clicking "Browse".\n2. Enter a bit of text to filter all files to be combined.\n   - E.g., entering "Rom13" would combine "Rom13.1.xml" and "Rom13.2.xml" but not "Rom14.1.xml" while entering "Rom" would result in combining them all.\n3. Click "Combine XML Files". You will then be prompted to select the name and location of the combined file.\n\n### Reformat Collation File\nThe output of the Collation Editor has several redundancies and lacks some useful features that are needed for the file to be used as input for the open-cbgm or the Apparatus Explorer.\n![screenshot of Reformat Collation File window](images/reformat_collation_file_window.png)\n1. Select an XML collation file that was combined during the previous step by clicking "Browse".\n2. Click "Convert". You will then be prompted to save the reformatted file.\n\n### View TEI Transcriptions\nThis is a simple way to view TEI transcriptions with the same styling applied to equivalent TEI transcriptions by the IGNTP.\n![screenshot of View TEI Transcriptions window](images/tei_viewer_window.png)\n1. Select a folder that has one or more TEI transcriptions in it. TEI transcriptions created with MarkdownTEI will work automatically, while others will need to have the style linking element inserted.\n2. Click "Launch TEI Transcription Viewer".\n   - For MacOS users, ensure that Firefox is installed since this stylesheet was created by ITSEE and the IGNTP for Firefox.\n   - Launching the viewer starts a local server and launches Firefox on MacOS and the default browser on Windows.\n    ![screenshot of browser viewing a directory](images/tei_viewer/firefox_tei_dir.png)\n   - Click on a TEI transcription to view it fully formatted and styled.\n    ![screenshot of browser viewing TEI transcription with stylesheet linked](images/tei_viewer/transcription_visualization_example.png)\n\n### Configure Collation Editor\nThe WCE Collation Editor is configured by manually editing a config file located at `<root>/collation/data/project/default/config.json`. The Collation Editor is launched by a convenient start up script distributed with the Collation Editor (`startup.sh` for MacOS and `startup.bat` for Windows). This module of Criticus provides convenient access to the important values in the config file. This module also contains a shortcut for launching the Collation Editor.\n\nNote, however, that the Collation Editor has its own dependencies: Python 3 and the JVM.\n\n![screenshot of the collation editor configuration file editor window](images/ce_config_window.png)\n\n1. Browse for the config file. Begin in the root folder of the Collation Editor and go to `/collation/data/project/default/config.json`. Once it is selected, click "Update" at the bottom to load the configuration settings.\n2. The "Project Title" is not important. Change it to whatever you like. It will be displayed in the Collation Editor.\n3. The "Basetext" is whichever witness you want all others to be collated against. The basetext must be prepared as json files just like any other witness.\n4. The "Witnesses" section tells the Collation Editor which witnesses should be included in the collation. This might change from verse to verse, but most likely it will not, since missing witnesses will be interpreted as lacunose for the entire verse.\n5. Add a witness to the list by typing its siglum or witness ID into the field and pressing "Enter" or clicking "Add Witness".\n6. Select one or more witnesses from the list, then click "Delete Selected" to remove these from the configuration file.\n7. "Update" is only needed to save the "Project Title" and "Basetext". The "Witnesses" are saved any time one is added or deleted.\n8. "Start Collation Editor" will attempt to locate the appropriate start up script and execute it. It will also attempt to open Firefox (by far the best for working in the Collation Editor) to the right port.\n\n### open-cbgm Interface\nThis is a GUI front end for [Joey McCollum\'s open-cbgm: a flexible and fast implementation](https://github.com/jjmccollum/open-cbgm-standalone) of the Coherence Based Genealogical Method. Only a few of the open-cbgm features are implemented in this interface at present. More will be added as I need them for my own research.\n\n#### Manage Databases\nThe first tab of this interface is a prerequisite for doing anything with the open-cbgm.\n![screenshot of the open-cbgm \'populate database\' module](images/open-cbgm/populate_database_tab_screenshot.png)\nThe two prerequisites for using the open-cbgm are:\n1. Having an XML collation file with which to feed the open-cbgm. This can be created by hand, but normally this will be the output of the output of the Collation Editor (see "Combine Collation Files" and "Reformat Collation File" above).\n2. Installing the open-cbgm. Joey has provided [excellent instructions](https://github.com/jjmccollum/open-cbgm-standalone#installation-and-dependencies) for Windows, Mac, and Linus.\n\nUsing Criticus with the open-cbgm:\n1. The first (and one time) step is to tell Criticus where you have installed the open-cbgm, and specifically to designate the folder containing the executable files (files ending in ".exe" on Windows).\n2. Browse and select an XML collation file (which should be prepared using the steps mentioned above).\n3. The open-cbgm takes the XML file as input and produces a database. Enter a name for this database. You can create many databases. I recommend naming the database in a way that indicates its content and settings (see next steps below). \n- The remaining options are optional. See Joey\'s [documentation](https://github.com/jjmccollum/open-cbgm-standalone#population-of-the-genealogical-cache) for what these options do. Remember that this is merely an interface for his software.\n4. Check the "Readings Threshold" box to limit witnesses to those that are extant at a given number of variation units. Enter this number in the field on the right.\n5. Check the "Treat as Trivial" box to designate which reading types should be treated as agreeing with their parent reading. Enter one or more reading types separated by a space or comma and space. \n   - NOTE: This presumes that reading types have been added to the XML collation file.\n   - Some reading types are added with the Collation Editor: "subreading" is a type added automatically to any reading that has been regularized by the user during collation.\n   - Custom reading types can be added by hand in the XML file, or by using my [Apparatus Explorer](https://github.com/d-flood/apparatus-explorer) in either its desktop or web application version.\n6. Check the "Exclude" box to designate reading type(s) to be entire omitted and treated as lacunose.\n7. Checking "Merge Split Attestations" will "will treat split attestations of the same reading as equivalent for the purposes of witness comparison."\n8. Finally, decide whether to use Joey McCollum\'s updated rules (standard) for genealogical relationships or to use the same rules used by INTF\'s implementation (classic).\n9. Click "Populate Database" to have Criticus call the open-cbgm with the settings and options provided.\n10. The newly created database will be added to the list of databases. Note that selecting and deleting a database is permanent.\n\n#### Compare Witnesses\nThis tab is for getting and viewing pre-genealogical coherence. It can be exported or viewed in multiple formats.\n![screenshot of the "compare witnesses" tab before submitting a request](images/open-cbgm/compare_witneses_starting_tab_screenshot.png)\n\n1. Select a database from the drop down menu. The options here are those created on the "Manage Databases" tab.\n2. Enter a witness to which all others will be compared. If the witness does not exist in your collation, you will get an error message.\n3. Select "Compare All Witnesses" to compare all witnesses in the original collation file against the one entered or\n4. select "Compare only these" to designate a more limited comparison. You can enter one or more witnesses to compare against the target witness.\n5. Press ENTER or click "Compare" to fill out the table with the comparison data. The completeness of the table depends upon how much was edited in the collation file _after_ it was produced by the Collation Editor. By default, there will be little to no genealogical data because this is not done during collation with the Collation Editor. I recommend using Apparatus Explorer to add genealogical relationships to the collation file. ![screenshot of the "Compare Witnesses" tab table filled in with collation data](images/open-cbgm/compare_witnesses_filled_tab_screenshot.png)\n- This table is a simplification of the output from the open-cbgm. The full output can saved or viewed in the following ways:\n  1. "Save as CSV" will save the data as a CSV file that can then be opened in Excel or any spreadsheet software.\n  2. "View Plain Text" opens a popup with the full text output of the open-cbgm as one would see when operating the CLI. ![Screenshot of plain text output of the "Compare Witnesses" tab](images/open-cbgm/compare_witnesses_plain_text_screenshot.png)\n\n#### Export XML Collation File to DOCX (Microsoft Word)\nThis feature is working and ready, detailed instructions to come...\n\n#### More features of the open-cbgm will be added over time.',
    'author': 'David Flood',
    'author_email': 'davidfloodii@gmail.com',
    'maintainer': None,
    'maintainer_email': None,
    'url': 'https://github.com/d-flood/criticus',
    'packages': packages,
    'package_data': package_data,
    'install_requires': install_requires,
    'python_requires': '>=3.8,<4.0',
}


setup(**setup_kwargs)
