home *** CD-ROM | disk | FTP | other *** search
/ Power CD-ROM!! 7 / POWERCD7.ISO / prgmming / clipper / levcost.prg < prev    next >
Text File  |  1993-10-14  |  3KB  |  93 lines

  1. /*
  2.  * GT CLIPPER STANDARD HEADER
  3.  *
  4.  * File......: levcost.prg
  5.  * Author....: Andy M Leighton
  6.  * BBS.......: The Dark Knight Returns
  7.  * Net/Node..: 050/069
  8.  * User Name.: Andy Leighton
  9.  * Date......: $Date$
  10.  * Revision..: $Revision$
  11.  *
  12.  * This is an original work by Andy Leighton and is placed in the
  13.  * public domain.
  14.  *
  15.  * Modification history:
  16.  * ---------------------
  17.  *
  18.  * $Log$
  19.  *
  20.  */
  21.  
  22. /*  $DOC$
  23.  *  $FUNCNAME$
  24.  *       GT_LEVCOST()
  25.  *  $CATEGORY$
  26.  *       String
  27.  *  $ONELINER$
  28.  *       Alter the costing of the various operations for GT_LevDist()
  29.  *  $SYNTAX$
  30.  *       GT_LevCost(<aCosts>) --> aOldCosts
  31.  *  $ARGUMENTS$
  32.  *       <aCosts>    -  An array of operation costs
  33.  *                          aCosts[1] == cost of insertion
  34.  *                          aCosts[2] == cost of deletion
  35.  *                          aCosts[3] == cost of substitution
  36.  *  $RETURNS$
  37.  *       aOldCosts   -  The old set of operation costs
  38.  *  $DESCRIPTION$
  39.  *       Alter the costing of the various operations for GT_LevDist()
  40.  *
  41.  *       For  some  applications  of  Levenshtein  distances  it is
  42.  *       important to  alter the  cost of  the various  operations.
  43.  *       For  example  if  analysing  DNA  insertions and deletions
  44.  *       should  be  more  costly  than  substitutions.  However if
  45.  *       trying to write voice recognition software the reverse  is
  46.  *       true (sounds often vary in length)
  47.  *
  48.  *       REFERENCE
  49.  *       Doctor Dobb's Journal #187, April 1992
  50.  *
  51.  *       IMPROVEMENTS
  52.  *       The  main  improvements  in  this  routine will be made by
  53.  *       introducing a more complex operation costing.
  54.  *
  55.  *       ie. have three matrices that record the cost of adding  or
  56.  *           deleting  a  specific   letter,  and  substituting   a
  57.  *           specified letter with another.
  58.  *
  59.  *       More improvements can be achieved  but at the loss of  the
  60.  *       general purpose of the routine.
  61.  *
  62.  *       This is left as an exercise for the foolhardy or brave.
  63.  *  $SEEALSO$
  64.  *       GT_LEVDIST()
  65.  *  $EXAMPLES$
  66.  *  $END$
  67.  */
  68.  
  69. #include "gt_LIB.ch"
  70. #include "levensht.ch"
  71.  
  72. function GT_LevCost(aCosts)
  73.  
  74.    local xRet := array(3)
  75.  
  76.    xRet[1] := gGT_Cost(LV_INS)
  77.    xRet[2] := gGT_Cost(LV_DEL)
  78.    xRet[3] := gGT_Cost(LV_SUB)
  79.  
  80.    if valtype("aCosts[1]") == "N"
  81.       gGT_Cost(LV_INS, aCosts[1])
  82.    endif
  83.  
  84.    if valtype("aCosts[2]") == "N"
  85.       gGT_Cost(LV_DEL, aCosts[2])
  86.    endif
  87.  
  88.    if valtype("aCosts[3]") == "N"
  89.       gGT_Cost(LV_SUB, aCosts[3])
  90.    endif
  91.  
  92. return xRet
  93.