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
  • Statistics interface - the base of every class of statistics: a dictionary of the statistics, nested or flat, a pandas frame, a printed table and the reading of a statistic by its scale
  • Basic statistics - sentences, words, syllables, letters, long and complex words, punctuation marks by type, with the syllables of a language library
  • Readability metrics - Flesch reading ease, Flesch-Kincaid, Coleman-Liau, ARI, SMOG, Gunning fog, LIX, RIX, Legibilidad µ, the consensus grade, the school stage and the reading time, with the coefficients of a language library
  • 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
  • Lexical sophistication - the base of the statistics by a frequency dictionary in the manner of TAALES: coverage, mean frequency, range and dispersion, surprisal and perplexity, frequency bands and lexical density
  • Style metrics - the base of the SEO metrics (nausea, water, spam, naturalness by Zipf's law, keyword density) and of the markers of the officialese, with the lists and the morphology of a language library
  • Cohesion statistics - the base of the referential cohesion in the manner of Coh-Metrix: the overlap of nouns, arguments and content words, adjacent and over all pairs, Dice, givenness, the repetition of the tense and the aspect, and the connectors of a dictionary with the context rules of a language, with the words and the features of a language library
  • Syntactic statistics - the base of the statistics of the dependency tree: dependency distances, tree depth, valency, coordination chains, clauses, modifiers of a noun, participial clauses, the passive, negations and split predicates, with the clauses and the constructions of a language library; tree helpers on the labels shared by Universal Dependencies and ClearNLP and the verb form of a predicate by its auxiliaries
  • Phonetic statistics - the base of the statistics of the sounds: classes of the sounds, consonant clusters, hiatuses, entropy of the CV patterns, alliteration and assonance by a repetition index, open syllables, with the transcription and the syllables of a language library
  • 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, a KWIC concordance
  • Visualization - Zipf's law, vocabulary growth and frequency spectrum, sentence lengths, literature fingerprinting, word tree, corpus and stylometric plots, the labels of the plots as a parameter; the highlighting of a text by layers
  • Components - the base of the spaCy components that put the statistics into an extension of Doc
  • Datasets - the base of a dataset: downloading an archive with a checksum, safe extraction and filters of the records
  • 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, spaCy, matplotlib and graphviz; no trained spaCy model is needed. Rendering the word tree and the network of collocations also needs the executables of Graphviz.

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 --fix, ruff format, 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.3.4

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.3.4
File Size Uploaded Provenance
anyts-0.3.4.tar.gz 150.5 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 322.0 kB

Release files / anyts-0.3.4.tar.gz

Download URL anyts-0.3.4.tar.gz
Size 150.5 kB
Tags Source
SHA-256 checksum
How to use checksums
dc6f0dba27fd87e7ddd617abc8b734bf73d4cad41dda6606ba26994148ae9e0d
BLAKE2b-256 checksum
How to use checksums
56964b33a6c40b077fc1ab86e02e97889519b4b40bf44ba69519591689e6075b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","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.3.4-py3-none-any.whl

Download URL anyts-0.3.4-py3-none-any.whl
Size 171.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
36b64fe7479b1da44ea97c947f2b4a1cce86d538fec4a0361fd9a81308e4c4a5
BLAKE2b-256 checksum
How to use checksums
34f9515026aa72869cecf54194b9f302ee00f1ed94d3f5b9dc967009b3bafa15
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","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}

Security for anyts 0.3.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

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