Skip to content

Command line

The command ests counts the statistics of texts without Python code: it prints them as a table, JSON or CSV, for the whole text or its parts, writes an HTML report and downloads the frequency dictionary. It is installed with the library; python -m ests is the same.

ests download
ests stats texto.txt
ests stats -f json capitulo1.txt capitulo2.txt
ests stats -s basic,readability -p sentences -f csv -o oraciones.csv texto.txt
cat texto.txt | ests stats -f json
ests report texto.txt -t "Mi texto" -o informe.html

Command

Command()

The command line of the statistics of a language library. Its command stats reads texts from files, or from the standard input without them or for -, parses every text once (parse) and prints the statistics of the classes of stats_classes:

Option Default Description
files the standard input Text files
-s, --stats the classes of default_stats Classes of statistics, by name and separated by commas; with -p, those of default_stats that count such parts by default
-p, --parts - sentences, lines or paragraphs: a row per part (by_parts); a class of -s that counts no such parts is an error
-f, --format table table - the table of print_stats of every class, or of the parts; json - the flat statistics of every class by text, get_stats(flat=True), or the records of the parts, with nan and infinities as null; csv - a row per text, or per part of a text, with a column <class>.<statistic> for every statistic and 0 for a count of a distribution a text lacks (stats_dataframe)
-o, --output the standard output File of the output, written only by a result: without one an existing file keeps its text and a new one is not left; the standard output for -. A table, written as every text is counted, refuses one of its texts after the first
-e, --encoding utf-8-sig Encoding of the files: UTF-8, a byte order mark left out, by default; the output is in UTF-8

The standard input is read as a file, its line breaks and its byte order mark alike, and a table is printed as every text is counted.

Its command download, of a library with datasets, downloads the datasets its classes need, those named or every one, again with --force, and names each on the standard output.

Its command report writes the HTML report of a text, from a file or from the standard input, to -o or to the standard output, with the classes of -s and the title of -t, --title; its statistics, those of its table of sentences too, are counted as by stats, and a class that cannot count the text is left out of it.

run(argv=None) runs the command with the arguments, those of the command line by default, and returns the exit code: 0; 1 when a file cannot be read or written, a class cannot count a text or a dataset cannot be downloaded, whose error goes to the standard error while the others are counted, and when the reader of the output stops, as head, without a message; 2 for wrong arguments, an unknown encoding among them, with the help of argparse, and without a command, with the help of the command; 130 when interrupted. -V, --version prints the versions of the library and of the core.

Raises ParameterError when a subclass is defined with texts that check_messages rejects against CLI_TEXTS, or with default_stats that names a class not in stats_classes.

In esTS anySeg splits the text and esMorph analyzes it in the context of its sentences once for all the classes; with syntax or cohesion among them esSyntax parses it too (parse_document), the longest step of the count, which -s without both leaves out. The classes of -s are:

Name Class
basic BasicStats
readability ReadabilityStats
unadapted_readability UnadaptedReadabilityStats
diversity DiversityStats
morph MorphStats
lexical LexicalStats
style StyleStats
phon PhonStats
cohesion CohesionStats
syntax SyntaxStats
verse VerseStats, only by its name in -s

The command parses a text as SyntaxStats(text) and CohesionStats(text) do in Python, so its statistics are theirs. ests download downloads the frequency dictionary freq_dict for lexical; without it the class is not counted, and its error names this command.

Report

Report(source, title=None, stats_classes=None, *, skip_errors=False)

The HTML report of the statistics of a text. The text is parsed once (parse), every class counts it and its sentences by compute, and its sections follow sections, each a method section_<name> that gives a fragment of HTML:

Section Content
statistics A table per class of stats_classes under its title (titles): the description of every statistic of stats_desc, as print_stats, its value - a float with two decimals, a smaller one than 0.1 with two significant digits, a distribution as its pairs from the most frequent, with the values described by value_desc, an undefined value as the text undefined - and its reading (describe); the classes left out by skip_errors are named above
sentences The text of every sentence with words, numbered as on the plot of their lengths, with the statistics of sentence_columns (by_parts); none without them. A text of more than max_sentences such sentences has those with the highest values of the first statistic, in their order
highlight The text highlighted by highlight_class with its default layers, its styles in the head of the page; none without it
plots The plots of plots in SVG with their captions: the lengths of the sentences (sentence_lengths_plot) by default, without a mark on every sentence for a text of more than 300 of them; none for a text without sentences

The page is the same for the same text, and no text of the source or of the statistics becomes markup.

Parameter Type Default Description
source str / Document - Data source
title str None Title of the report; the text title by default
stats_classes dict[str, type[Stats]] None Classes of statistics by name; those of the class by default
skip_errors bool False Leave out a class that cannot count the source, with its error in errors, instead of raising it

The object keeps its classes by name, classes, document, title, the statistics of every class by name, stats, and the errors of the classes left out, errors. to_html() returns the page, and save(path) writes it to a file in UTF-8, the encoding the page declares. A source a class cannot count raises the error of the class, unless skip_errors; a skip_errors that is not a bool and stats_classes that are not a dictionary of classes of statistics raise ParameterError.

In esTS Report is in ests.report: its classes are STATS_CLASSES of the same module, the classes of the command but verse; a string is analyzed as by the command; the columns of the sentences are the characters, the words, the syllables, the Flesch reading ease and the water; the highlighting is HighlightedText with its default layers. The texts of the report are in English, as those of print_stats, and the readings keep the names of the bands of their scales (bastante fácil).

from ests.report import Report

report = Report(
    "El gato duerme en la ventana. El perro ladra en el patio.",
    title="Dos oraciones",
    skip_errors=True,
)
report.save("informe.html")
report.stats["basic"].n_words, len(report.document.sentences)
(12, 2)