[U2] Levenshtein's distance algorithm

2013-04-17 Thread George Hammerle
I got this from some other pick source and modified it a bit.

*PROGRAM.TYPEUTILITY/PROGRAM.TYPELANGUAGE.CONVERTNO/LANGUAGE.CONVERTROLL.TO.DEAD.CODENO/ROLL.TO.DEAD.CODE
$BASICTYPE 'U'
SUBROUTINE GBH.STRING.DISTANCES( SOURCE.STRING, TARGET.STRING, 
CASE.INSENSITIVE, DISTANCE, MISC.IN.OUT, ERROR.MSG )
*com-
* Written By : George HammerleDate :
*
* Purpose : Determine the number of permutations needed to make the source
*   string match the target string. A permutation may be a 
*   substitution, addition, or deletion of a character. This
*   programs uses Levenshtein's distance algorithm for string 
*   comparisons.
*
* Send In  : SOURCE.STRING
*TARGET.STRING
*CASE.INSENSITIVE1 or 0
*MISC.IN.OUT  - future use
*
* Send Out : DISTANCE
*MISC.IN.OUT - future use
*ERROR.MSG
*
* Modifications :
*
*/com

MISC.IN.OUT = ''
ERROR.MSG = ''

TESTING = 0
IF @LOGNAME = 'zhammerl' THEN
  TESTING = 1
END
IF TESTING THEN
  CASE.INSENSITIVE = 1
  SOURCE.STRING = GUMBO
  TARGET.STRING = GUMBO
  TARGET.STRING = xyz
  TARGET.STRING = 'OBMUG'
  TARGET.STRING = GAMBOL
  TARGET.STRING = 'gumbo'
  TARGET.STRING = 'gambol'
END

IF CASE.INSENSITIVE THEN
  SOURCE.STRING = UPCASE(SOURCE.STRING)
  TARGET.STRING = UPCASE(TARGET.STRING)
END


IF SOURCE.STRING = TARGET.STRING THEN
  DISTANCE = 0
  RETURN
END

LEN.SOURCE = LEN(SOURCE.STRING)
LEN.TARGET = LEN(TARGET.STRING)

IF LEN.SOURCE = 0 THEN
  DISTANCE = LEN.TARGET
  RETURN
END

IF LEN.TARGET = 0 THEN
  DISTANCE = LEN.SOURCE
  RETURN
END


TABLE = ''
FOR SS = 1 TO LEN.SOURCE + 1
  TABLESS,1 = SS-1
NEXT SS

FOR TT= 1 TO LEN.TARGET + 1
  TABLE1,TT = TT-1
NEXT TT


FOR SS = 2 TO LEN.SOURCE + 1
  SOURCE.CHAR = SOURCE.STRING[SS-1,1]
  FOR TT = 2 TO LEN.TARGET + 1
TARGET.CHAR = TARGET.STRING[TT-1,1]

IF SOURCE.CHAR = TARGET.CHAR THEN
  COST = 0
END ELSE
  COST = 1
END
 
MINIMUM.OF = TABLE(SS-1),TT + 1

IF (TABLESS,(TT-1) + 1)  MINIMUM.OF THEN
  MINIMUM.OF = TABLESS,(TT-1) + 1
END

IF (TABLE(SS-1),(TT-1) + COST )  MINIMUM.OF THEN
  MINIMUM.OF = TABLE(SS-1),(TT-1) + COST 
END

TABLESS,TT = MINIMUM.OF

  NEXT SS

NEXT TT  
 
DISTANCE = TABLELEN.SOURCE + 1,LEN.TARGET + 1

IF TESTING THEN
  CRT SOURCE.STRING = :SOURCE.STRING
  CRT TARGET.STRING = :TARGET.STRING
  FOR TT = 1 TO LEN.TARGET + 1
FOR SS = 1 TO LEN.SOURCE + 1
  CRT TABLESS,TT:  :
NEXT SS
CRT
  NEXT TT
  CRT 
  CRT DISTANCE = :DISTANCE
  CRT - DISTANCE indicates the number of substitutions, deletions or additions
  CRT   required to make the source and target string match.
END


RETURN
*com--
*- G O S U B S -
*/com-

George Hammerle 
Programming Dude 
Hubert Company LLC. 
9555 Dry Fork Road 
Harrison, Ohio 45030 
513-367-8974 
zhammerle@hubertREMOVE_THIS.com 




This e-mail and any files transmitted with it are confidential and intended
solely for the use of the individual or company to whom they are addressed. If
you have received this e-mail in error, please notify the sender immediately and
delete this e-mail including all attachments from your system. Thank you
___
U2-Users mailing list
U2-Users@listserver.u2ug.org
http://listserver.u2ug.org/mailman/listinfo/u2-users


Re: [U2] Levenshtein's distance algorithm

2013-04-17 Thread Baker Hughes
Thanks George.  Looks like a very workable starting point.

Thank you.
-Baker
x3598


-Original Message-
From: u2-users-boun...@listserver.u2ug.org 
[mailto:u2-users-boun...@listserver.u2ug.org] On Behalf Of George Hammerle
Sent: Wednesday, April 17, 2013 2:10 PM
To: u2-users@listserver.u2ug.org
Subject: [U2] Levenshtein's distance algorithm

I got this from some other pick source and modified it a bit.

*PROGRAM.TYPEUTILITY/PROGRAM.TYPELANGUAGE.CONVERTNO/LANGUAGE.CONVERTROLL.TO.DEAD.CODENO/ROLL.TO.DEAD.CODE
$BASICTYPE 'U'
SUBROUTINE GBH.STRING.DISTANCES( SOURCE.STRING, TARGET.STRING, 
CASE.INSENSITIVE, DISTANCE, MISC.IN.OUT, ERROR.MSG )
*com-
* Written By : George HammerleDate :
*
* Purpose : Determine the number of permutations needed to make the source
*   string match the target string. A permutation may be a
*   substitution, addition, or deletion of a character. This
*   programs uses Levenshtein's distance algorithm for string
*   comparisons.
*
* Send In  : SOURCE.STRING
*TARGET.STRING
*CASE.INSENSITIVE1 or 0
*MISC.IN.OUT  - future use
*
* Send Out : DISTANCE
*MISC.IN.OUT - future use
*ERROR.MSG
*
* Modifications :
*
*/com

MISC.IN.OUT = ''
ERROR.MSG = ''

TESTING = 0
IF @LOGNAME = 'zhammerl' THEN
  TESTING = 1
END
IF TESTING THEN
  CASE.INSENSITIVE = 1
  SOURCE.STRING = GUMBO
  TARGET.STRING = GUMBO
  TARGET.STRING = xyz
  TARGET.STRING = 'OBMUG'
  TARGET.STRING = GAMBOL
  TARGET.STRING = 'gumbo'
  TARGET.STRING = 'gambol'
END

IF CASE.INSENSITIVE THEN
  SOURCE.STRING = UPCASE(SOURCE.STRING)
  TARGET.STRING = UPCASE(TARGET.STRING)
END


IF SOURCE.STRING = TARGET.STRING THEN
  DISTANCE = 0
  RETURN
END

LEN.SOURCE = LEN(SOURCE.STRING)
LEN.TARGET = LEN(TARGET.STRING)

IF LEN.SOURCE = 0 THEN
  DISTANCE = LEN.TARGET
  RETURN
END

IF LEN.TARGET = 0 THEN
  DISTANCE = LEN.SOURCE
  RETURN
END


TABLE = ''
FOR SS = 1 TO LEN.SOURCE + 1
  TABLESS,1 = SS-1
NEXT SS

FOR TT= 1 TO LEN.TARGET + 1
  TABLE1,TT = TT-1
NEXT TT


FOR SS = 2 TO LEN.SOURCE + 1
  SOURCE.CHAR = SOURCE.STRING[SS-1,1]
  FOR TT = 2 TO LEN.TARGET + 1
TARGET.CHAR = TARGET.STRING[TT-1,1]

IF SOURCE.CHAR = TARGET.CHAR THEN
  COST = 0
END ELSE
  COST = 1
END

MINIMUM.OF = TABLE(SS-1),TT + 1

IF (TABLESS,(TT-1) + 1)  MINIMUM.OF THEN
  MINIMUM.OF = TABLESS,(TT-1) + 1
END

IF (TABLE(SS-1),(TT-1) + COST )  MINIMUM.OF THEN
  MINIMUM.OF = TABLE(SS-1),(TT-1) + COST
END

TABLESS,TT = MINIMUM.OF

  NEXT SS

NEXT TT

DISTANCE = TABLELEN.SOURCE + 1,LEN.TARGET + 1

IF TESTING THEN
  CRT SOURCE.STRING = :SOURCE.STRING
  CRT TARGET.STRING = :TARGET.STRING
  FOR TT = 1 TO LEN.TARGET + 1
FOR SS = 1 TO LEN.SOURCE + 1
  CRT TABLESS,TT:  :
NEXT SS
CRT
  NEXT TT
  CRT
  CRT DISTANCE = :DISTANCE
  CRT - DISTANCE indicates the number of substitutions, deletions or additions
  CRT   required to make the source and target string match.
END


RETURN
*com--
*- G O S U B S -
*/com-

George Hammerle
Programming Dude
Hubert Company LLC.
9555 Dry Fork Road
Harrison, Ohio 45030
513-367-8974
zhammerle@hubertREMOVE_THIS.com




This e-mail and any files transmitted with it are confidential and intended
solely for the use of the individual or company to whom they are addressed. If
you have received this e-mail in error, please notify the sender immediately and
delete this e-mail including all attachments from your system. Thank you
___
U2-Users mailing list
U2-Users@listserver.u2ug.org
http://listserver.u2ug.org/mailman/listinfo/u2-users



This communication, its contents and any file attachments transmitted with it 
are intended solely for the addressee(s) and may contain confidential 
proprietary information.
Access by any other party without the express written permission of the sender 
is STRICTLY PROHIBITED.
If you have received this communication in error you may not copy, distribute 
or use the contents, attachments or information in any way. Please destroy it 
and contact the sender.
___
U2-Users mailing list
U2-Users@listserver.u2ug.org
http://listserver.u2ug.org/mailman/listinfo/u2-users