Skip to main content

Any Texts Statistics (anyTS)

Version Supported Python versions Build Ruff License: MIT

anyTS is the language-independent core of the text statistics libraries ruTS (Russian) and esTS (Spanish). It holds the code that does not depend on a language, so that it is written, tested and documented once; a language library adds its tokenizer, lemmatizer, spaCy model and rules and re-exports the core under its own names.

Documentation · PyPI

Features

  • Extraction - sentence, word and character N-gram extractors whose tokenizer, lemmatizer and number pattern are hooks a language library overrides
  • Lexical diversity - 32 metrics: TTR and its variants, MATTR, MSTTR, MTLD, MA-MTLD, MTLD-W, HD-D, the indices of Simpson and Yule, entropy, the laws of Zipf and Heaps, over the whole text or over windows with confidence intervals
  • Cohesion helpers - the overlap of sentences, adjacent and over all pairs, Dice, givenness and repetition
  • Dependency tree helpers - dependency distances, tree depth, valency and coordination chains on the labels shared by Universal Dependencies and ClearNLP
  • Corpus measures - keywords against a corpus or a frequency dictionary, collocations, the dispersion of a word, Burrows's Delta and its variants, Zeta, Kilgarriff's chi-square, the Mendenhall curve and the comparison of corpora with effect sizes, a bootstrap by texts and the Holm correction
  • Exceptions - one hierarchy whose classes are also built-in exceptions

The reference of every function is a named section that the libraries include in their own documentation, so a formula is described in one place.

Installation

Requires Python 3.11 or newer.

pip install anyts

Or with uv:

uv add anyts

The dependencies are numpy, pandas, scipy and spaCy; no trained spaCy model is needed.

Quick start

>>> from anyts import DiversityStats, SentsExtractor, WordsExtractor

>>> text = "The cat sat on the mat. The dog sat on the log! The cat and the dog slept."

>>> SentsExtractor().extract(text)
('The cat sat on the mat.', 'The dog sat on the log!', 'The cat and the dog slept.')

>>> ds = DiversityStats(WordsExtractor(lowercase=True).extract(text))
>>> ds.ttr, round(ds.entropy, 3)
(0.5, 2.864)

A language library subclasses the extractors and overrides their hooks:

>>> class Words(WordsExtractor):
...     def lemmatize(self, word):
...         return {"sat": "sit", "slept": "sleep"}.get(word.lower(), word)

>>> Words(lowercase=True, use_lexemes=True).extract("The cat sat. The dog slept.")
('the', 'cat', 'sit', 'the', 'dog', 'sleep')

The corpus measures take lists of words:

>>> from anyts.corpus import keyness

>>> cats = WordsExtractor(lowercase=True).extract("The cat sat on the mat. The cat saw a bird. The cat slept.")
>>> dogs = WordsExtractor(lowercase=True).extract("The dog sat on the log. The dog saw a cat. The dog barked.")
>>> [(keyword.word, round(keyword.log_ratio, 2)) for keyword in keyness(cats, dogs, min_freq=2)]
[('cat', 1.58)]

Development

The project uses uv for dependencies and ruff for linting and formatting.

git clone https://github.com/SergeyShk/anyTS.git
cd anyTS

make deps                   # create the environment and install all dependencies
uv run pre-commit install   # hooks: linters on commit, tests on push
make lint                   # ruff check, ruff format --check, mypy
make test-cov               # pytest with doctests and full coverage
make docs-build             # mkdocs build --strict

The full list of commands is in make help. Contribution guidelines are in CONTRIBUTING.md.

License

MIT

Metadata

Release files for anyts 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for anyts 0.1.0
File Size Uploaded
anyts-0.1.0.tar.gz 47.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for anyts 0.1.0
File Interpreter ABI Platform
anyts-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 101.5 kB

Release files / anyts-0.1.0.tar.gz

Download URL anyts-0.1.0.tar.gz
Size 47.4 kB
Tags Source
SHA-256 checksum
How to use checksums
f8168bc0fc94c04870611f5dc5892495ba5bef9d10239e54f85731015ccaad88
BLAKE2b-256 checksum
How to use checksums
6e07c8644870302a7f4ab3e458a9c3e5e93e162cf8af15f450ebb64c8165949a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.19 {"installer":{"name":"uv","version":"0.12.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / anyts-0.1.0-py3-none-any.whl

Download URL anyts-0.1.0-py3-none-any.whl
Size 54.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a8665dd31d80edb8144cf4d535510d12354dcb7f0d33ab3444e33b06004ef1d1
BLAKE2b-256 checksum
How to use checksums
8d0b4de8bb873f248e66ebaadbf3c2fb23de768c101990ef871cfbbe87fe9163
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.19 {"installer":{"name":"uv","version":"0.12.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

0.2.13

2 release files

0.2.12

2 release files

0.2.11

2 release files

0.2.10

2 release files

0.2.9

2 release files

0.2.8

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page