summaryrefslogtreecommitdiff
path: root/ipl/procs/plural.icn
blob: 583c7cf8ce8e08250bd25cb1e308fd263ed30209 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
############################################################################
#
#	File:     plural.icn
#
#	Subject:  Procedures to produce plural of English noun
#
#	Author:   Ralph E. Griswold
#
#	Date:     July 15, 1995
#
############################################################################
#
#   This file is in the public domain.
#
############################################################################
#
#     This procedure produces the plural form of a singular English noun.
#  The procedure here is rudimentary and does not work in all cases.
#
############################################################################

procedure plural(word)		#: produce plural of word
   local lcword
   static plural_map, plural_id, plural_s

   initial {
      plural_map := table()
      plural_map["mouse"] := "mice"
      plural_map["louse"] := "lice"
      plural_map["goose"] := "geese"
      plural_map["datum"] := "data"

      plural_id := set()
      every insert(plural_id,"chassis" | "fish" | "sheep" | "semantics")

      plural_s := set()
      every insert(plural_s,"roman" | "norman" | "human" | "shaman" |
         "german" | "talisman" | "superhuman")
      }
   
   lcword := map(word)

   if member(plural_id,lcword) then return word

   if member(plural_s,lcword) then return word || "s"

   (lcword := \plural_map[lcword]) | {
      lcword ?:= {
         (tab(-3) || (match("man") & "men")) |
         (tab(-3) || (match("sis") & "ses")) |
         (tab(-2) || =("ch" | "sh" | "ss") || "es") |
         (tab(-3) || (="tus" & "ti")) |
         (tab(-2) || tab(any('cbdghmnprstvxz')) || (match("y") & "ies")) |
         (tab(-1) || tab(any('xz')) || "es") |
         (tab(0) || "s")
         }
      }

   if word ? any(&ucase) then lcword ?:= {
      map(move(1),&lcase,&ucase) || tab(0)
      }

   return lcword
         
end