Hi, Michel.

>Can you provide the code?
>

Sure.  Here is the plisp code, such as it is.  It is unoptimised,
blah-blah.  Some sample line from the data files are also
included for reference.

 .. mark.


----
#!/usr/bin/picolisp /usr/lib/picolisp/lib.l
# 
(load "@lib/misc.l" "@lib/mplib.l")

#
# read in a file, line-by-line
#
(setq ff "first.txt")
(setq fl "last.txt")

(setq first-names ())
(setq last-names  ())
(setq name-list   ())

(setq first-n     0)
(setq last-n      0)

(setq *appS   "namegen.l")
(setq *defN   10)

(seed (usec))

# ---------------------| capc
# capitalize: take a  str and return Str
#
(de capc (s)
   (pack 
      (uppc (car (chop (lowc s)))) 
      (cdr (chop (lowc s)))))

# ---------------------| 
# slurp in the firstname file
#   format  name:m-count:f-count:u-count
#
(de load-firstnames ()
   (in ff
      (skip "#")
      (until (eof)
         (setq first-names
            (cons 
               (split (chop (line T)) ",") 
               first-names))))
   (length first-names))

(de load-lastnames ()
   (in fl
      (skip "#")
      (until (eof)
         (setq last-names
            (cons 
               (line T) 
               last-names))))
   (length last-names))


# --------------------|
# read in the files and get their upper limit
#
(de read-files ()
   (setq first-n (load-firstnames))
   (setq last-n (load-lastnames)))


# --------------------|
# get a random name
#
(de random-name ()
   (prinl 
      (capc (pack (car (get first-names (rand 1 first-n)))))
      " "
      (uppc (get last-names (rand 1 last-n)))))


# --------------------|
# command-line
#

(de h ()
   (prinl "Usage: " *appS " [OPTIONS]")
   (prinl "Generate random names")
   (prinl "Options:")
   (prinl "    -n N       print N names (def: N=" *defN ")")
   (prinl "    -i         Show the database stats")
   (prinl "    -h         this help message")
   (bye) )

(de i ()
   (read-files)
   (prinl "Database Size:")
   (prinl "   Surnames   = " last-n)
   (prinl "   Firstnames = " first-n)
   (bye) )

(de n ()
   (setq *defN (format (opt))))
   
(load T)


# ---------------------|
# main program
#
(de main ()
    (read-files)
    (prinl "# Generating " *defN " names")
    (prinl "# -----------------------")
        (do *defN
        (random-name)))

(main)
(bye)
 
------------------------
$ head -34 first.txt
# fields
#  1: Firstname
#  2: # of times the name is labeled as male
#  3: # of times the name is labeled as female,
#  4: # of name occurrences
#
AADI,2,0,2
AADIL,2,0,3
AAISHA,0,2,5
AAKASH,9,0,16
AALAP,3,0,4
AALIYAH,0,22,34
AAMER,2,0,3
AAMIR,11,0,19
AAN,0,2,5
AARON,880,1,1706
AARTHI,0,4,5
AARTI,0,10,31
AASHISH,4,0,9
AASIM,5,0,6
AAYUSH,2,0,3
AB,7,2,15
ABA,1,3,8
ABAD,2,0,2
ABASS,2,0,2
ABAYOMI,4,0,5
ABBA,6,0,7
ABBAS,15,0,38
ABBE,0,14,32
ABBEY,4,36,78
ABBI,0,4,12
ABBIE,0,20,58
ABBIGAIL,0,2,3
ABBII,0,2,2

------------------------
$ head -34 last.txt 
Aaberg
Aaby
Aadland
Aagaard
Aakre
Aaland
Aalbers
Aalderink
Aalund
Aamodt
Aamot
Aanderud
Aanenson
Aanerud
Aarant
Aardema
Aarestad
Aarhus
Aaron
Aarons
Aaronson
Aarsvold
Aas
Aasby
Aase
Aasen
Aavang
Abad
Abadi
Abadie
Abair
Abaja
Abajian
Abalos


-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe

Reply via email to