From 2b7e96835e75e0d153e7f993d1c4fc2add452ddd Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 8 Feb 2026 22:47:02 -0500 Subject: Added Text.distance(a,b) for text similarity comparisons. --- man/man3/tomo-Text.3 | 12 ++++++++++-- man/man3/tomo-Text.distance.3 | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 man/man3/tomo-Text.distance.3 (limited to 'man/man3') diff --git a/man/man3/tomo-Text.3 b/man/man3/tomo-Text.3 index 634e3e0a..10032155 100644 --- a/man/man3/tomo-Text.3 +++ b/man/man3/tomo-Text.3 @@ -1,8 +1,8 @@ '\" t -.\" Copyright (c) 2025 Bruce Hill +.\" Copyright (c) 2026 Bruce Hill .\" All rights reserved. .\" -.TH Text 3 2025-11-29 "Tomo man-pages" +.TH Text 3 2026-02-08 "Tomo man-pages" .SH NAME Text \- a Tomo type .SH LIBRARY @@ -66,6 +66,14 @@ For more, see: .BR Tomo-Text.codepoint_names (3) +.TP +.BI Text.distance\ :\ func(a:\ Text,\ b:\ Text,\ language:\ Text\ =\ "C"\ ->\ Num) +Get an approximate distance between two texts, such that when the distance is small, the texts are similar and when the distance is large, the texts are dissimilar. + +For more, see: +.BR Tomo-Text.distance (3) + + .TP .BI Text.ends_with\ :\ func(text:\ Text,\ suffix:\ Text,\ remainder:\ &Text?\ =\ none\ ->\ Bool) Checks if the \fBText\fR ends with a literal suffix text. diff --git a/man/man3/tomo-Text.distance.3 b/man/man3/tomo-Text.distance.3 new file mode 100644 index 00000000..fe516e48 --- /dev/null +++ b/man/man3/tomo-Text.distance.3 @@ -0,0 +1,43 @@ +'\" t +.\" Copyright (c) 2026 Bruce Hill +.\" All rights reserved. +.\" +.TH Text.distance 3 2026-02-08 "Tomo man-pages" +.SH NAME +Text.distance \- distance between two texts +.SH LIBRARY +Tomo Standard Library +.SH SYNOPSIS +.nf +.BI Text.distance\ :\ func(a:\ Text,\ b:\ Text,\ language:\ Text\ =\ "C"\ ->\ Num) +.fi +.SH DESCRIPTION +Get an approximate distance between two texts, such that when the distance is small, the texts are similar and when the distance is large, the texts are dissimilar. + + +.SH ARGUMENTS + +.TS +allbox; +lb lb lbx lb +l l l l. +Name Type Description Default +a Text The first text to compare. - +b Text The second text to compare. - +language Text The ISO 639 language code for which character width to use. "C" +.TE +.SH RETURN +The distance between the two texts (larger means more dissimilar). + +.SH NOTES +The exact distance algorithm is not specified and may be subject to change over time. + +.SH EXAMPLES +.EX +assert "hello".distance("hello") == 0 +texts := &["goodbye", "hello", "hallo"] +texts.sort(func(a,b:&Text) a.distance("hello") <> b.distance("hello")) +assert texts == ["hello", "hallo", "goodbye"] +.EE +.SH SEE ALSO +.BR Tomo-Text (3) -- cgit v1.2.3