1
0
mirror of https://github.com/ilri/csv-metadata-quality.git synced 2024-12-22 12:12:18 +01:00
A simple but opinionated metadata quality checker and fixer designed to work with CSVs in the DSpace ecosystem.
Go to file
Alan Orth 8435ee242d
Experimental language detection using langid
Works decenty well assuming the title, abstract, and citation fields
are an accurate representation of the language as identified by the
language field. Handles ISO 639-1 (alpha 2) and ISO 639-3 (alpha 3)
values seamlessly.

This includes updated pipenv environment, test data, pytest tests
for both correct and incorrect ISO 639-1 and ISO 639-3 languages,
and a new command line option "-e".
2019-09-26 13:46:32 +03:00
csv_metadata_quality Experimental language detection using langid 2019-09-26 13:46:32 +03:00
data Experimental language detection using langid 2019-09-26 13:46:32 +03:00
tests Experimental language detection using langid 2019-09-26 13:46:32 +03:00
.build.yml Update tests 2019-08-01 23:59:11 +03:00
.flake8 Add flake8 to pipenv dev environment 2019-07-28 17:46:30 +03:00
.gitignore .gitignore: Ignore egg cache from distutils 2019-07-31 17:38:54 +03:00
.travis.yml .travis.yml: Only test Python 3.6 and 3.7 2019-07-29 12:13:55 +03:00
CHANGELOG.md CHANGELOG.md: Update notes 2019-09-24 18:55:05 +03:00
LICENSE.txt Add GPLv3 license 2019-07-26 22:16:16 +03:00
Pipfile Experimental language detection using langid 2019-09-26 13:46:32 +03:00
Pipfile.lock Pipfile.lock: Run pipenv update 2019-09-24 18:54:49 +03:00
pytest.ini pytest.ini: Ignore deprecation warnings 2019-07-31 13:33:20 +03:00
README.md README.md: Update comment about ISO 639-3 2019-09-26 07:51:41 +03:00
requirements-dev.txt Update requirements-dev.txt 2019-08-29 01:25:14 +03:00
requirements.txt Update python requirements 2019-08-28 21:01:48 +03:00
setup.cfg Add configuration for isort 2019-08-29 01:14:31 +03:00
setup.py Release version 0.2.2 2019-08-28 00:10:17 +03:00

CSV Metadata Quality Build Status builds.sr.ht status

A simple, but opinionated metadata quality checker and fixer designed to work with CSVs in the DSpace ecosystem. The implementation is essentially a pipeline of checks and fixes that begins with splitting multi-value fields on the standard DSpace "||" separator, trimming leading/trailing whitespace, and then proceeding to more specialized cases like ISSNs, ISBNs, languages, etc.

Requires Python 3.6 or greater. CSV and Excel support comes from the Pandas library, though your mileage may vary with Excel because this is much less tested.

Functionality

  • Validate dates, ISSNs, ISBNs, and multi-value separators ("||")
  • Validate languages against ISO 639-1 (alpha2) and ISO 639-3 (alpha3)
  • Validate subjects against the AGROVOC REST API (see the --agrovoc-fields option)
  • Fix leading, trailing, and excessive (ie, more than one) whitespace
  • Fix invalid multi-value separators (|) using --unsafe-fixes
  • Fix problematic newlines (line feeds) using --unsafe-fixes
  • Remove unnecessary Unicode like non-breaking spaces, replacement characters, etc
  • Check for "suspicious" characters that indicate encoding or copy/paste issues, for example "foreˆt" should be "forêt"
  • Remove duplicate metadata values

Installation

The easiest way to install CSV Metadata Quality is with pipenv:

$ git clone https://github.com/ilri/csv-metadata-quality.git
$ cd csv-metadata-quality
$ pipenv install
$ pipenv shell

Otherwise, if you don't have pipenv, you can use a vanilla Python virtual environment:

$ git clone https://github.com/ilri/csv-metadata-quality.git
$ cd csv-metadata-quality
$ python3 -m venv venv
$ source venv/bin/activate
$ pip install -r requirements.txt

Usage

Run CSV Metadata Quality with the --help flag to see available options:

$ csv-metadata-quality --help

To validate and clean a CSV file you must specify input and output files using the -i and -o options. For example, using the included test file:

$ csv-metadata-quality -i data/test.csv -o /tmp/test.csv

Unsafe Fixes

You can enable several "unsafe" fixes with the --unsafe-fixes option. Currently this will attempt to fix invalid multi-value separators and remove newlines.

Invalid Multi-Value Separators

This is considered "unsafe" because it is theoretically possible for a single | character to be used legitimately in a metadata value, though in my experience it is always a typo. For example, if a user mistakenly writes Kenya|Tanzania when attempting to indicate two countries, the result will be one metadata value with the literal text Kenya|Tanzania. The --unsafe-fixes option will correct the invalid multi-value separator so that there are two metadata values, ie Kenya||Tanzania.

Newlines

This is considered "unsafe" because some systems give special importance to vertical space and render it properly. DSpace does not support rendering newlines in its XMLUI and has, at times, suffered from parsing errors that cause the import process to fail if an input file had newlines. The --unsafe-fixes option strips Unix line feeds (U+000A).

AGROVOC Validation

You can enable validation of metadata values in certain fields against the AGROVOC REST API with the --agrovoc-fields option. For example, in addition to agricultural subjects, many countries and regions are also present AGROVOC. Enable this validation by specifying a comma-separated list of fields:

$ csv-metadata-quality -i data/test.csv -o /tmp/test.csv -u --agrovoc-fields dc.subject,cg.coverage.country
...
Invalid AGROVOC (dc.subject): FOREST
Invalid AGROVOC (cg.coverage.country): KENYAA

Note: Requests to the AGROVOC REST API are cached using requests_cache to speed up subsequent runs with the same data and to be kind to the system's administrators.

Todo

  • Reporting / summary
  • Better logging, for example with INFO, WARN, and ERR levels
  • Verbose, debug, or quiet options
  • Warn if an author is shorter than 3 characters?
  • Validate dc.rights field against SPDX? Perhaps with an option like -m spdx to enable the spdx module?
  • Validate DOIs? Normalize to https://doi.org format? Or use just the DOI part: 10.1016/j.worlddev.2010.06.006
  • Warn if two items use the same file in filename column
  • Add an option to drop invalid AGROVOC subjects?
  • Add check for author names with incorrect spacing after commas, ie "Orth,Alan S."
  • Add tests for application invocation, ie tests/test_app.py?

License

This work is licensed under the GPLv3.

The license allows you to use and modify the work for personal and commercial purposes, but if you distribute the work you must provide users with a means to access the source code for the version you are distributing. Read more about the GPLv3 at TL;DR Legal.