LEXAS ; ISL Look-up Check Input                  ; 09-23-96
 ;;2.0;LEXICON UTILITY;**4**;Sep 23, 1996
 ;
SPL(LEXX) ; Check word
 S LEXX=$G(LEXX) Q:LEXX="" LEXX
 Q:$L(LEXX)<6&(LEXX["/") LEXX   ; PCH 4 - Quit if LEXX=XX/XX 
 N LEXFQ,LEXFQT,LEXT S LEXFQ=0,LEXFQT=""
 S LEXT=$$DBL^LEXAS4(LEXX) D COMP(LEXX,LEXT)
 S LEXT=$$REM^LEXAS4(LEXX) D COMP(LEXX,LEXT)
 S LEXT=$$LC^LEXAS7(LEXX) D COMP(LEXX,LEXT)
 S LEXT=$$TP^LEXAS6(LEXX) D COMP(LEXX,LEXT)
 S LEXT=$$ONE^LEXAS2(LEXX) D COMP(LEXX,LEXT)
 S LEXT=$$SHIFT^LEXAS3(LEXX) D COMP(LEXX,LEXT)
 S LEXT=$$SPLIT^LEXAS5(LEXX) D COMP(LEXX,LEXT)
 S LEXT=$$TRIM^LEXAS6(LEXX) D COMP(LEXX,LEXT)
 S LEXT=$$TC^LEXAS7(LEXX) D COMP(LEXX,LEXT)
 S:LEXFQT'="" LEXX=LEXFQT
 Q LEXX
COMP(LEXKN,LEXF) ; Compare words
 Q:'$L($G(LEXF))  N LEXOTKN,LEXCLEN,LEXLEN,LEXI,LEXC,LEXDIF
 S LEXOTKN=LEXF,LEXCLEN=$L(LEXKN)+$L(LEXF) S:LEXF["^" LEXCLEN=LEXCLEN-1 S LEXC=0
 S:LEXF'["^"&(+($$W(LEXF))) LEXC=1
 S:LEXF["^" LEXF=$TR(LEXF,"^"," ")
 S:$L(LEXKN)>$L(LEXF) LEXLEN=$L(LEXKN)-$L(LEXF) S:$L(LEXF)>$L(LEXKN) LEXLEN=$L(LEXF)-$L(LEXKN)
 S:$L(LEXF)=$L(LEXKN) LEXLEN=0 S LEXCLEN=LEXCLEN-LEXLEN
 I LEXKN'=LEXF D
 . I LEXOTKN'["^" S LEXC=LEXC+$$CNT(LEXKN,LEXF)
 . I LEXOTKN["^" D
 . . S LEXC=LEXC+$$CNT($P(LEXOTKN,"^",2),$E(LEXKN,(($L(LEXKN)-$L($P(LEXOTKN,"^",2)))+1),$L(LEXKN)))
 . . S LEXC=LEXC+($$CNT($P(LEXOTKN,"^",1),$E(LEXKN,1,$L($P(LEXOTKN,"^",1)))))
 N LEXMUL S LEXMUL=LEXCLEN*LEXC
 I LEXOTKN'["^",$D(^LEX(757.01,"AWRD",LEXOTKN)) S LEXMUL=LEXMUL*2
 I LEXOTKN["^",$D(^LEX(757.01,"AWRD",$P(LEXOTKN,"^",2))) S LEXMUL=LEXMUL*2
 S LEXMUL=0 I LEXC>0,LEXCLEN>0 S LEXMUL=LEXCLEN/LEXC
 S LEXDIF=0 S:LEXMUL'=0 LEXDIF=LEXCLEN+LEXC
 I LEXDIF>LEXFQ S LEXFQ=LEXDIF,LEXFQT=LEXOTKN
 Q
CNT(LEXX,LEXY) ; Count characters
 N LEXC,LEXL,LEXI,LEXU S LEXC=0
 F LEXI=1:1:$L(LEXY)  D
 . S LEXL=$E(LEXY,LEXI) Q:$D(LEXU(LEXL))  S:$E(LEXX,LEXI)=$E(LEXY,LEXI) LEXC=LEXC+1
 . I $L(LEXY)<$L(LEXX) S:$E(LEXX,(LEXI+1))=$E(LEXY,LEXI) LEXC=LEXC+1
 . I $L(LEXY)>$L(LEXX) S:$E(LEXX,(LEXI-1))=$E(LEXY,LEXI) LEXC=LEXC+1
 . S LEXU(LEXL)=""
 K LEXU S LEXX=LEXC Q LEXX
 Q
W(LEXX) ; Is LEXX a word
 Q:'$L($G(LEXX)) 0
 I $D(^LEX(757.01,"AWRD",LEXX)) Q 1
 Q 0
