Repository navigation
0.4.0
The fourth release of anyTS, the language-independent core of the text statistics libraries ruTS (Russian) and esTS (Spanish).
New in this release:
- morphological statistics and readability formulas with their original coefficients;
- new measures of syntax, cohesion and lexical diversity;
- keywords by n-grams, rolling Delta, Zeta segments and three stylometric plots.
Requirements
- Python 3.11 or newer.
- spaCy 3.8.15 or newer within 3.
- preshed 3.0.11 or newer, except 3.0.14 (new). The wheels of 3.0.14 break the tokenizer of spaCy (explosion/spaCy#14058).
- numpy 1.26, pandas 2.1, scipy 1.11, matplotlib 3.8 and graphviz 0.20.3 or newer. No trained spaCy model is needed.
- Rendering the word tree and the network of collocations also needs the executables of Graphviz.
pip install anytsruTS 0.18 and esTS 0.8 require anyTS 0.3 (anyts<0.4).
Incompatible changes
- Messages (74 → 90 keys).
hook_resultis removed, andcheck_messagesrefuses a dictionary that has it. The result of each hook has a key of its own instead:hook_doc,hook_lexical_words,hook_cohesion_words,hook_syllables,hook_sounds,hook_highlightsandhook_morph_words.- New keys:
source_span;connector_breaks,connector_breaks_short,connector_blocked,connector_blocked_emptyandconnector_type;morph_features,morph_markers,morph_stats_descandmorph_values_desc.
source_typenames the type, "The data source cannot be of type {type}". ASpangetssource_span, "The data source cannot be a Span: pass span.as_doc()".anyts.utils.source_type_errorgives either error for a class to raise.layer_annotationslists the annotations after a colon, and the defaultHighlightedText.annotation_namesare bare nouns ("parts of speech" instead of "the parts of speech").- The errors of
ConnectorMatcher.findandis_subordinatortake themessagesof the class.
- New keys of the statistics.
BASIC_STATS_DESCgets 2 keys,DIVERSITY_STATS_DESC2,COHESION_STATS_DESC6 andSYNTAX_STATS_DESC14.- A subclass with the
stats_descof the core gets them inget_stats,print_statsandto_dataframe, and the widths ofprint_statschange. - The units of L2SCA, the prepositional chains and the similarity of sentences, and the overlaps with the next two sentences and of the paragraphs, are computed on first use. A subclass without these keys costs nearly as before.
CohesionWordhas two more fields at the end,connector_blockedandparagraph_start. Unpacking it by position breaks.- Behaviour.
SyntaxStatsraisesSourceError(no_pos) for aDocwith a parse but without parts of speech, asCohesionStatsandMorphStatsdo.PhonStats.mean_syllable_lencounts the sounds of the classes of a syllable, by its CV pattern.- Quotes and the apostrophe are no longer marks between words in
find_marks,find_unit_marksandfind_connector_highlights. BLANK_LINEtakes every line break of Unicode:\r\n,\r, U+0085 and U+2028 besides\n, and U+2029 alone. The zero-width space and the byte order mark count as whitespace on a blank line. This bounds the sentences ofSentsExtractor,start_sents_after_blank_lines,kwicand the paragraphs. The pattern moves toanyts.utils, andanyts.extractorsstill exports it.positiveofkeynessmust be abool.- Equal scores of
keynessandcollocationsare ordered by frequency, the scores compared to 12 significant digits. - In
compare_features, every feature draws its bootstrap from a generator of its own. The intervals of a feature no longer depend on the other columns, and they change once, for the same seed. - Juilland's D of
dispersionandcalc_juilland_dis cut at 0. - A
SyntaxStatsorCohesionStatsof the core pickled by 0.3.9 loads, but itsget_stats,print_statsandto_dataframeraiseAttributeError: it lacks the new keys. Such objects need to be computed again. A subclass that names only the keys of 0.3.9 is not affected, nor are the other classes.
Features
-
Morphology:
MorphStatswith theanalyzehook andMorphWord. It counts the parts of speech and the features of Universal Dependencies, word by word or by value, and gives the markers of a language library,explain_textandprint_markers. The component isMorphStatsComponent. -
Unadapted readability:
UnadaptedReadabilityStatsand eleven formulas with their original coefficients:- FORCAST, and Linsear Write in the form of textstat;
- Powers-Sumner-Kearl and McAlpine EFLAW;
- the Wiener Sachtextformel in its four variants, and Dickes-Steiwer;
- Gulpease, Fucks, Strain, ELF and Wheeler-Smith.
The component is
UnadaptedReadabilityStatsComponent. -
Syntax: 14 keys:
- the words before the root;
- the T-units and phrases of L2SCA: T/S, MLT, C/T, CT/T, VP/T, CP/C and CN/C;
- the prepositional chains, with the
is_prep_complementhook; - the share of nominal subjects and objects before the verb;
- the similarity of adjacent sentences, by the edit distance of their parts of speech and by their dependency triples.
Also
calc_edit_distance,calc_multiset_similarityanddependency_triples. -
Cohesion: the overlaps of nouns, arguments and content words with the next two sentences and between paragraphs, in the manner of TAACO, by
calc_forward_overlap. Paragraphs start after a blank line, byCohesionWord.paragraph_start, and the class givesn_paragraphs. -
Diversity: Orlov's Z (
calc_orlov_z), burstiness (calc_burstiness, Kim and Jo 2016), andcalc_mamtld(step=), faster by the step.BasicStatsaddsletters_entropyandsyllables_entropy. -
Corpus:
keyness(n=)gives keywords by n-grams of a list of texts;collocations(side=)gives directed windows, and a node no longer slows it down;rolling_deltawithstatistics=, andzeta_segments;split_paragraphsinanyts.extractors: the numbers of words of its paragraphs give the sizes of the parts ofdispersion.
-
Plots:
rolling_delta_plot,zeta_scatter_plotanddelta_histogram_plot. -
Helpers:
source_type_error,find_paragraph_startsandfind_unit_paragraph_startsinanyts.utils;ConnectorMatcher.find(blocked=),CohesionWord.connector_blockedandfind_connector_highlights(blocked=): the positions where no connector starts, by a rule of a language that reads more than the words and their parts of speech, such as the parse.
For the libraries
-
New sections of the docs to include (50).
components.md:MorphStatsComponent,UnadaptedReadabilityStatsComponent.corpus/stylometry.md:rolling_delta,zeta_segments.extractors/sentences.md:split_paragraphs.stats/cohesion_stats.md:CohesionStats-forward_overlap,calc_forward_overlap.stats/diversity_stats.md:calc_orlov_z,calc_burstiness.stats/morph_stats.md:MorphStats,MorphStats-attributes,MorphStats-parameters,MorphStats-hooks,MorphStats-metrics,MorphStats-get_stats,MorphStats-print_stats,MorphStats-markers,MorphStats-explain_text,MorphWord.stats/syntax_stats.md:SyntaxStats-words_before_root,SyntaxStats-l2sca,SyntaxStats-prep_chains,SyntaxStats-word_order,SyntaxStats-similarity,is_prep_complement,calc_edit_distance,calc_multiset_similarity,dependency_triples.stats/unadapted_readability_stats.md:UnadaptedReadabilityStats,UnadaptedReadabilityStats-attributes,UnadaptedReadabilityStats-parameters,UnadaptedReadabilityStats-hooks,UnadaptedReadabilityStats-metrics, and the elevencalc_*of the formulas.utils/messages.md:source_type_error.utils/spacy.md:find_unit_paragraph_starts.utils/words.md:find_paragraph_starts.visualizers/stylometry.md:rolling_delta_plot,zeta_scatter_plot,delta_histogram_plot.
-
Anchors the tables of metrics link to. The sections
DiversityStats-metrics,CohesionStats-metricsandSyntaxStats-metricslink to the headings of new cards, which stand above their sections, outside them. Without these anchors,mkdocs build --strictfails. Above each of these sections, a library writes a heading with the anchor:#forward_overlapaboveCohesionStats-forward_overlap;#orlov_zabovecalc_orlov_z, and#burstinessabovecalc_burstiness;#words_before_root,#l2sca,#prep_chains,#word_orderand#similarityaboveSyntaxStats-words_before_root,-l2sca,-prep_chains,-word_orderand-similarity.
In the same way,
UnadaptedReadabilityStats-metricslinks to the cards of its eleven formulas: each anchor is the name of thecalc_*section below it withoutcalc_(#forcastabovecalc_forcast). -
Paragraphs. An
analyzeofCohesionStatsthat builds its own words setsparagraph_startbyfind_paragraph_startsorfind_unit_paragraph_starts. Without it, the keys*_paraarenan. -
Corpus.
keynessof several texts takes the list of texts, not their words joined. A mapping of the frequencies of n-grams goes withn=1.
Quality
-
Tests: 2,390 tests with 100% line and branch coverage. Two tests of the docs check every parameter table against its signature and run the examples of 39 pages against their results.
-
CI: Python 3.11-3.14 on Linux, Windows and macOS, a job on the lowest versions of the dependencies, and a job for the examples of the docs.
-
Numbers of the libraries: through the classes of esTS 0.8 and ruTS 0.18, the keys of 0.3.9 give the same numbers bitwise. The exception is
mean_syllable_lenof ruTS, 2.369 → 2.333 on average over its texts. The snapshots of the libraries, 4,620 and 4,822 results, change only by the changes named above. -
QA: a quality check before the release covered:
- syntax, cohesion and morphology;
- diversity, the basic statistics and readability;
- the corpus, stylometry and the plots;
- the move of the libraries;
- the docs, the public API, the packaging and the speed.
Links
- Documentation: https://sergeyshk.github.io/anyTS/
- PyPI: https://pypi.org/project/anyts/