The echo axis
The echo axis checks whether each token’s content occurs elsewhere in the input: how many times, how far back it last appeared, and whether its occurrences come at a regular spacing. A token whose content appears once is novel; one whose content recurs is an echo. Punctuation and brackets recur by grammar rather than by content, so the axis leaves them unkeyed.
Source: src/echo.rs.
What it reads that nothing else does
ERROR disk full; WARN slow disk; error disk full; ERROR net down; warn slow netEvery word here is short and lowercase or uppercase, so magnitude and shape read them alike.
Echo reads their content: disk occurs three times at a near-regular spacing, ERROR, full,
slow and net twice, and WARN, down and the rest once. With case folded, ERROR and
error are one piece of content occurring three times. The same reading finds a repeated
message in a log, a name a file reuses, or a value that should have been unique.
Every example on this page reads that line.
The readings
| Reading | Meaning |
|---|---|
| count | how many times the token’s content occurs in the input |
| back-lag | the bytes back to its previous occurrence |
| novel | the token is the first occurrence of its content |
| period | the mean spacing of a content’s occurrences, where the spacings vary by at most max_period_cv of their mean, 0.3 by default |
| novelty | the share of keyed tokens that are novel |
| echo rate | the share of keyed tokens whose content occurs more than once |
The key is the token’s text, read exactly by default, which is the identity group. Another
group reads it up to a symmetry or a representation: case folds case, shape reads its pattern
of letters and digits, e8 its profile of character kinds, numeric its value, and ip, url,
time, path, fold and notation fold the different ways of writing an address, a URL, a
time, a path, accented or wide text and a symbol. A typed relation keys a token by the part of it
the relation reads, so under subnet/24 every address of a network is one key. The
orbit page shows what each group folds.
Reading the axis
The summary counts the tokens, the keyed ones and the distinct contents, gives the novelty and the echo rate, and lists the strongest echoes:
$ trex echo --text 'ERROR disk full; WARN slow disk; error disk full; ERROR net down; warn slow net'
trex echo: 79 bytes, 33 tokens (15 keyed, 9 distinct), novelty 60.0%, echo rate 73.3%
strongest echoes (top 5 of 5; first occurrence, count, period):
disk x3 period ~16 B
ERROR x2
full x2
slow x2
net x2
--top K sizes the ranked lists, eight by default; the reports carry every echo.
Every token’s reading
--field lists each keyed token’s count, its back-lag and whether it is novel, and --limit N
stops the list after N tokens and counts the rest. -Detail in PowerShell and detail=True in
Python add a frame at every token:
$ trex echo --field --limit 4 --text 'ERROR disk full; WARN slow disk; error disk full; ERROR net down; warn slow net'
trex echo: 79 bytes, 33 tokens (15 keyed, 9 distinct), novelty 60.0%, echo rate 73.3%
strongest echoes (top 5 of 5; first occurrence, count, period):
disk x3 period ~16 B
ERROR x2
full x2
slow x2
net x2
per-token (token -> count | back-lag | novel):
ERROR x2 back= - novel
disk x3 back= - novel
full x2 back= - novel
WARN x1 back= - novel
... (+11 more tokens; raise --limit)
Reading up to a group
--group case keys each token with its case folded, so ERROR and error, and WARN and
warn, are each one content. The distinct count falls and the echo rate rises:
$ trex echo --group case --top 3 --text 'ERROR disk full; WARN slow disk; error disk full; ERROR net down; warn slow net'
trex echo: 79 bytes, 33 tokens (15 keyed, 7 distinct), novelty 46.7%, echo rate 93.3%
strongest echoes (top 3 of 6; first occurrence, count, period):
ERROR x3
disk x3 period ~16 B
full x2
Structural rhyme
--structure keys each supertoken by its role and its
token-kind silhouette, so two units that differ only in their names and values are one structure.
Six distinct words, every one novel, and one recurring structure:
$ trex echo --structure --text 'alpha: one
bravo: two
delta: six'
trex echo: 32 bytes, 14 tokens (6 keyed, 6 distinct), novelty 100.0%, echo rate 0.0%
structural rhyme (top 1 of 1 recurring supertoken structures):
kv:W:W x3 period ~11 B
Choosing a threshold
The period. A content is periodic when its spacings are steady enough: their standard
deviation at most max_period_cv of their mean. disk recurs after 21 bytes and then after 12,
a mean of 16.5 with a deviation of 4.5, which is 0.27 of the mean, inside the default 0.3. Lower
the cut to demand a steadier rhythm, raise it to admit a looser one; at 0 only exactly regular
spacings count, and disk loses its period:
$ trex echo --max-period-cv 0 --top 1 --text 'ERROR disk full; WARN slow disk; error disk full; ERROR net down; warn slow net'
trex echo: 79 bytes, 33 tokens (15 keyed, 9 distinct), novelty 60.0%, echo rate 73.3%
strongest echoes (top 1 of 5; first occurrence, count, period):
disk x3
The comparison is inclusive: spacings that vary by exactly the cut are periodic.
A count. @echo>k takes the contents that occur more than k times, so read the counts the
summary lists and put k below the count of the repetition you are after: here @echo>2 keeps
disk alone, and under (?orbit:case ...) ERROR and error join it.
Declarations
A declared shape or kind changes what a token is, and so changes the content echo keys: a message
declared as one token recurs as a whole rather than word by word. Every axis that reads tokens
takes the declarations a scan takes: --lib, --shape, --shape-after, --kind, --let and
--declare on the command line, -Library in PowerShell and lib= in Python
(pattern files); the magnitude page shows
one at work.
In a pattern
@novel holds on the first occurrence of a token’s content and @echoed on content that recurs
elsewhere, before or after. @echo>k, @echo=k and @echo<k read the count; @echo:nth=k tests
which occurrence this one is, counting from one, and nth=-1 counts back from the last;
@echo:period holds on a periodic content. A scope (?orbit:G ...) around an anchor counts up
to that group, and @echoed:@other.log reads a second input. The
pattern syntax page has every form.
$ trex scan '@echo>2 \W' --text 'ERROR disk full; WARN slow disk; error disk full; ERROR net down; warn slow net'
[6..10] "disk"
[27..31] "disk"
[39..43] "disk"
$ trex scan '(?orbit:case @echo>2 \W)' --text 'ERROR disk full; WARN slow disk; error disk full; ERROR net down; warn slow net'
[0..5] "ERROR"
[6..10] "disk"
[27..31] "disk"
[33..38] "error"
[39..43] "disk"
[50..55] "ERROR"
$ trex scan '@echo:nth=2 \W' --text 'ERROR disk full; WARN slow disk; error disk full; ERROR net down; warn slow net'
[27..31] "disk"
[44..48] "full"
[50..55] "ERROR"
[71..75] "slow"
[76..79] "net"
Data model
EchoFrame, one token’s reading: its span start..end, whether it is keyed, its content’s
count, back_lag and fwd_lag (the bytes to the previous and the next occurrence, none at
either end), nth (which occurrence it is) and period (the content’s mean spacing where it is
periodic, 0 otherwise). EchoField holds a frame at every token with keyed, distinct,
novel and echoed counts, and novelty() and echo_rate(); EchoConfig holds orbit (the
group, Identity by default), min_len (1) and max_period_cv (0.3). analyze_with(tokens, bytes, &cfg) reads under it, and
analyze_super_with(bytes, &cfg) returns the recurring supertoken structures.
Algorithm
One pass keys each token’s content, under the group’s canonical form where one is named, in a
map from key to its occurrences; a second pass reads each token’s count, back-lag and novelty
from the map. A content’s period is the mean of its successive spacings where their coefficient
of variation is at most max_period_cv.