Files
harbour-core/harbour/contrib/hbnf/metaph.prg
Viktor Szakats 2832c55881 2009-07-09 23:14 UTC+0200 Viktor Szakats (harbour.01 syenar.hu)
* include/hbvmpub.h
  * include/extend.api
  * include/hbwince.h
  * include/hb_io.h
  * include/hbdefs.h
  * include/hbsetup.h
  * include/hbinit.h
  * include/clipdefs.h
  * include/hbmath.h
  * include/hbzlib.h
  * include/hbregex.h
  * include/hbexprb.c
  * source/pp/hbpp.c
  * source/lang/msgrukoi.c
  * source/lang/msgzhgb.c
  * source/lang/msgruwin.c
  * source/lang/msgelwin.c
  * source/lang/msgro.c
  * source/lang/msghriso.c
  * source/lang/msgcskam.c
  * source/lang/msggl.c
  * source/lang/msges.c
  * source/lang/msgde.c
  * source/lang/msgru866.c
  * source/lang/msgcs852.c
  * source/lang/msgplmaz.c
  * source/lang/msgpliso.c
  * source/lang/msgplwin.c
  * source/lang/msgid.c
  * source/lang/msgel.c
  * source/lang/msgdewin.c
  * source/lang/msghr437.c
  * source/lang/msghr852.c
  * source/lang/msgcsiso.c
  * source/lang/msgcswin.c
  * source/lang/msgeswin.c
  * source/vm/macro.c
  * source/vm/mainwin.c
  * source/vm/maindll.c
  * source/vm/itemapi.c
  * source/vm/hvm.c
  * source/vm/cmdarg.c
  * source/vm/mainstd.c
  * source/vm/maindllp.c
  * source/vm/fm.c
  * source/vm/extrap.c
  * source/vm/thread.c
  * source/vm/main.c
  * source/vm/break.c
  * source/vm/dynlibhb.c
  * source/vm/set.c
  * source/vm/classes.c
  * source/debug/dbgtwin.prg
  * source/debug/dbgtmenu.prg
  * source/debug/dbgmenu.prg
  * source/debug/dbgthsh.prg
  * source/debug/dbgwa.prg
  * source/common/hbgete.c
  * source/common/hbver.c
  * source/common/hbprintf.c
  * source/common/hbfsapi.c
  * source/common/hbverdsp.c
  * source/common/hbwince.c
  * source/common/hbfopen.c
  * source/common/hbdate.c
  * source/macro/macroa.c
  * source/macro/macrob.c
  * source/rtl/lennum.c
  * source/rtl/gtdos/gtdos.c
  * source/rtl/setposbs.c
  * source/rtl/gtwin/gtwin.c
  * source/rtl/typefile.prg
  * source/rtl/math.c
  * source/rtl/getsys53.prg
  * source/rtl/tobject.prg
  * source/rtl/gtcrs/gtcrs.c
  * source/rtl/gtcrs/gtcrs.h
  * source/rtl/philesx.c
  * source/rtl/filehb.c
  * source/rtl/hbtoken.c
  * source/rtl/fstemp.c
  * source/rtl/ampm.c
  * source/rtl/maxrow.c
  * source/rtl/hbstrfmt.c
  * source/rtl/transfrm.c
  * source/rtl/gttone.c
  * source/rtl/datec.c
  * source/rtl/fserr.c
  * source/rtl/pushbtn.prg
  * source/rtl/memvarbl.prg
  * source/rtl/hbregexc.c
  * source/rtl/profiler.prg
  * source/rtl/hbini.prg
  * source/rtl/dbedit.prg
  * source/rtl/filesys.c
  * source/rtl/lang.c
  * source/rtl/einstv52.prg
  * source/rtl/hbbit.c
  * source/rtl/isprint.c
  * source/rtl/altd.prg
  * source/rtl/diskspac.c
  * source/rtl/console.c
  * source/rtl/gtos2/gtos2.c
  * source/rtl/adir.prg
  * source/rtl/gui.prg
  * source/rtl/hbgtcore.c
  * source/rtl/dirdrive.c
  * source/rtl/wait.prg
  * source/rtl/mlcfunc.c
  * source/rtl/scrollbr.prg
  * source/rtl/gtapiu.c
  * source/rtl/tbrowsys.prg
  * source/rtl/oemansi.c
  * source/rtl/philes53.c
  * source/rtl/color53.prg
  * source/rtl/xsavescr.c
  * source/rtl/tgetlist.prg
  * source/rtl/gtsln/mousesln.c
  * source/rtl/gtsln/kbsln.c
  * source/rtl/gtsln/gtsln.h
  * source/rtl/disksphb.c
  * source/rtl/tlabel.prg
  * source/rtl/radiogrp.prg
  * source/rtl/scrrow.c
  * source/rtl/net.c
  * source/rtl/stuff.c
  * source/rtl/checkbox.prg
  * source/rtl/filebuf.c
  * source/rtl/mtran.c
  * source/rtl/gete.c
  * source/rtl/hbproces.c
  * source/rtl/gtwvt/gtwvt.c
  * source/rtl/fssize.c
  * source/rtl/memofile.c
  * source/rtl/hbffind.c
  * source/rtl/tmenuitm.prg
  * source/rtl/gtsys.c
  * source/rtl/devoutp.prg
  * source/codepage/uckoi8.c
  * source/codepage/uckoi8u.c
  * source/codepage/cphu852s.c
  * source/codepage/cpes850c.c
  * source/codepage/cphuisos.c
  * source/codepage/ucmaz.c
  * source/codepage/cptr857.c
  * source/codepage/ucmik.c
  * source/codepage/cphr437.c
  * source/codepage/cphuwins.c
  * source/rdd/dbjoin.prg
  * source/rdd/dbnubs.c
  * source/rdd/dbfuncs.prg
  * source/rdd/dbtotal.prg
  * source/rdd/dbstrux.prg
  * source/rdd/dbsort.prg
  * source/rdd/dbfcdx/dbfcdx1.c
  * source/rdd/hbsix/sxcompr.c
  * source/compiler/hbmain.c
  * source/compiler/expropta.c
  * source/compiler/exproptb.c
  * source/compiler/fixflex.c
  * source/compiler/compi18n.c
  * source/compiler/gencobj.c
  * source/compiler/hbopt.c
  * source/compiler/hbgenerr.c
  * utils/hbtest/rt_main.h
  * utils/hbtest/rt_main.ch
  * utils/hbtest/rt_trans.prg
  * utils/hbtest/rt_misc.prg
  * utils/hbtest/rt_vars.ch
  * contrib/gtalleg/gtalleg.c
  * contrib/gtalleg/ssf.h
  * contrib/hbmysql/mysqlold.c
  * contrib/hbmysql/mysql.c
  * contrib/hbct/charlist.c
  * contrib/hbct/ctnet.c
  * contrib/hbct/charonly.c
  * contrib/hbct/ctset.c
  * contrib/hbct/ctset.h
  * contrib/hbct/cterror.ch
  * contrib/hbct/ftoc.c
  * contrib/hbct/charevod.c
  * contrib/hbct/exponent.c
  * contrib/hbct/dattime3.c
  * contrib/hbct/ct.prg
  * contrib/hbct/cursor.c
  * contrib/hbct/color.c
  * contrib/hbct/charone.c
  * contrib/hbct/numconv.prg
  * contrib/hbct/cttime.prg
  * contrib/hbct/ctstr.h
  * contrib/hbct/atnum.c
  * contrib/hbct/disk.c
  * contrib/hbct/misc1.c
  * contrib/hbct/print.c
  * contrib/xhb/hblog.ch
  * contrib/xhb/bkgtsks.c
  * contrib/xhb/wintypes.ch
  * contrib/xhb/classex.ch
  * contrib/xhb/hbcomprs.c
  * contrib/xhb/ttable.ch
  * contrib/xhb/hbcompat.ch
  * contrib/xhb/arrayblk.prg
  * contrib/xhb/hbctypes.ch
  * contrib/xhb/xhbextrn.ch
  * contrib/xhb/filestat.c
  * contrib/xhb/hblogdef.ch
  * contrib/xhb/xhbcopyf.c
  * contrib/xhb/hbserv.c
  * contrib/xhb/xhbfunc.c
  * contrib/hbodbc/odbcold.c
  * contrib/hbtpathy/telepath.ch
  * contrib/hbmzip/hbmzip.c
  * contrib/hbblat/hbblat.ch
  * contrib/hbxbp/xbpfiledialog.prg
  * contrib/hbxbp/gra.ch
  * contrib/hbxbp/xbpwindow.prg
  * contrib/hbxbp/xbp.ch
  * contrib/hbxbp/xbphtmlviewer.prg
  * contrib/hbxbp/xbptoolbar.prg
  * contrib/hbxbp/appevent.ch
  * contrib/hbxbp/xbpgeneric.prg
  * contrib/xpp/philesx.c
  * contrib/hbnf/acctyear.prg
  * contrib/hbnf/byteneg.prg
  * contrib/hbnf/isshare.prg
  * contrib/hbnf/kspeed.c
  * contrib/hbnf/prtscr.c
  * contrib/hbnf/ftshadow.c
  * contrib/hbnf/descendn.c
  * contrib/hbnf/scancode.prg
  * contrib/hbnf/vidmode.prg
  * contrib/hbnf/acctadj.prg
  * contrib/hbnf/vidcur.prg
  * contrib/hbnf/iamidle.c
  * contrib/hbnf/acctmnth.prg
  * contrib/hbnf/madd.prg
  * contrib/hbnf/fttext.c
  * contrib/hbnf/mouse1.prg
  * contrib/hbnf/settime.prg
  * contrib/hbnf/page.prg
  * contrib/hbnf/setkeys.c
  * contrib/hbnf/month.prg
  * contrib/hbnf/acctweek.prg
  * contrib/hbnf/acctqtr.prg
  * contrib/hbnf/dosver.prg
  * contrib/hbnf/metaph.prg
  * contrib/hbnf/menu1.prg
  * contrib/hbnf/byteand.prg
  * contrib/hbnf/bytexor.prg
  * contrib/hbnf/byteor.prg
  * contrib/hbnf/asum.prg
  * contrib/hbnf/wda.prg
  * contrib/hbnf/aavg.prg
  * contrib/hbnf/mouse.c
  * contrib/hbnf/setdate.prg
  * contrib/hbnf/amedian.prg
  * contrib/hbnf/blink.prg
  * contrib/hbnf/getvid.c
  * contrib/hbnf/getver.c
  * contrib/hbnf/nwuid.prg
  * contrib/hbnf/aemaxlen.prg
  * contrib/hbnf/bitset.prg
  * contrib/hbnf/nwlstat.prg
  * contrib/hbnf/tempfile.prg
  * contrib/hbnf/diskfunc.prg
  * contrib/hbnf/d2e.prg
  * contrib/hbnf/mouse2.prg
  * contrib/hbnf/firstday.prg
  * contrib/hbnf/menutonf.prg
  * contrib/hbnf/pvid.prg
  * contrib/hbnf/isbit.prg
  * contrib/hbnf/datecnfg.prg
  * contrib/hbnf/putkey.c
  * contrib/hbnf/getenvrn.c
  * contrib/hbnf/bytenot.prg
  * contrib/hbnf/aeminlen.prg
  * contrib/hbnf/year.prg
  * contrib/hbnf/ftmenuto.ch
  * contrib/hbnf/rmdir.c
  * contrib/hbnf/sysmem.prg
  * contrib/hbnf/bitclr.prg
  * contrib/hbnf/setlastk.c
  * contrib/hbnf/clrsel.prg
  * contrib/hbcurl/hbcurl.ch
  * contrib/gtwvg/gtwvg.c
  * contrib/gtwvg/wvgax.prg
  * contrib/gtwvg/gtwvg.h
  * contrib/gtwvg/wvggui.c
  * contrib/gtwvg/wvggui.h
  * contrib/gtwvg/wvgwin.c
  * contrib/gtwvg/wvgutils.c
  * contrib/gtwvg/wvgcore.c
  * contrib/gtwvg/wvgtabpg.prg
  * contrib/gtwvg/wvgsink.c
  * contrib/gtwvg/wvgwing.c
  * contrib/hbclipsm/num.c
  * contrib/hbclipsm/stack.c
  * contrib/rddads/rddads.h
  * contrib/rddads/ads1.c
  * contrib/hbfimage/fi_winfu.c
  * contrib/hbfimage/fi_wrp.c
  * contrib/hbgd/gd.ch
  * contrib/hbgd/gdchart.prg
  * contrib/hbgd/gdimage.prg
  * contrib/hbgd/gdwrp.c
  * contrib/hbmisc/nconvert.prg
  * contrib/hbmisc/stringsx.c
  * contrib/hbmisc/spd.c
  * contrib/hbmisc/stringp.prg
  * contrib/hbwin/win_prn2.c
  * contrib/hbwin/wapi_commctrl.c
  * contrib/hbwin/wapi_winbase.c
  * contrib/hbwin/wapi_winuser.c
  * contrib/hbwin/hbwinole.h
  * contrib/hbwin/win_dll.c
  * contrib/hbwin/axfunc.prg
  * contrib/hbwin/win_prn1.c
  * contrib/hbvpdf/hbvpdf.ch
  * examples/hboleold/win_ole.c
    * Formatting:
       - Removing EOL whitespaces.
       - Removing extra empty lines at EOF.
       - Adding EOL at EOF if missing.
      (except in foreign code)
2009-07-09 21:22:22 +00:00

393 lines
14 KiB
Plaintext

/*
* $Id$
*/
/*
* File......: metaph.prg
* Author....: Dave Adams
* CIS ID....: ?
*
* This is an original work by Dave Adams and is placed in the
* public domain.
*
* Modification history:
* ---------------------
*
* Rev 1.2 15 Aug 1991 23:04:00 GLENN
* Forest Belt proofread/edited/cleaned up doc
*
* Rev 1.1 14 Jun 1991 19:52:20 GLENN
* Minor edit to file header
*
* Rev 1.0 01 Apr 1991 01:01:44 GLENN
* Nanforum Toolkit
*
*/
/* $DOC$
* $FUNCNAME$
* FT_METAPH()
* $CATEGORY$
* String
* $ONELINER$
* Convert a character string to MetaPhone format
* $SYNTAX$
* FT_METAPH( <cName> [, <nSize> ] ) -> cMetaPhone
* $ARGUMENTS$
* <cName> is the character string to convert
* <nSize> is the length of the character string to be returned.
* If not specified the default length is 4 bytes.
* $RETURNS$
* A phonetically spelled character string
* $DESCRIPTION$
* This function is a character function use to index and search for
* sound-alike or phonetic matches. It is an alternative to
* the SOUNDEX() function, and addresses some basic pronunciation
* rules, by looking at surrounding letters to determine how parts of
* the string are pronounced. FT_METAPH() will group sound-alikes
* together, and forgive shortcomings in spelling ability.
* $EXAMPLES$
* USE Persons
* INDEX ON FT_METAPH( LastName ) TO LastName
* SEEK FT_METAPH( "Philmore" )
* ? FOUND(), LastName // Result: .T. Philmore
* SEEK FT_METAPH( "Fillmore" )
* ? FOUND(), LastName // Result: .T. Philmore
* $END$
*/
/*
* File Contents
*
* FT_METAPH() Calculates the metaphone of a name
* _ftMakeAlpha() Removes non-alpha characters from a string
* _ftConvVowel() Converts all vowels to the letter 'v'
*
*
* Commentary
*
* The concepts for this algoritm were adapted from an article in the
* Computer Language Magazine (Dec.90, Vol.7, No.12) written by
* Lawrence B.F. Phillips.
*
* The STRTRAN function was selected to calculate the MetaPhone, to
* allow the algoritm to be fine-tuned in an easy manner, as there are
* always exceptions to any phonetic pronunciation in not only English,
* but many other languages as well.
*
* What is a metaphone?
* Basically it takes a character string, removes the vowels, and equates
* letters (or groups of letters) to other consonent sounds. The vowels
* are not removed until near the end, as they play an important part
* in determining how some consonents sound in different surroundings.
*
* The consonant sounds are: B, F, H, J, K, L, M, N, P, R, S, T, W, X, Y, 0
* Vowels are only included if they are at the beginning.
* Here are the transformations. The order of evaluation is important
* as characters may meet more than one transformation conditions.
* ( note: v = vowel )
*
* B --> B unless at end of a word after 'm' as in dumb.
* C --> X (sh) CIA, TCH, CH, ISCH, CC
* S SCI, SCE, SCY, CI, CE, CY
* K otherwise ( including CK )
* D --> J DGE, DGY, DGI
* T otherwise
* F --> F
* G --> K GHv, vGHT
* W vGH
* J DGE, DGY, DGI, GI, GE, GY
* N GN
* K otherwise
* H --> H vHv
* otherwise silent
* J --> J
* K --> K
* L --> L
* M --> M
* N --> N
* P --> F PH
* P otherwise
* Q --> K
* R --> R
* S --> X (sh) SH, SIO, SIA, ISCH
* S otherwise
* T --> X (sh) TIA, TIO, TCH
* 0 (th) TH
* T otherwise
* V --> F
* W --> W
* X --> KS
* Y --> vY
* Y otherwise
* Z --> S
*
*/
*------------------------------------------------
// Demo of FT_METAPH()
// #define FT_TEST .T.
#IFDEF FT_TEST
FUNCTION MAIN()
LOCAL cJunk := SPACE( 8000 )
LOCAL aNames := {}
LOCAL cName, nElem
SET( _SET_SCOREBOARD, .F. )
SET( _SET_COLOR, "W/B" )
CLS
// Demo will create an array of names and display in 3 columns
// _ftRow() and _ftCol() will calculate the screen co-ordinates
// by evaluating the element number
AADD( aNames, "Adams" )
AADD( aNames, "Addams" )
AADD( aNames, "Atoms" )
AADD( aNames, "Adamson" )
AADD( aNames, "Cajun" )
AADD( aNames, "Cagen" )
AADD( aNames, "Cochy" )
AADD( aNames, "Cocci" )
AADD( aNames, "Smith" )
AADD( aNames, "Smythe" )
AADD( aNames, "Naylor" )
AADD( aNames, "Nailer" )
AADD( aNames, "Holberry" )
AADD( aNames, "Wholebary" )
AADD( aNames, "Jackson" )
AADD( aNames, "Jekksen" )
AADD( aNames, "The Source" )
AADD( aNames, "The Sores" )
AADD( aNames, "Jones" )
AADD( aNames, "Johns" )
AADD( aNames, "Lennon" )
AADD( aNames, "Lenin" )
AADD( aNames, "Fischer" )
AADD( aNames, "Fisher" )
AADD( aNames, "O'Donnell" )
AADD( aNames, "O Donald" )
AADD( aNames, "Pugh" )
AADD( aNames, "Pew" )
AADD( aNames, "Heimendinger" )
AADD( aNames, "Hymendinker" )
AADD( aNames, "Knight" )
AADD( aNames, "Nite" )
AADD( aNames, "Lamb" )
AADD( aNames, "Lamb Chops" )
AADD( aNames, "Stephens" )
AADD( aNames, "Stevens" )
AADD( aNames, "Neilson" )
AADD( aNames, "Nelson" )
AADD( aNames, "Tchaikovski" )
AADD( aNames, "Chikofski" )
AADD( aNames, "Caton" )
AADD( aNames, "Wright" )
AADD( aNames, "Write" )
AADD( aNames, "Right" )
AADD( aNames, "Manual" )
AADD( aNames, "Now" )
AADD( aNames, "Wheatabix" )
AADD( aNames, "Science" )
AADD( aNames, "Cinzano" )
AADD( aNames, "Lucy" )
AADD( aNames, "Reece" )
AADD( aNames, "Righetti" )
AADD( aNames, "Oppermann" )
AADD( aNames, "Bookkeeper" )
AADD( aNames, "McGill" )
AADD( aNames, "Magic" )
AADD( aNames, "McLean" )
AADD( aNames, "McLane" )
AADD( aNames, "Maclean" )
AADD( aNames, "Exxon" )
// display names and metaphones in 3 columns on screen
AEVAL( aNames, ;
{ | cName, nElem | ;
SETPOS( _ftRow( nElem ), _ftCol( nElem ) ), ;
QQOUT( PadR( cName, 18, "." ) + FT_METAPH( cName ) ) ;
} )
SETPOS( 21, 00 )
QUIT
*------------------------------------------------
STATIC FUNCTION _ftRow( nElem ) // Determine which row to print on
RETURN IIF( nElem > 40, nElem - 40, IIF( nElem > 20, nElem - 20, nElem ) )
*------------------------------------------------
STATIC FUNCTION _ftCol( nElem ) // Determine which column to start print
RETURN IIF( nElem > 40, 55, IIF( nElem > 20, 28, 1 ) )
*------------------------------------------------
#endif
// End of Test program
*------------------------------------------------
FUNCTION FT_METAPH ( cName, nSize )
// Calculates the metaphone of a character string
LOCAL cMeta
cName := IIF( cName == NIL, "", cName ) // catch-all
nSize := IIF( nSize == NIL, 4, nSize ) // default size: 4-bytes
// Remove non-alpha characters and make upper case.
// The string is padded with 1 space at the beginning & end.
// Spaces, if present inside the string, are not removed until all
// the prefix/suffix checking has been completed.
cMeta := " " + _ftMakeAlpha( UPPER( ALLTRIM( cName ) ) ) + " "
// prefixes which need special consideration
IF " KN" $ cMeta ; cMeta := STRTRAN( cMeta, " KN" , " N" ) ; ENDIF
IF " GN" $ cMeta ; cMeta := STRTRAN( cMeta, " GN" , " N" ) ; ENDIF
IF " PN" $ cMeta ; cMeta := STRTRAN( cMeta, " PN" , " N" ) ; ENDIF
IF " AE" $ cMeta ; cMeta := STRTRAN( cMeta, " AE" , " E" ) ; ENDIF
IF " X" $ cMeta ; cMeta := STRTRAN( cMeta, " X" , " S" ) ; ENDIF
IF " WR" $ cMeta ; cMeta := STRTRAN( cMeta, " WR" , " R" ) ; ENDIF
IF " WHO" $ cMeta ; cMeta := STRTRAN( cMeta, " WHO", " H" ) ; ENDIF
IF " WH" $ cMeta ; cMeta := STRTRAN( cMeta, " WH" , " W" ) ; ENDIF
IF " MCG" $ cMeta ; cMeta := STRTRAN( cMeta, " MCG", " MK" ) ; ENDIF
IF " MC" $ cMeta ; cMeta := STRTRAN( cMeta, " MC" , " MK" ) ; ENDIF
IF " MACG" $ cMeta ; cMeta := STRTRAN( cMeta, " MACG"," MK" ) ; ENDIF
IF " MAC" $ cMeta ; cMeta := STRTRAN( cMeta, " MAC", " MK" ) ; ENDIF
IF " GI" $ cMeta ; cMeta := STRTRAN( cMeta, " GI", " K" ) ; ENDIF
// Suffixes which need special consideration
IF "MB " $ cMeta ; cMeta := STRTRAN( cMeta, "MB " , "M " ) ; ENDIF
IF "NG " $ cMeta ; cMeta := STRTRAN( cMeta, "NG " , "N " ) ; ENDIF
// Remove inner spaces (1st and last byte are spaces)
IF " " $ SUBSTR( cMeta, 2, LEN( cMeta ) - 2 )
cMeta := " " + STRTRAN( cMeta, " " , "" ) + " "
ENDIF
// Double consonants sound much the same as singles
IF "BB" $ cMeta ; cMeta := STRTRAN( cMeta, "BB" , "B" ) ; ENDIF
IF "CC" $ cMeta ; cMeta := STRTRAN( cMeta, "CC" , "CH" ) ; ENDIF
IF "DD" $ cMeta ; cMeta := STRTRAN( cMeta, "DD" , "T" ) ; ENDIF
IF "FF" $ cMeta ; cMeta := STRTRAN( cMeta, "FF" , "F" ) ; ENDIF
IF "GG" $ cMeta ; cMeta := STRTRAN( cMeta, "GG" , "K" ) ; ENDIF
IF "KK" $ cMeta ; cMeta := STRTRAN( cMeta, "KK" , "K" ) ; ENDIF
IF "LL" $ cMeta ; cMeta := STRTRAN( cMeta, "LL" , "L" ) ; ENDIF
IF "MM" $ cMeta ; cMeta := STRTRAN( cMeta, "MM" , "M" ) ; ENDIF
IF "NN" $ cMeta ; cMeta := STRTRAN( cMeta, "NN" , "N" ) ; ENDIF
IF "PP" $ cMeta ; cMeta := STRTRAN( cMeta, "PP" , "P" ) ; ENDIF
IF "RR" $ cMeta ; cMeta := STRTRAN( cMeta, "RR" , "R" ) ; ENDIF
IF "SS" $ cMeta ; cMeta := STRTRAN( cMeta, "SS" , "S" ) ; ENDIF
IF "TT" $ cMeta ; cMeta := STRTRAN( cMeta, "TT" , "T" ) ; ENDIF
IF "XX" $ cMeta ; cMeta := STRTRAN( cMeta, "XX" , "KS" ) ; ENDIF
IF "ZZ" $ cMeta ; cMeta := STRTRAN( cMeta, "ZZ" , "S" ) ; ENDIF
// J sounds
IF "DGE" $ cMeta ; cMeta := STRTRAN( cMeta, "DGE" , "J" ) ; ENDIF
IF "DGY" $ cMeta ; cMeta := STRTRAN( cMeta, "DGY" , "J" ) ; ENDIF
IF "DGI" $ cMeta ; cMeta := STRTRAN( cMeta, "DGI" , "J" ) ; ENDIF
IF "GI" $ cMeta ; cMeta := STRTRAN( cMeta, "GI" , "J" ) ; ENDIF
IF "GE" $ cMeta ; cMeta := STRTRAN( cMeta, "GE" , "J" ) ; ENDIF
IF "GY" $ cMeta ; cMeta := STRTRAN( cMeta, "GY" , "J" ) ; ENDIF
// X sounds (KS)
IF "X" $ cMeta ; cMeta := STRTRAN( cMeta, "X" , "KS" ) ; ENDIF
// special consideration for SCH
IF "ISCH" $ cMeta; cMeta := STRTRAN( cMeta, "ISCH", "IX" ) ; ENDIF
IF "SCH" $ cMeta ; cMeta := STRTRAN( cMeta, "SCH" , "SK" ) ; ENDIF
// sh sounds (X)
IF "CIA" $ cMeta ; cMeta := STRTRAN( cMeta, "CIA" , "X" ) ; ENDIF
IF "SIO" $ cMeta ; cMeta := STRTRAN( cMeta, "SIO" , "X" ) ; ENDIF
IF "C" $ cMeta ; cMeta := STRTRAN( cMeta, "SIA" , "X" ) ; ENDIF
IF "SH" $ cMeta ; cMeta := STRTRAN( cMeta, "SH" , "X" ) ; ENDIF
IF "TIA" $ cMeta ; cMeta := STRTRAN( cMeta, "TIA" , "X" ) ; ENDIF
IF "TIO" $ cMeta ; cMeta := STRTRAN( cMeta, "TIO" , "X" ) ; ENDIF
IF "TCH" $ cMeta ; cMeta := STRTRAN( cMeta, "TCH" , "X" ) ; ENDIF
IF "CH" $ cMeta ; cMeta := STRTRAN( cMeta, "CH" , "X" ) ; ENDIF
// hissing sounds (S)
IF "SCI" $ cMeta ; cMeta := STRTRAN( cMeta, "SCI" , "S" ) ; ENDIF
IF "SCE" $ cMeta ; cMeta := STRTRAN( cMeta, "SCE" , "S" ) ; ENDIF
IF "SCY" $ cMeta ; cMeta := STRTRAN( cMeta, "SCY" , "S" ) ; ENDIF
IF "CI" $ cMeta ; cMeta := STRTRAN( cMeta, "CI" , "S" ) ; ENDIF
IF "CE" $ cMeta ; cMeta := STRTRAN( cMeta, "CE" , "S" ) ; ENDIF
IF "CY" $ cMeta ; cMeta := STRTRAN( cMeta, "CY" , "S" ) ; ENDIF
IF "Z" $ cMeta ; cMeta := STRTRAN( cMeta, "Z" , "S" ) ; ENDIF
// th sound (0)
IF "TH" $ cMeta ; cMeta := STRTRAN( cMeta, "TH" , "0" ) ; ENDIF
// Convert all vowels to 'v' from 3rd byte on
cMeta := LEFT( cMeta, 2 ) + _ftConvVowel( SUBSTR( cMeta, 3 ) )
// Make Y's silent if not followed by vowel
IF "Y" $ cMeta
cMeta := STRTRAN( cMeta, "Yv" , "#" ) // Y followed by vowel
cMeta := STRTRAN( cMeta, "Y" , "" ) // not followed by vowel
cMeta := STRTRAN( cMeta, "#" , "Yv" ) // restore Y and vowel
ENDIF
// More G sounds, looking at surrounding vowels
IF "GHv" $ cMeta ; cMeta := STRTRAN( cMeta, "GHv" , "G" ) ; ENDIF
IF "vGHT" $ cMeta; cMeta := STRTRAN( cMeta, "vGHT", "T" ) ; ENDIF
IF "vGH" $ cMeta ; cMeta := STRTRAN( cMeta, "vGH" , "W" ) ; ENDIF
IF "GN" $ cMeta ; cMeta := STRTRAN( cMeta, "GN" , "N" ) ; ENDIF
IF "G" $ cMeta ; cMeta := STRTRAN( cMeta, "G" , "K" ) ; ENDIF
// H sounds, looking at surrounding vowels
IF "vHv" $ cMeta ; cMeta := STRTRAN( cMeta, "vHv" , "H" ) ; ENDIF
IF "vH" $ cMeta ; cMeta := STRTRAN( cMeta, "vH" , "" ) ; ENDIF
// F sounds
IF "PH" $ cMeta ; cMeta := STRTRAN( cMeta, "PH" , "F" ) ; ENDIF
IF "V" $ cMeta ; cMeta := STRTRAN( cMeta, "V" , "F" ) ; ENDIF
// D sounds a bit like T
IF "D" $ cMeta ; cMeta := STRTRAN( cMeta, "D" , "T" ) ; ENDIF
// K sounds
IF "CK" $ cMeta ; cMeta := STRTRAN( cMeta, "CK" , "K" ) ; ENDIF
IF "Q" $ cMeta ; cMeta := STRTRAN( cMeta, "Q" , "K" ) ; ENDIF
IF "C" $ cMeta ; cMeta := STRTRAN( cMeta, "C" , "K" ) ; ENDIF
// Remove vowels
cMeta := STRTRAN( cMeta, "v", "" )
RETURN PadR( ALLTRIM( cMeta ), nSize )
*------------------------------------------------
STATIC FUNCTION _ftMakeAlpha ( cStr )
// Strips non-alpha characters from a string, leaving spaces
LOCAL x, cAlpha := ""
FOR x := 1 to LEN( cStr )
IF SUBSTR( cStr, x, 1 ) == " " .OR. ISALPHA( SUBSTR( cStr, x, 1 ) )
cAlpha := cAlpha + SUBSTR( cStr, x, 1 )
ENDIF
NEXT
RETURN cAlpha
*------------------------------------------------
STATIC FUNCTION _ftConvVowel ( cStr )
// Converts all vowels to letter 'v'
LOCAL x, cConverted := ""
FOR x := 1 to LEN( cStr )
IF SUBSTR( cStr, x, 1 ) $ "AEIOU"
cConverted := cConverted + "v"
ELSE
cConverted := cConverted + SUBSTR( cStr, x, 1 )
ENDIF
NEXT
RETURN cConverted
*------------------------------------------------
// eof metaph.prg