Download code

Jump to: navigation, search

Back to New_York_State_Identification_and_Intelligence_System_(Rexx)

Download for Windows: single file, zip

Download for UNIX: single file, zip, tar.gz, tar.bz2

nysiis_test.rexx

 1 /* The authors of this work have released all rights to it and placed it
 2 in the public domain under the Creative Commons CC0 1.0 waiver
 3 (http://creativecommons.org/publicdomain/zero/1.0/).
 4 
 5 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 6 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 7 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 8 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 9 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
10 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
11 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12 
13 Retrieved from: http://en.literateprograms.org/New_York_State_Identification_and_Intelligence_System_(Rexx)?oldid=18728
14 */
15 
16 Do Forever
17    Call LineOut , "Enter the name: "
18    Name = LineIn()
19    If Name = "" then Leave
20    Say "NYSIIS value = " || NYSIIS(Name)
21 End
22 Exit 0
23 
24 /* ---------------------------------------------------------------------- */
25 /* code = NYSIIS(name)                                                    */
26 /*                                                                        */
27 /* Compute and return the NYSIIS code corresponding to the specfied name. */
28 /* ---------------------------------------------------------------------- */
29 NYSIIS: Procedure
30    Source = Arg(1)
31 
32    Vowels = "AEIOU"
33    Select
34       When Left(Source, 3) = "MAC" then Source = "MCC" || Substr(Source, 4)
35       When Left(Source, 3) = "SCH" then Source = "SSS" || Substr(Source, 4)
36       When Left(Source, 2) = "KN" then  Source = "NN"  || Substr(Source, 3)
37       When Left(Source, 2) = "PH" | ,
38            Left(Source, 2) = "PF" then  Source = "FF"  || Substr(Source, 3)
39       When Left(Source, 1) = "K" then   Source = "C"   || Substr(Source, 2)
40       Otherwise Nop
41    End
42 
43    Ending = Right(Source, 2)
44    If Ending = "EE" | Ending = "IE" then ,
45       Source = Left(Source, Length(Source)-2) || "Y"
46    If Ending = "DT" | Ending = "RT" | Ending = "RD" | Ending = "NT" | ,
47          Ending = "ND" then ,
48       Source = Left(Source, Length(Source)-2) || "D"
49    Result = Left(Source, 1)
50    Do Cursor = 2 to Length(Source)
51       Chars = Substr(Source, Cursor, 3)
52       Char = Left(Chars, 1)
53       Select
54          When Left(Chars, 2) = "EV" then  Char = "AF"
55          When Pos(Char, Vowels) > 0 then  Char = "A"
56          When Char = "Q" then             Char = "G"
57          When Char = "Z" then             Char = "S"
58          When Char = "M" then             Char = "N"
59          When Left(Chars, 2) = "KN" then  Char = "N"
60          When Char = "K" then             Char = "C"
61          When Left(Chars, 3) = "SCH" then Char = "SSS"
62          When Left(Chars, 2) = "PH" then  Char = "FF"
63          When Char = "H" then Do
64             If Find(Substr(Source, Cursor-1, 1), Vowels) = 0 then ,
65               Char = Substr(Source, Cursor-1, 1)
66             Else If Find(Substr(Chars, 2, 1), Vowels) = 0 then ,
67                Char = Substr(Chars, 2, 1)
68          End
69          When Cursor = "W" then ,
70             If Find(Substr(Source, Cursor-1, 1),Vowels) > 0 then ,
71               Char = Substr(Source, Cursor-1, 1)
72          Otherwise Nop
73       End /* Select */
74       Source = Left(Source, Cursor-1) || Char || Substr(Source, Cursor+1)
75       If Char <> Right(Result, 1) then ,
76          Result = Result || Char
77    End
78    If Right(Result, 1) = "S" then ,
79       Result = Left(Result, Length(Result)-1)
80    If Right(Result, 2) = "AY" then ,
81       Result = Left(Result, Length(Result)-2) || "Y"
82    If Right(Result, 1) = "A" then ,
83       Result = Left(Result, Length(Result)-1)
84    Result = Left(Result, 10)
85 
86 Return Result


hijacker
hijacker
hijacker
hijacker