Find where text reads two ways
Find the points where the text behind and the text ahead read differently: where one kind of text gives way to another, placed at the change rather than a window after it (observation).
$ cat export.txt
id,host,bytes
1,alpha,1024
2,beta,2048
3,gamma,4096
The export finished without errors and wrote three rows.
Where the two sides differ most
Each byte has three readings of the byte classes around it: from behind, from ahead and from both sides. A contested point is where behind and ahead differ most, and the peak is the contested point where they differ more than anywhere else:
$ trex observe export.txt --contested
trex observe: 109 bytes, 6 contested point(s)
peak observer-dependence: 0.54 at byte 55
contested points (6):
@ 20 ...tes 1,alpha,1024 2,beta,...
@ 40 ...eta,2048 3,gamma,4096 Th...
@ 55 ...a,4096 The export finish...
@ 63 ...he export finished witho...
@ 71 ...t finished without error...
@ 89 ... errors and wrote three ...
The disagreement rises at byte 51, the newline that ends the last row, and holds near its height
across the first word of the prose, peaking at byte 55, the space after The: the reading from
behind still sees a table there, and the reading from ahead already sees words. Of two contested
points closer together than eight bytes, the stronger is the one kept, so the point reported in
that stretch is its peak. A reading of the past alone places a change a window late, and over an
input this short spectral, which reads that way, finds no
change point at all. The smaller contested points are local disagreements inside each kind of
text.
Match at the point
@ambiguous anchors a pattern at a contested point. At the token grain it reads the sequence of
token kinds, so it holds where the kinds behind and ahead differ most, on the table’s last token:
$ trex scan '@ambiguous:token .' export.txt
[47..51] "4096"
@ambiguous:byte reads the bytes and @ambiguous:super the sequence of supertoken roles; a bare
@ambiguous reads the bytes.