Data update

This commit is contained in:
Ingy döt Net 2026-02-01 16:33:20 -08:00
parent 5150844a7d
commit 4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions

View file

@ -1,91 +0,0 @@
with Ada.Text_IO;
procedure Jaro_Distances is
type Jaro_Measure is new Float;
function Jaro_Distance (Left, Right : in String) return Jaro_Measure
is
Left_Matches : array (Left'Range) of Boolean := (others => False);
Right_Matches : array (Right'Range) of Boolean := (others => False);
Matches : Natural := 0;
Transpositions : Natural := 0;
begin
if Left'Length = 0 and Right'Length = 0 then
return 1.000;
end if;
declare
Match_Distance : constant Natural := Natural'Max (Left'Length, Right'Length) / 2 - 1;
begin
for L in Left'Range loop
declare
First : constant Natural := Natural'Max (Right'First, Right'First + L - Left'First - Match_Distance);
Last : constant Natural := Natural'Min (L - Left'First + Match_Distance + Right'First, Right'Last);
begin
for R in First .. Last loop
if
not Right_Matches (R) and
Left (L) = Right (R)
then
Left_Matches (L) := True;
Right_Matches (R) := True;
Matches := Matches + 1;
exit;
end if;
end loop;
end;
end loop;
end;
if Matches = 0 then
return 0.000;
end if;
declare
R : Natural := Right'First;
begin
for L in Left'Range loop
if Left_Matches (L) then
while not Right_Matches (R) loop
R := R + 1;
end loop;
if Left (L) /= Right (R) then
Transpositions := Transpositions + 1;
end if;
R := R + 1;
end if;
end loop;
end;
declare
Match : constant Float := Float (Matches);
Term_1 : constant Float := Match / Float (Left'Length);
Term_2 : constant Float := Match / Float (Right'Length);
Term_3 : constant Float := (Match - Float (Transpositions) / 2.0) / Match;
begin
return Jaro_Measure ((Term_1 + Term_2 + Term_3) / 3.0);
end;
end Jaro_Distance;
procedure Show_Jaro (Left, Right : in String)
is
package Jaro_IO is
new Ada.Text_IO.Float_IO (Jaro_Measure);
use Ada.Text_IO;
Distance : constant Jaro_Measure := Jaro_Distance (Left, Right);
begin
Jaro_IO.Put (Distance, Fore => 1, Aft => 5, Exp => 0);
Set_Col (10); Put (Left);
Set_Col (22); Put (Right);
New_Line;
end Show_Jaro;
S1 : constant String := " MARTHA VS MARHTA ";
begin
Show_Jaro ("DWAYNE", "DUANE");
Show_Jaro ("DIXON", "DICKSONX");
Show_Jaro ("JELLYFISH", "SMELLYFISH");
Show_Jaro (S1 (3 .. 8), S1 (13 .. 18));
end Jaro_Distances;

View file

@ -1,98 +0,0 @@
identification division.
program-id. JaroDistance.
environment division.
configuration section.
repository.
function length intrinsic
function trim intrinsic
function max intrinsic
function min intrinsic
.
data division.
working-storage section.
77 s pic x(255).
77 t pic x(255).
77 s-length pic 9(3).
77 t-length pic 9(3).
77 i pic 9(3).
77 j pic 9(3).
77 k pic 9(3).
77 start-pos pic 9(3).
77 end-pos pic 9(3).
77 match-distance pic 9(3).
77 matches pic 9(3).
77 transpositions pic 9(3).
77 distance pic 9v9(8).
01 jaro-table.
05 filler occurs 255.
10 filler pic 9(1).
88 s-matches value 1 when set to false is 0.
10 filler pic 9(1).
88 t-matches value 1 when set to false is 0.
procedure division.
main.
move "MARTHA" to s
move "MARHTA" to t
perform jaro-calc-and-show
move "DIXON" to s
move "DICKSONX" to t
perform jaro-calc-and-show
move "JELLYFISH" to s
move "SMELLYFISH" to t
perform jaro-calc-and-show
stop run
.
jaro-calc-and-show.
perform jaro-distance
display trim(s) " -> " trim(t) ", distance=" distance
.
jaro-distance.
move length(trim(s)) to s-length
move length(trim(t)) to t-length
if s-length = zeros and t-length = zeros
move 1 to distance
exit paragraph
end-if
compute match-distance = max(s-length, t-length) / 2 - 1
move low-values to jaro-table
move zeros to matches
move zeros to transpositions
perform varying i from 1 by 1 until i > s-length
move max(1, i - match-distance) to start-pos
move min(i + match-distance, t-length) to end-pos
perform varying j from start-pos by 1 until j > end-pos
if t-matches(j) or s(i:1) <> t(j:1)
exit perform cycle
end-if,
set s-matches(i), t-matches(j) to true
add 1 to matches
exit perform
end-perform
end-perform
if matches = zeros
move matches to distance
exit paragraph
end-if
move 1 to k
perform varying i from 1 by 1 until i > s-length
if not s-matches(i)
exit perform cycle
end-if
perform until t-matches(k)
add 1 to k
end-perform
if s(i:1) <> t(k:1)
add 1 to transpositions
end-if
add 1 to k
end-perform
compute distance = ((matches / s-length) + (matches / t-length) +
((matches - transpositions / 2) / matches)) / 3
.

View file

@ -1,55 +0,0 @@
(let ()
(defun jaro (s1 s2)
(let (mw mflags1 mflags2 fn-reset-mflags fn-reset-all-mflags fn-cnt-trans)
(setq mflags1 (make-vector (length s1) nil))
(setq mflags2 (make-vector (length s2) nil))
(setq mw (1- (/ (max (length s1) (length s2)) 2)))
(setq fn-reset-mflags
(lambda (idx)
(let ((start (max 0 (- idx mw)))
(end (min (1- (length s2)) (+ idx mw))))
(cl-loop for i from start to end do
(when (and (not (elt mflags1 idx))
(not (elt mflags2 i)))
(when (equal (elt s1 idx) (elt s2 i))
(aset mflags1 idx 't)
(aset mflags2 i 't) ) ) ) ) ) )
(setq fn-reset-all-mflags
(lambda ()
(dotimes (idx (length s1))
(funcall fn-reset-mflags idx) ) ) )
(setq fn-cnt-trans
(lambda ()
(let ((cur2 0) (transposition 0))
(dotimes (cur1 (length s1))
(when (aref mflags1 cur1)
(while (not (aref mflags2 cur2))
(setq cur2 (1+ cur2)) )
(when (not (equal (aref s1 cur1)
(aref s2 cur2)))
(setq transposition (1+ transposition)) )
(setq cur2 (1+ cur2))
)
)
transposition ) ) )
(funcall fn-reset-all-mflags)
(let ((m (seq-count (lambda (f) f) mflags1))
(tr (funcall fn-cnt-trans)))
;;(message "matches: %s, transposition: %s, |s1|: %d |s2|: %d" m tr (length s1) (length s2))
(if (= m 0)
0
(progn (/ (+ (/ (float m) (length s1)) (/ (float m) (length s2)) (/ (float (- m (/ (float tr) 2))) m) ) 3))
) ) ) )
(let ((params '(("MARTHA" "MARHTA")
("DIXON" "DICKSONX")
("JELLYFISH" "SMELLYFISH"))))
(dolist (p params)
(message "jaro(%s, %s) = %f"
(nth 0 p) (nth 1 p)
(jaro (nth 0 p) (nth 1 p)))
)
)
)

View file

@ -1,39 +0,0 @@
class Jaro {
private static function jaro(s1: String, s2: String): Float {
var s1_len = s1.length;
var s2_len = s2.length;
if (s1_len == 0 && s2_len == 0) return 1;
var match_distance = Std.int(Math.max(s1_len, s2_len)) / 2 - 1;
var matches = { s1: [for(n in 0...s1_len) false], s2: [for(n in 0...s2_len) false] };
var m = 0;
for (i in 0...s1_len) {
var start = Std.int(Math.max(0, i - match_distance));
var end = Std.int(Math.min(i + match_distance + 1, s2_len));
for (j in start...end)
if (!matches.s2[j] && s1.charAt(i) == s2.charAt(j)) {
matches.s1[i] = true;
matches.s2[j] = true;
m++;
break;
}
}
if (m == 0) return 0;
var k = 0;
var t = 0.;
for (i in 0...s1_len)
if (matches.s1[i]) {
while (!matches.s2[k]) k++;
if (s1.charAt(i) != s2.charAt(k++)) t += 0.5;
}
return (m / s1_len + m / s2_len + (m - t) / m) / 3.0;
}
public static function main() {
Sys.println(jaro( "MARTHA", "MARHTA"));
Sys.println(jaro( "DIXON", "DICKSONX"));
Sys.println(jaro("JELLYFISH", "SMELLYFISH"));
}
}