Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework packaging settings to ensure data files are included #361

Merged
merged 5 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
restore-keys: |
${{ runner.os }}-pip-
- run: pip install -r ci-requirements.txt
- run: python setup.py develop
- run: python -m pip install --editable .
- run: python -m unittest

coverage:
Expand All @@ -51,6 +51,6 @@ jobs:
restore-keys: |
${{ runner.os }}-pip-
- run: pip install -r ci-requirements.txt
- run: python setup.py develop
- run: python -m pip install --editable .
- run: coverage run -m unittest
- uses: codecov/codecov-action@v1
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
with:
python-version: 3.8
- run: pip install -r dev-requirements.txt
- run: python setup.py sdist bdist_wheel
- run: python -m build
- run: twine upload dist/*
env:
TWINE_USERNAME: ${{ secrets.TWINE_USERNAME }}
Expand Down
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include dphon/data
graft dphon/data
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# dphon

[![ci](https://github.com/direct-phonology/dphon/workflows/ci/badge.svg)](https://github.com/direct-phonology/dphon/actions?query=workflow%3Aci)
[![codecov](https://codecov.io/gh/direct-phonology/dphon/branch/main/graph/badge.svg?token=uGbgB5UFtk)](https://codecov.io/gh/direct-phonology/dphon)
![pyversions](https://img.shields.io/pypi/pyversions/dphon.svg?style=flat)
Expand All @@ -19,6 +20,7 @@ if you're on windows and are seeing incorrectly formatted output in your termina
## usage

### basics

the main function of `dphon` is to look for instances of text reuse in a corpus of old chinese texts. instead of relying purely on graphemes, it does this by performing grapheme-to-phoneme conversion, and determining possible reuse based on whether passages are likely to have _sounded_ similar (or rhymed) when spoken aloud.

you will need to have files stored locally as utf-8 encoded plain-text (`.txt`) or json-lines (`.jsonl`) format. for the former, one file is assumed to represent one document. for the latter, one file can contain any number of lines, each of which is a document, with required keys `id` (a unique identifier) and `text` (text content) and any number of optional keys. you can obtain a representative corpus of old chinese sourced from the kanseki repository via [`direct-phonology/ect-krp`](https://github.com/direct-phonology/ect-krp).
Expand All @@ -42,7 +44,7 @@ which would look for phonetically similar passages between `text_a` and `text_b`

the numbers next to the identifiers are _token indices_, and may vary depending on how the text is tokenized – `dphon` currently uses character-based tokenization. whitespace will be removed, and the output will be aligned to make it easier to spot differences between the two sequences. by default, insertions are highlighted in green, and mismatches (differences between the two sequences) are highlighted in red. additional (non-matching) context added to either side of match sequences is displayed using a dimmed color (see "advanced usage" below for more information on colorization).

matches are sorted by the ratio of their phomenic similarity to their graphic similarity – in other words, matches between texts that sound highly similar but were written very differently will be at the top of the list.
matches are sorted by the ratio of their phomenic similarity to their graphic similarity – in other words, matches between texts that sound highly similar but were written very differently will be at the top of the list.

by default, `dphon` only returns matches that display at least one instance of _graphic variation_ – a case where two different graphemes are used in the same place to represent the same sound. these cases are highlighted in blue. if you're interested in all instances of reuse, regardless of graphic variation, you can use the `--all` flag:

Expand All @@ -51,16 +53,19 @@ $ dphon --all text_a.txt text_b.txt
```

you can view the full list of command options with:

```sh
$ dphon --help
```

this tool is under active development, and results may vary. to find the version you are running:

```sh
$ dphon --version
```

### advanced usage

by default, `dphon` uses your system's `$PAGER` to display output, since the results can be quite long. on MacOS and Linux, this will likely be `less`, which supports additional options like searching through the output once it's displayed. for more information, see the man page:

```sh
Expand Down Expand Up @@ -100,7 +105,7 @@ if two characters have the same phonemes, they're treated as a match. for charac

in version 1.0, `dphon`'s default reconstruction was based on Schuessler 2007[<sup>1</sup>](#note1), but used a single "dummy" character to represent all the lexemes in a rhyming group. [the dictionary](dphon/data/sound_table_v1.json) was compiled by John O'Leary ([@valgrinderror](https://github.com/valgrinderror)) and Gian Duri Rominger ([@GDRom](https://github.com/GDRom)). since version 2.0, `dphon` uses [a dictionary](dphon/data/sound_table_v2.json) based on the Baxter-Sagart 2014 reconstruction[<sup>2</sup>](#note2), with additional work by Rominger.

the matching algorithm is based on Paul Vierthaler's [`chinesetextreuse`](https://github.com/vierth/chinesetextreuse) project[<sup>3</sup>](#note3), with some modifications. it uses a [BLAST](https://en.wikipedia.org/wiki/BLAST_(biotechnology))-like strategy to identify initial match candidates, and then extend them via phonetic [edit distance](https://en.wikipedia.org/wiki/Edit_distance) comparison. finally, the results are aligned using a version of the [Smith-Waterman algorithm](https://en.wikipedia.org/wiki/Smith%E2%80%93Waterman_algorithm) that operates on phonemes, powered by the `lingpy` library[<sup>4</sup>](#note4).
the matching algorithm is based on Paul Vierthaler's [`chinesetextreuse`](https://github.com/vierth/chinesetextreuse) project[<sup>3</sup>](#note3), with some modifications. it uses a [BLAST](<https://en.wikipedia.org/wiki/BLAST_(biotechnology)>)-like strategy to identify initial match candidates, and then extend them via phonetic [edit distance](https://en.wikipedia.org/wiki/Edit_distance) comparison. finally, the results are aligned using a version of the [Smith-Waterman algorithm](https://en.wikipedia.org/wiki/Smith%E2%80%93Waterman_algorithm) that operates on phonemes, powered by the `lingpy` library[<sup>4</sup>](#note4).

## development setup

Expand Down Expand Up @@ -133,22 +138,25 @@ $ pip install -e .
now your changes will be automatically picked up when you run `dphon`.

pull requests can be made against `main`.

## code documentation

code documentation is [available on github pages](https://direct-phonology.github.io/dphon) and is generated with `pdoc3`.

to build the docs:

```sh
$ pdoc --html --output-dir docs dphon
```

## tests

unit tests are written with `unittest`. you can run them with:

```sh
$ python -m unittest
```


## releases

the package is built and published to pyPI automatically using `twine` when using GitHub's release functionality.
Expand Down
2 changes: 1 addition & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-r requirements.txt
coverage
wheel
build
twine
setuptools
pdoc3
2 changes: 1 addition & 1 deletion dphon/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2.0.3"
__version__ = "2.0.4"
60 changes: 59 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,61 @@
[build-system]
requires = ["setuptools>=42", "wheel"]
build-backend = "setuptools.build_meta"
build-backend = "setuptools.build_meta"

[project]
name = "dphon"
readme = "README.md"
description = "Tools and algorithms for phonology-aware Early Chinese NLP."
dynamic = ["version"]
license = { file = "LICENSE" }
keywords = ["old chinese", "early chinese", "phonology", "linguistics", "nlp"]
classifiers = [
"Environment :: Console",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: MIT License",
"Natural Language :: Chinese (Traditional)",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Topic :: Text Processing :: Linguistic",
"Topic :: Utilities",
]
dependencies = [
"docopt",
"spacy>=3",
"python-levenshtein",
"lingpy",
"rich",
"jsonlines",
]
authors = [
{ name = "Nick Budak", email = "[email protected]" },
{ name = "Gian Duri Rominger", email = "[email protected]" },
]
requires-python = ">=3.8"

[project.urls]
Repository = "https://github.com/direct-phonology/dphon"
Issues = "https://github.com/direct-phonology/dphon/issues"
Documentation = "https://direct-phonology.github.io/dphon/"

[project.optional-dependencies]
dev = ["check-manifest", "mypy", "pylint"]
test = ["coverage"]

[project.entry-points.console_scripts]
dphon = "dphon.cli:run"

[project.entry-points.spacy_factories]
ngrams = "dphon.ngrams:create_ngrams"
g2p = "dphon.g2p:create_graphemes_to_phonemes"
ngram_phonemes_index = "dphon.index:create_ngram_phonemes_lookup_index"

[tool.setuptools]
packages = ["dphon"]

[tool.setuptools.dynamic]
version = { attr = "dphon.__version__" }
2 changes: 0 additions & 2 deletions setup.cfg

This file was deleted.

59 changes: 0 additions & 59 deletions setup.py

This file was deleted.

Loading