Version 0 of Whadjasay

Updated 2002-07-01 17:19:19

set Name .top0 catch "destroy .top0"

    toplevel $Name     -background purple
    wm title $Name "Whadjasay ?"
    wm geometry $Name 439x437
    set Toppos($Name) 0
    set Topgeom($Name) 1

global _whad set _whad(status) Status set _whad(listfile) unixdict.txt source math.tcl source combobox.tcl package require combobox 2.0 catch {namespace import combobox::*}

proc Load_Wordlist {win fname} { global _whad

.top0.l9 configure -text "Now loading $fname"

 if {[catch {open $fname} wlist]} {
        puts "Cannot open $fname"
        }

   foreach line [split [read $wlist] \n] {
        .top0.l9 configure -text "Now parsing $line"
        lappend _whad([Soundex $line]) $line

        }

.top0.l9 configure -text "$fname word list loaded"

}

proc Soundex { in } {

  global SoundexCode
  if ![info exist SoundexCode] then {
    array set SoundexCode [list a 0 b 1 c 2 d 3 e 0 f 1 g 2 h 0 i 0 j 2 k 2 l 4 m 5 n 5 o 0 p 1 \
                       q 2 r 6 s 2 t 3 u 0 v 1 w 0 x 2 y 0 z 2]
  }
  set key ""

# Remove the leading/trailing white space punctuation etc.

  set TempIn [string trim $in "\t\n\r .,'-"]

# only use alphabetic characters, so strip out all others # also, soundex index uses only lower case chars, so force to lower

  regsub -all {[^a-z]} "[string tolower $TempIn]" {} TempIn
  if {[string length "$TempIn"] == 0} then {
    return "Z000"
  }
  set last "[string index $TempIn 0]" 
  set key "[string toupper $last]"
  set last $SoundexCode($last)

# Scan rest of string, stop at end of string or when the key is full

  set count 1
  set MaxIndex [string length $TempIn]
  for { set index 1} {(($count < 4) && ($index < $MaxIndex))} {incr index } {
    set chcode $SoundexCode([string index $TempIn $index])
    # Fold together adjacent letters sharing the same code
    if { "$last" != "$chcode"} then {
      set last "$chcode"
      # Ignore code==0 letters except as separators
      if {"$last" != 0} then {
        set key "$key$last"
        incr count
      }
    }
  }
  return [string range "${key}0000" 0 3]

}

set abouttext {Whadjasay.exe was developed by Mike Doyle ([email protected]) as a 2001 holiday gift for his friends and family. It was inspired by such entertainingly-phonetically-substituted phrases as "visualize whirled peas."

You can enter any text in the top window and click the "Convert Text" button to see its phonetically-randomized translation in the bottom window. It uses several built-in word lists, but you can use your own wordlist file (one word per line) by entering the file name in the entry field and hitting "Enter."

If you don't change the top-window text and click the convert button repeatedly, you should see a different translation at each click.

Enjoy! Happy Holidays!

--Mike

This application is Copyright 2001 Michael D. Doyle All rights reserved. }

# #---------- wm resizable .top0 0 0 set Name .top0 set Parent $Name # #---------- set Name $Parent.l9 label $Name -background black \

    -foreground green \
    -text "$_whad(status)"

set Name $Parent.f1 frame $Name -background violet \

    -borderwidth 2 \
    -height 50 \
    -relief raised \
    -width 50

place $Name -x 8 \

    -y 40 \
    -width 424 \
    -height 160 \
    -anchor nw
 #
 #----------
 set Name $Parent.f1.f12
 frame $Name     -background violet \
    -borderwidth 2 \
    -height 50 \
    -highlightbackground lightgray \
    -relief raised \
    -width 50
 place $Name     -width 416 \
    -height 152 \
    -anchor nw
 #
 #----------
 set Name $Parent.f1.f12.t13
 text $Name     -background white \
    -borderwidth 1 \
    -font -*-fixed-bold-r-normal--13-* \
    -foreground black \
    -height 5 \
    -highlightbackground lightgray \
    -insertbackground black \
    -selectbackground lightblue \
    -selectforeground black \
    -width 10 \
    -wrap word \
    -yscrollcommand "$Parent.f1.f12.sb14 set"
 $Name insert end {
 Enter a phrase or text passage here.

 Then click "Convert Text" below.
 }
 pack $Name     -anchor center \
    -expand 1 \
    -fill both \
    -padx 5 \
    -pady 5 \
    -side left
 #
 #----------
 set Name $Parent.f1.f12.sb14
 scrollbar $Name     -activebackground gray92 \
    -background violet \
    -command "$Parent.f1.f12.t13 yview" \
    -highlightbackground lightgray \
    -troughcolor purple
 pack $Name     -anchor center \
    -fill y \
    -padx 5 \
    -pady 5 \
    -side left
 #
 #----------
 set Name $Parent.f3
 frame $Name     -background violet \
    -borderwidth 2 \
    -height 50 \
    -relief raised \
    -width 50
 place $Name     -x 8 \
    -y 240 \
    -width 424 \
    -height 152 \
    -anchor nw
 #
 #----------
 set Name $Parent.f3.f12
 frame $Name     -background violet \
    -borderwidth 2 \
    -height 50 \
    -highlightbackground lightgray \
    -relief raised \
    -width 50
 place $Name     -width 416 \
    -height 144 \
    -anchor nw
 #
 #----------
 set Name $Parent.f3.f12.t13
 text $Name     -background white \
    -borderwidth 1 \
    -font -*-fixed-bold-r-normal--13-* \
    -foreground black \
    -height 5 \
    -highlightbackground lightgray \
    -insertbackground black \
    -selectbackground lightblue \
    -selectforeground black \
    -width 10 \
    -wrap word \
    -yscrollcommand "$Parent.f3.f12.sb14 set"
 $Name insert end {
 The converted text will appear here.

 Enjoy!

 --Mike



 }
 pack $Name     -anchor center \
    -expand 1 \
    -fill both \
    -padx 5 \
    -pady 5 \
    -side left
 #
 #----------
 set Name $Parent.f3.f12.sb14
 scrollbar $Name     -activebackground gray92 \
    -background violet \
    -command "$Parent.f3.f12.t13 yview" \
    -highlightbackground violet \
    -troughcolor purple
 pack $Name     -anchor center \
    -fill y \
    -padx 5 \
    -pady 5 \
    -side left
 #
 #----------

 set Name $Parent.f10
 frame $Name -background purple
 place $Name     -relx 0.02 \
    -rely 0.02 \
    -relwidth 0.7 \
    -relheight 0.06 \
    -anchor nw
 #
 #----------

 #set Name $Parent.b5
 set Name $Parent.f10.combo
 #button $Name     -background violet \
 #    -text "Reload Word List" -command {.top0.l9 configure -text "Now loading Word List";  Load_Wordlist}

   combobox $Name \
            -textvariable family \
            -editable true \
            -highlightthickness 1 \
            -width 20 -height 2 -command Load_Wordlist

    $Name list delete 0 end
    $Name list insert end "crlwords.txt"
    $Name list insert end "pocket.txt"
    $Name list insert end "soed.txt"
    $Name list insert end "unixdict.txt"
    $Name list insert end "wordlist.txt"


    $Name configure -value "unixdict.txt"

    pack $Name -side left -expand y -anchor nw

 set Name $Parent.b7
 button $Name     -background violet \
    -text "Convert Text" \
     -command {set tstring [.top0.f1.f12.t13 get 1.0 end]
                .top0.f3.f12.t13 delete 1.0 end
               foreach word [split $tstring " "] {
                set words $_whad([Soundex $word])
                .top0.f3.f12.t13 insert end " [lindex $words [expr (int ([::math::random] * [llength $words])) ]]"
                }                

                                     } 
 place $Name     -relx 0.02 \
    -rely 0.48 \
    -relwidth 0.3 \
    -relheight 0.06 \
    -anchor nw
 #
 #----------

 place $Parent.l9     -relx 0.02 \
    -rely 0.92 \
    -relwidth 0.96 \
    -relheight 0.06 \
    -anchor nw
 #
 #----------
 set Name $Parent.b13
 button $Name     -background violet \
    -text "About this Program" \
    -command { .top0.f3.f12.t13 delete 1.0 end
                .top0.f3.f12.t13 insert end $abouttext}
 place $Name     -relx 0.46 \
    -rely 0.02 \
    -relwidth 0.52 \
    -relheight 0.06 \
    -anchor nw
 #
 .top0.l9 configure -text "Loading Word List"

 wm withdraw .

 Load_Wordlist %w $_whad(listfile)
 #------< End of File >-----