Post by meerkat on Sept 19, 2019 9:47:01 GMT -5
Saw the translation of Spanish to English post on Liberty Basic.
libertybasiccom.proboards.com/user/2/recent
I always wanted to know how well SOUNDEX worked. We all know how the sql SOUNDEX verb works. However SQLite does not have it available unless you compile it in. Because I didn't wanna do that, I had to roll my own soundex function.
Anyway I used the file available from the LB post and loaded it into a table defined as:
CREATE TABLE trans (
transFrom TEXT,
transTo TEXT,
type TEXT,
sndx CHAR(4) );
CREATE INDEX trans_spanish ON trans( transFrom, transTo);
CREATE INDEX trans_english ON trans( transTo);
CREATE INDEX trans_sndx ON trans( sndx , transFrom);
transFrom is the Spanish word
transTo is the definition of the spanish word.
Translating Spanish to English.
First the program generates the Soundex word since I do not have Soundex compiled into SQLite.
It searches for any spanish word that equals the word.
It searches for any spanish word that begins with the word.
It searches for any Soundex that matches.
Translating English to Spanish.
It searches for the spanish definition that begins with the word.
It searches for any spanish definition that contains any word that begins with the word.
It shows the results with a count for all searches that has a result greater than zero.
Some results:
Program
libertybasiccom.proboards.com/user/2/recent
I always wanted to know how well SOUNDEX worked. We all know how the sql SOUNDEX verb works. However SQLite does not have it available unless you compile it in. Because I didn't wanna do that, I had to roll my own soundex function.
Anyway I used the file available from the LB post and loaded it into a table defined as:
CREATE TABLE trans (
transFrom TEXT,
transTo TEXT,
type TEXT,
sndx CHAR(4) );
CREATE INDEX trans_spanish ON trans( transFrom, transTo);
CREATE INDEX trans_english ON trans( transTo);
CREATE INDEX trans_sndx ON trans( sndx , transFrom);
transFrom is the Spanish word
transTo is the definition of the spanish word.
Translating Spanish to English.
First the program generates the Soundex word since I do not have Soundex compiled into SQLite.
It searches for any spanish word that equals the word.
It searches for any spanish word that begins with the word.
It searches for any Soundex that matches.
Translating English to Spanish.
It searches for the spanish definition that begins with the word.
It searches for any spanish definition that contains any word that begins with the word.
It shows the results with a count for all searches that has a result greater than zero.
Some results:
Program
bf1$ = "<SPAN STYLE='font-family:Arial; font-weight:700; font-size:12pt'>"
db$ = "c:\rbp101\projects\a_project\data\a.db"
sqliteconnect #sql, db$ ' Connect to the db
maxList = 15
[getWord]
html bf1$;"<P><TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0 BGCOLOR=silver>"
html "<TR>"
html "<TD ALIGN=RIGHT>Translate"
html "</TD><TD>"
html "<INPUT TYPE=TEXT NAME='fromWord' id='fromWord' SIZE=30 VALUE='";fromWord$;"'>"
html "</TD></TR><TR><TD ALIGN=RIGHT>Display count</TD><TD>"
html "<INPUT TYPE=number NAME='maxList' id='maxList' SIZE=4 VALUE=";maxList;" min=1 max=100>"
html "</TD></TR><TR><TD COLSPAN=2 align=center>"
button #s2e, "Spanish to English", [s2e] ' spanish to english
button #e2s, "English to Spanish", [e2s] ' english to spanish
button #ext, "Exit", [ext]
html "</TD></TR></TABLE>"
wait
[s2e]
from2$ = "S" ' set switch to Spanish to English
goto [doTrn]
[e2s]
from2$ = "E" ' set switch to Engilsh to Spanish
[doTrn]
maxList = val(#request get$("maxList")) ' get the pass data and determine what routine
fromWord$ = #request get$("fromWord") ' gomme some of the fromWord
fromWord$ = trim$(lower$(fromWord$))
cls
if fromWord$ = "" then goto [getWord]
if from2$ = "E" then ' English to spanish
sql$ = "SELECT * FROM trans WHERE transTo = '";fromWord$;"' ORDER BY transTo"
else ' Spanish to english
sql$ = "SELECT * FROM trans WHERE transFrom = '";fromWord$;"' ORDER BY transFrom"
end if
#sql execute(sql$)
rows = #sql ROWCOUNT() 'Get the number of rows
gosub [shoResults]
if rows > 0 then gosub [shoTrans]
if from2$ = "E" then ' English to spanish
sql$ = "SELECT * FROM trans WHERE transTo like '";fromWord$;"%'
OR transTo like '% ";fromWord$;"%' ORDER BY transTo"
else ' Spanish to english
sql$ = "SELECT * FROM trans WHERE transFrom LIKE '";fromWord$;"%' ORDER BY transFrom"
end if
#sql execute(sql$)
rows = #sql ROWCOUNT() 'Get the number of rows
gosub [shoResults]
if rows > 0 then gosub [shoTrans]
if from2$ = "S" then
sndx$ = soundex$(fromWord$)
sql$ = "SELECT * FROM trans WHERE sndx = '";sndx$;"' ORDER BY transFrom"
#sql execute(sql$)
rows = #sql ROWCOUNT() 'Get the number of rows
gosub [shoResults]
if rows > 0 then gosub [shoTrans]
end if
goto [getWord]
' ----------------------------
' Show results of SQL search
' ----------------------------
[shoResults]
html "<HR>"
html bf1$;"Count: ";rows;" Search: ";word$(word$(sql$,2,"WHERE"),1,"ORDER")
RETURN
' -------------------------------------
' Show Translations
' -------------------------------------
[shoTrans]
html bf1$;"<TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0>"
html "<TR BGCOLOR=silver align=center>"
html "<TD>Spanish</TD>"
html "<TD>English</TD>"
html "<TD>Type</TD>"
html "<TD>Sndx</TD>"
html "</TR>"
rows = min(rows,maxList)
for i = 1 to rows
#row = #sql #nextrow()
transFrom$ = #row transFrom$()
transTo$ = #row transTo$()
type$ = #row type$()
sndx$ = #row sndx$()
html "<tr>"
html "<TD>";transFrom$;"</TD>"
html "<TD>";transTo$;"</TD>"
html "<TD>";type$;"</TD>"
html "<TD>";sndx$;"</TD>"
html "</TR>"
next i
html "</TABLE>"
return
' --------------------------------------------
' Create soundex
' --------------------------------------------
function soundex$(txt$)
soundex$ = "?" ' unknown soundex
maxSound = 4 ' max soundex length
' Make sure the word is at least two characters in length
If len(txt$) < 2 then goto [endf]
wrd$ = upper$(txt$)
' Convert the wrd$ to a character array for faster processing
dim chars$(len(wrd$))
for i = 1 to len(wrd$)
chars$(i) = mid$(wrd$,i,1)
next i
' Add the first character
soundex$ = chars$(1)
' Loop through all the characters and convert them to the proper character code
For i = 1 To len(wrd$)
if instr("HW",chars$(i)) then currCode = -1
if instr("AEIOUY",chars$(i)) then currCode = 0
if instr("BFPV",chars$(i)) then currCode = 1
if instr("CGJKQSXZ",chars$(i)) then currCode = 2
if instr("DT",chars$(i)) then currCode = 3
if chars$(i) = "L" then currCode = 4
if instr("MN",chars$(i)) then currCode = 5
if chars$(i) = "R" then currCode = 6
If i > 1 Then
' two letters With the same number separated by 'h' or 'w' are coded as a single number
If currCode = -1 Then currCode = prevCode
' Check to see if the current code is the same as the last one
If currCode <> prevCode Then
' Check to see if the current code is 0 (a vowel); do not proceed
If currCode <> 0 Then soundex$ = soundex$ + str$(currCode)
End If
end If
prevCode = currCode
' If the buffer size meets the length limit, then exit the loop
If len(soundex$) = maxSound Then goto [endf]
next i
' Pad the code with "0" if required
soundex$ = left$(soundex$ + "000",maxSound)
[endf]
End Function