soundex.pl

loading
details
attribute value
description
owner Johannes Waldmann
uploaded 2017-08-17 03:45:17.0
disk size 1.12 KB
downloadable true
type
attribute value
name no_type
processor id 1
description this is the default benchmark type for rejected benchmarks and benchmarks that are not associated with a type.
owning community none
loading contents
% Problem Solving with Prolog by John Stobo
% Adapted to use natural numbers in Peano arithmetics
% terminating

%query: goal(i,o).
goal(Name,Code) :- eq(Name,[First|Others]), reduce(Others,s(0),First,Reduced), eq(Code, Reduced).

%Original call with atom to constant list transformation
%soundex(Name,Code) :-
%   name(Name,[First|Others]),
%   reduce(Others,s(0),First,Reduced),
%   name(Code,[First|Reduced]).

% reduce (Input_list, Count_of_output, Previous_letter, Output_list)
reduce(_,s(s(s(s(0)))),_,[]) :- !. % Output is empty list...
reduce([],_,_,[]) :- !. % in both base cases.
reduce([Current|Others],Count,Current,Code) :-
   vowel_h_w_y(Current),
   !,
   reduce(Others,Count,Current,Code).
reduce([Letter|Others],Count,Letter,Code) :- !, reduce(Others,Count,Letter,Code).
reduce([Current|Others],Count,_,[Current|Code]) :- reduce(Others,s(Count),Current,Code).

vowel_h_w_y(97).      % "a"
vowel_h_w_y(101).     % "e"
vowel_h_w_y(105).     % "i"
vowel_h_w_y(111).     % "o"
vowel_h_w_y(117).     % "u"
vowel_h_w_y(104).     % "h"
vowel_h_w_y(119).     % "w"
vowel_h_w_y(121).     % "y"

eq(X,X).
popout

content may be truncated. 'popout' for larger text window.

actions get anonymous link download benchmark