Skip to content

Corpus comparison

compare_texts(a=[], b=[], a_paths=[], b_paths=[], window=null, whole_texts=false, top_n=15)

Comparison of two corpora by style features - for authorship attribution, comparing genres and translations, human and model texts. The texts are cut into windows of window words, 210 features of esTS are computed for every window, and the distributions of every feature in the corpora A and B are compared. Syntactic parsing takes most of the time: two corpora of 250 thousand characters each are compared in about 6 seconds, of 500 thousand each in about 12. With whole_texts whole texts are compared, without windows. The features and comparison statistics are on the esTS page Corpus comparison.

A text is cut in a row into windows of exactly window words; a remainder shorter than a window and a text shorter than a window are left out of the comparison. The response warns about such texts and about a loss of more than 10% of the words of a corpus, and a smaller window loses less text. When whole texts are compared, the response warns if the mean text length differs noticeably between the corpora: features that depend on the text length differ because of it as well.

Each corpus needs at least two windows. Several texts per corpus are more reliable: the windows of one text are not independent, and with few texts p_holm is understated.

Errors - those common to the tools and:

  • a corpus is empty or its texts have no words;
  • a corpus has fewer than two windows;
  • a corpus is longer than the ESTS_MCP_MAX_TEXT_LENGTH limit: the limit applies to the sum of the lengths of its texts.

The opening and the portrait of the hero in Don Quijote (A) and in Galdós's Marianela (B):

{
  "name": "compare_texts",
  "arguments": {
    "a": [
      "En un lugar de la Mancha, de cuyo nombre no quiero acordarme, no ha mucho tiempo que vivía un hidalgo de los de lanza en astillero, adarga antigua, rocín flaco y galgo corredor.",
      "Frisaba la edad de nuestro hidalgo con los cincuenta años; era de complexión recia, seco de carnes, enjuto de rostro, gran madrugador y amigo de la caza."
    ],
    "b": [
      "Se puso el sol. Tras el breve crepúsculo vino tranquila y oscura la noche, en cuyo negro seno murieron poco a poco los últimos rumores de la tierra soñolienta, y el viajero siguió adelante en su camino, apresurando su paso a medida que avanzaba la noche.",
      "Era un hombre de mediana edad, de complexión recia, buena talla, ancho de espaldas, resuelto de ademanes, firme de andadura, basto de facciones, de mirar osado y vivo, ligero a pesar de su regular obesidad, y (dígase de una vez aunque sea prematuro) excelente persona por doquiera que se le mirara."
    ],
    "whole_texts": true,
    "top_n": 3
  }
}
{
  "window": null,
  "n_windows": {"a": 2, "b": 2},
  "n_texts": {"a": 2, "b": 2},
  "features": [
    {
      "feature": "morph_person_1",
      "mean_a": 0.4167,
      "mean_b": 0.0,
      "median_diff": 0.4167,
      "ci_low": 0.3333,
      "ci_high": 0.5,
      "cliff_delta": 1.0,
      "p_holm": 1.0
    },
    {
      "feature": "morph_p_proclitics",
      "mean_a": 0.0,
      "mean_b": 0.1667,
      "median_diff": -0.1667,
      "ci_low": -0.1667,
      "ci_high": -0.1667,
      "cliff_delta": -1.0,
      "p_holm": 1.0
    },
    {
      "feature": "syntax_p_passive",
      "mean_a": 0.0,
      "mean_b": 0.2083,
      "median_diff": -0.2083,
      "ci_low": -0.25,
      "ci_high": -0.1667,
      "cliff_delta": -1.0,
      "p_holm": 1.0
    }
  ],
  "warnings": [
    "The mean length of a text is 30 words in A and 48 in B: the features that depend on the length of a text (lexical diversity, shares and frequencies of words) differ because of it too; to compare passages of one length, compare by windows (whole_texts=false)",
    "No difference is significant after Holm's correction (p_holm < 0.05): windows in A: 2, in B: 2. It needs more texts; Cliff's delta on so few windows is a rough estimate",
    "Beyond top_n there are 26 more features with the same absolute Cliff's delta 1.0: with equal delta the features are ordered by the relative difference of the medians; top_n gives more features"
  ]
}

Parameters

Parameter Type Default Description
a array[string] [] Texts of the first corpus, up to 1000
b array[string] [] Texts of the second corpus, up to 1000
a_paths array[string] [] Absolute paths to files with texts of the first corpus or links ests://datasets/..., up to 1000, together with a or instead of it; a query link gives all its texts as separate texts of the corpus
b_paths array[string] [] Absolute paths to files with texts of the second corpus or links ests://datasets/..., up to 1000, together with b or instead of it
window integer null Window size in words, from 100 to 10,000; not given - at most 1000 and such that the shortest text splits into at least two windows
whole_texts boolean false Compare whole texts, without windows; at least two texts per corpus are needed
top_n integer 15 Number of features with the largest difference, up to 200

Features

Prefix Features
basic_ Shares of long, complex, simple, mono- and polysyllabic words, of letters, spaces and marks, letters and syllables per word
readability_ Readability formulas and the consensus grade
diversity_ Lexical diversity measures
morph_ Shares of parts of speech and of the features of one value among all words (morph_pos_NOUN, morph_polarity_Neg) and of the values of the other features among the words that carry them (morph_mood_Sub, morph_tense_Imp); shares of the infinitive, gerund, participle, clitics, ser, adverbs in -mente and diminutives (morph_p_enclitics)
sents_ Mean sentence length in words, its standard deviation, coefficient of variation and autocorrelation of adjacent lengths
punct_ Marks by type per 1000 words and the share of the opening ¿ and ¡ among question and exclamation marks (punct_inverted_share)
cohesion_ Cohesion statistics: overlaps between sentences, pronouns, givenness, repetition of tense and mood, connectors per 1000 words
syntax_ Statistics of the syntax group: dependency length, tree shape, clauses and the L2SCA indices, chains, participial and gerund clauses, the passive and se, word order, the similarity of adjacent sentences

Result

Field Type Description
window integer Window size; null - whole texts
n_windows object Number of windows in A and B
n_texts object Number of texts in A and B
features array[object] Features by descending absolute Cliff's delta, with equal deltas by the relative difference of medians, with the fields below
warnings array[string] A corpus is not in Spanish, the texts of the corpora differ in length, texts or their remainders are left out of the comparison, a corpus has one text, no difference is significant, features with the same Cliff's delta as the last one shown are beyond top_n
Feature field Description
feature Name of the feature
mean_a, mean_b Means over the windows of A and B
median_diff Difference of medians A - B
ci_low, ci_high 95% bootstrap interval of the difference of medians; the bootstrap resamples whole texts, and with one text in a corpus the interval is null
cliff_delta Cliff's delta from -1 to 1: the share of window pairs where A is greater minus the share where it is smaller; in absolute value from 0.147 - small, from 0.33 - medium, from 0.474 - large effect
p_holm p-value of the Mann-Whitney U test with the Holm correction for the number of features