#! /usr/bin/python3
import sys, re
import html_gen as h
from process_funcs import bash
import html_report_funcs as hr
last_edit = "Last edited on 2026-06-03 20:19:13 by stolfi"
def main():
global last_edit
title = "Page ???"
st = h.new_doc(title, "#eeffdd")
h.section(st, 3, "Definition of {k}-repeat")
h.parags(st, """Let {tks[0..nt-1]} be the sequence of all tokens of
either text. For the SBJ, each token {tks[i]} is a pinyin syllable, in
Unicode, initially with tones marked by diacritics. Recipe boundaries
are ignored for simplicity. For the SBJ, each token is a sequence of
lowercase EVA letters ([a-z] or '?') originally delimited by EVA
spaces [.,-] of line breaks, ignorng line, parag, and page boundaries.
For any positive {k}, we say that the text has a {k}-repeat at positions {i0} and
{i1}if the following conditions hold:
(0) {0 <= i0 < i1 < nt};
(1) {tks[i0+r]} and {tks[i1+r]} are similar for all {r} in {0..k-1}.
(2) {tks[i0-1]} and {tks[i1-1]} are not similar (or {i0 == 0});
(3) {tks[i0+k]} and {tks[i1+k]} are not similar (or {i1+k == nt}); and
(4) There exist no {k} repeat {i0,im} with {i0 < im < i1}.
Conditions (2) and (3) exclude {k}-repeats {i0,i1} where both token strings are
substrings of the strings of a {k'} repeat with {k'>k}. It is OK is that happens to only one
of the strings.
Condition (4) means that a sequence of words that occurs 6
times counts as 5 repeats (not 15).
For example, in the text
"x y B C D z A B C D E w r A B C D E s t B C D E u v B C D t"
0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9
there is
a 5-repeat "A B C D E" at 06 and 13
a 4-repeat "B C D E" at 14 and 20
a 3-repeat "B C D" at 02 and 07
a 3-repeat "B C D" at 14 and 26
However there is not a 3-repeat "A B C" at 06 and 13, nor a
4-repeat "B C D E" at 07 and 14, nor a 3-repeat "B C D" at 02 and 20.
If there is a {k}-repeat at {i0} and {i1}, the pairs of words mentioned
in conditions (2) and (3) are its stop pairs -- the tokens that
prevented the repeat from being extended further. In the above example,
the stop pairs of the 3-repeat at 06 and 07 are ("y", "A") and ("z", "E").
""")
h.section(st, 2, "Summary")
h.parags(st, """Page ???""")
h.section(st, 2, "All clips")
h.parags(st, """???""")
hr.links_section(st)
h.output_doc(st, sys.stdout, 99, last_edit)
return 0
# ----------------------------------------------------------------------
main()