Skip to content

Commit

Permalink
Merge pull request #51 from Living-with-machines/poetry-config
Browse files Browse the repository at this point in the history
Poetry config
  • Loading branch information
griff-rees authored Nov 29, 2022
2 parents 9cba63d + 90c9b7a commit 34f9433
Show file tree
Hide file tree
Showing 19 changed files with 700 additions and 372 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, 3.8, 3.9]
python-version: ["3.7", "3.8", "3.9", "3.10"]

steps:
- uses: actions/checkout@v2
Expand Down
21 changes: 13 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.2.0
rev: v4.3.0
hooks:
- id: trailing-whitespace
# Leave demo-files unaltered after download from BL website.
Expand All @@ -12,18 +12,23 @@ repos:
- id: check-xml
- id: check-added-large-files
- repo: https://github.com/psf/black
rev: 22.3.0
rev: 22.6.0
hooks:
- id: black
- repo: https://github.com/pre-commit/mirrors-autopep8
rev: 'v1.6.0' # Use the sha / tag you want to point at
rev: v1.6.0 # Use the sha / tag you want to point at
hooks:
- id: autopep8
- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v0.960' # Use the sha / tag you want to point at
rev: v0.971 # Use the sha / tag you want to point at
hooks:
- id: mypy
# - repo: https://github.com/pre-commit/mirrors-isort
# rev: v5.10.1
# hooks:
# - id: isort
- repo: https://github.com/pre-commit/mirrors-isort
rev: v5.10.1
hooks:
- id: isort
- repo: https://github.com/hadialqattan/pycln
rev: v1.2.5
hooks:
- id: pycln
args: [--config=pyproject.toml]
73 changes: 66 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,83 @@ All notable changes to this software will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

Please maintain both this file AND the README.md file.
Please maintain both this file AND the `README.md` file.

## [Unreleased]
## [0.3.4]

### Added
* Added this changelog file.
* Established use of [Semantic Versioning](https://semver.org/spec/v2.0.0.html) for this project.
* Added a separate 'CONTRIBUTING.md' doc for software developers notes.
* Added a separate copyright notice for example datasets
* Added `PyPI` version and `MIT` license badges to `README.md`
* Added `pytest-cov` with default options to assess documentation
* Added `isort` to `.pre-commit-config.yaml` to sort import consistency
* Added `pycln` to `.pre-commit-config.yaml` to check unused imports
* Added `pycln` configuration to `pyproject.toml`
* Added `alto2txt` as a command line script in `pyproject.toml`

### Changed
* Switch from Apache v2.0 license to MIT license, inline with project recommendations.
* Switch from `Apache v2.0` license to `MIT` license, inline with project recommendations.
* Updated `mypy` in `.pre-commit-config.yaml`

### Deprecated
* Replace `extract_publications_text.py` with the `alto2txt` `command line interface` script specified in `pyproject.toml`

### Removed
* `setup.py`
* `requirements.txt`

### Fixed

* Fixed `python = ">3.6.0"` in `pyproject.toml` rather than `>3.7` for consistency with documentation
* Fixed licensing ambiguity (now all should be `MIT`)
* Fixed typos in `README.md`
* Fixed surperflous imports via `pycln` in `pre-commit`

### Security

## v0.3.3

### Added

### Changed

### Deprecated

### Removed

### Fixed

### Security

## v0.3.2

### Added

### Changed

### Deprecated

### Removed

### Fixed

### Security

## v0.3.1

### Added
* Added this changelog file.
* Established use of [Semantic Versioning](https://semver.org/spec/v2.0.0.html) for this project.
* Added a separate `CONTRIBUTING.md` doc for software developers notes.
* Added a separate copyright notice for example datasets

### Changed

### Deprecated

### Removed

### Fixed

### Security

## v0.3.0 and before (prior to 2022-04-27)

Expand Down
8 changes: 5 additions & 3 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
Copyright © 2022 The Alan Turing Institute, British Library Board, Queen Mary University of London, University of Exeter, University of East Anglia and University of Cambridge
MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
Copyright (c) 2020 The Alan Turing Institute, British Library Board, Queen Mary University of London, University of Exeter, University of East Anglia and University of Cambridge

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
61 changes: 30 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Extract plain text from newspapers (alto2txt 0.3.1)
# `alto2txt`: Extract plain text from newspapers

Converts XML (in METS 1.8/ALTO 1.4, METS 1.3/ALTO 1.4, BLN or UKP format) publications to plaintext articles and generates minimal metadata.
![GitHub](https://img.shields.io/github/license/Living-with-Machines/alto2txt) ![PyPI](https://img.shields.io/pypi/v/alto2txt)

Converts `XML` (in `METS` `1.8`/`ALTO` `1.4`, `METS` `1.3`/`ALTO` `1.4`, `BLN` or `UKP` format) publications to plaintext articles and generates minimal metadata.


## [Full documentation and demo instructions.](https://living-with-machines.github.io/alto2txt/#/)
Expand All @@ -14,7 +16,7 @@ We recommend installation via Anaconda:

* Refer to the [Anaconda website and follow the instructions](https://docs.anaconda.com/anaconda/install/).

* Create a new environment for alto2txt
* Create a new environment for `alto2txt`

```bash
conda create -n py37alto python=3.7
Expand All @@ -26,19 +28,19 @@ conda create -n py37alto python=3.7
conda activate py37alto
```

* Install alto2txt itself
* Install `alto2txt` itself

Install `alto2txt` using pip:

```bash
pip install alto2txt
```

(For now it is still necessary to install using pip. In due course we plan to make alto2txt available through a conda channel, meaning that it can be installed directly using conda commands.)
(For now it is still necessary to install using `pip`. In due course we plan to make `alto2txt` available through a `conda` channel, meaning that it can be installed directly using `conda` commands.)

### Installation using pip, outside an Anaconda environment

Note, the use of `alto2txt`` outside a conda environment has not been as extensively tested as within a conda environment. Whilst we believe that this should work, please use with caution.
Note, the use of ``alto2txt`` outside a conda environment has not been as extensively tested as within a conda environment. Whilst we believe that this should work, please use with caution.

```bash
pip install alto2txt
Expand All @@ -54,16 +56,15 @@ pip install -i https://test.pypi.org/simple/ alto2txt==0.3.1a20

## Usage

Downsampling can be used to convert only every Nth issue of each newspaper. One text file is output per article, each complemented by one XML metadata file.
Downsampling can be used to convert only every Nth issue of each newspaper. One text file is output per article, each complemented by one `XML` metadata file.



```
extract_publications_text.py [-h] [-d [DOWNSAMPLE]]
[-p [PROCESS_TYPE]]
[-l [LOG_FILE]]
[-n [NUM_CORES]]
xml_in_dir txt_out_dir
usage: alto2txt [-h] [-p [PROCESS_TYPE]] [-l [LOG_FILE]] [-d [DOWNSAMPLE]] [-n [NUM_CORES]]
xml_in_dir txt_out_dir
alto2txt [-h] [-p [PROCESS_TYPE]] [-l [LOG_FILE]] [-d [DOWNSAMPLE]] [-n [NUM_CORES]]
xml_in_dir txt_out_dir
Converts XML publications to plaintext articles
Expand All @@ -73,19 +74,17 @@ positional arguments:
optional arguments:
-h, --help show this help message and exit
-d [DOWNSAMPLE], --downsample [DOWNSAMPLE]
Downsample. Default 1
-p [PROCESS_TYPE], --process-type [PROCESS_TYPE]
Process type. One of: single,serial,multi,spark Default: multi
-l [LOG_FILE], --log-file [LOG_FILE]
Log file. Default out.log
-p [PROCESS_TYPE], --process-type [PROCESS_TYPE]
Process type.
One of: single,serial,multi,spark
Default: multi
-d [DOWNSAMPLE], --downsample [DOWNSAMPLE]
Downsample. Default 1
-n [NUM_CORES], --num-cores [NUM_CORES]
Number of cores (Spark only). Default 1")
```

`xml_in_dir` is expected to hold XML for multiple publications, in the following structure:
`xml_in_dir` is expected to hold `XML` for multiple publications, in the following structure:

```
xml_in_dir
Expand All @@ -97,7 +96,7 @@ xml_in_dir
|-- publication
```

However, if `-p|--process-type single` is provided then `xml_in_dir` is expected to hold XML for a single publication, in the following structure:
However, if `-p|--process-type single` is provided then `xml_in_dir` is expected to hold `XML` for a single publication, in the following structure:

```
xml_in_dir
Expand All @@ -118,41 +117,41 @@ xml_in_dir

`DOWNSAMPLE` must be a positive integer, default 1.

The following XSLT files need to be in an `extract_text.xslts` module:
The following `XSLT` files need to be in an `extract_text.xslts` module:

* `extract_text_mets18.xslt`: METS 1.8 XSL file.
* `extract_text_mets13.xslt`: METS 1.3 XSL file.
* `extract_text_bln.xslt`: BLN XSL file.
* `extract_text_ukp.xslt`: UKP XSL file.
* `extract_text_mets18.xslt`: `METS 1.8 XSL` file.
* `extract_text_mets13.xslt`: `METS 1.3 XSL` file.
* `extract_text_bln.xslt`: `BLN XSL` file.
* `extract_text_ukp.xslt`: `UKP XSL` file.

## Process publications

Assume `~/BNA` exists and matches the structure above.
Assume folder `BNA` exists and matches the structure above.

Extract text from every publication:

```bash
./extract_publications_text.py ~/BNA txt
alto2txt BNA txt
```

Extract text from every 100th issue of every publication:

```bash
./extract_publications_text.py ~/BNA txt -d 100
alto2txt BNA txt -d 100
```

## Process a single publication

Extract text from every issue of a single publication:

```bash
./extract_publications_text.py -p single ~/BNA/0000151 txt
alto2txt -p single BNA/0000151 txt
```

Extract text from every 100th issue of a single publication:

```bash
./extract_publications_text.py -p single ~/BNA/0000151 txt -d 100
alto2txt -p single BNA/0000151 txt -d 100
```

## Configure logging
Expand All @@ -162,7 +161,7 @@ By default, logs are put in `out.log`.
To specify an alternative location for logs, use the `-l` flag e.g.

```bash
./extract_publications_text.py -l mylog.txt ~/BNA txt -d 100 2> err.log
alto2txt -l mylog.txt BNA txt -d 100 2> err.log
```

## Process publications via Spark
Expand Down
Loading

0 comments on commit 34f9433

Please sign in to comment.