|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Translator
I wrote a little program, which translates a given sentence - word by word, but program is very slow as it looks in database (85.000+ words) for every word and gives result only after it finds the translation of every word. The code is like this,
Code:
begin
word3:='';
SerChar:=' ';
tnum:=1;
Memo1.Visible:=False;
RichEdit1.WordWrap:=False;
word1:=RichEdit1.Lines.Text+SerChar;
strlength:=Length(word1);
tend:=strlength;
while ((tnum <= 100) and (tend <> 0)) do
begin
tend:=Pos(SerChar,word1);
word5:='';
if tend <> 0 then
begin
word2:=Copy(word1,1,tend-1);
Table1.First;
while not Table1.Eof do
begin
if Table1.Fields[0].AsString=word2 then
word5:=Table1.Fields[1].AsString;
Table1.Next;
end;
delete(word1,1,tend);
if word5 <> '' then
word3:=word3+' '+word5
else word3:=word3+' '+word2;
StatusBar1.Panels[1].Text:='Words: '+IntToStr(tnum);
end
else word4:=word1;
inc(tnum);
end;
word3:=TrimLeft(word3);
RichEdit1.WordWrap:=True;
RichEdit2.Lines.Text:=word3;
end;
For ex. the sentence is 'Delphi rules forever'. Now I want the program look for the first word - delphi, and if it finds it in db, it must replace the new word with delphi, otherwise it will make the word 'delphi' underlined with red color and passes to the second word and goes like that till the end of sentence. Can anyone help me with that? Thanks. |
|
#2
|
||||
|
||||
|
Your method of searching data in the database is highly inefficient. No wonder it is taking a while to translate the data. Instead of going through the result set and searching for a match, it is faster to use the FindKey method of the TTable object to locate it. Note that FindKey() returns true if it finds the data or false if it doesn't. Also, put an index on the database table on the first field and this will increase your program speed tremendously.
__________________
Up the Irons What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home. "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest Down with Sharon Osbourne Puzzle of the Month solved by Keath and KevinADC, superior perl programmers of the month |
|
#3
|
|||
|
|||
|
I've put an index on the first field and noticed really big differences. It works greater than filter. Then I separated the sentence into words and added them to Memo1. Now I want to take the words from memo one by one and search them in a dictionary but program doesnt work. What's the problem supposed to be? Here is the code:
Code:
procedure TForm1.BitBtn1Click(Sender: TObject); Var soz: Array[1..1000] of String; temp: Array[1..1000] of String; a, i: Integer; begin For i:= 1 To Memo1.Lines.Count-1 Do Begin soz[i]:= Memo1.Lines.Text[i]; Table1.FindKey([soz[i]]); If Table1.FindKey([soz[i]]) Then temp[i]:= Table1.Fields.Fields[1].AsString else temp[i]:= 'UNKNOWN'; end; inc(i); Memo1.Lines.Clear; For a:= 1 To i Do Memo1.Lines.Add(temp[i]); end; It also reports that For-Loop variable 'i' may be undefined after loop. Waiting for your help.. |
|
#4
|
|||
|
|||
|
I've put an index on the first field and noticed really big differences. It works greater than filter. Then I separated the sentence into words and added them to Memo1. Now I want to take the words from memo one by one and search them in a dictionary but program doesnt work. What's the problem supposed to be? Here is the code:
Code:
procedure TForm1.BitBtn1Click(Sender: TObject); Var soz: Array[1..1000] of String; temp: Array[1..1000] of String; a, i: Integer; begin For i:= 1 To Memo1.Lines.Count-1 Do Begin soz[i]:= Memo1.Lines.Text[i]; Table1.FindKey([soz[i]]); If Table1.FindKey([soz[i]]) Then temp[i]:= Table1.Fields.Fields[1].AsString else temp[i]:= 'UNKNOWN'; end; inc(i); Memo1.Lines.Clear; For a:= 1 To i Do Memo1.Lines.Add(temp[i]); end; It also reports that For-Loop variable 'i' may be undefined after loop. Waiting for your help.. |
|
#5
|
|||
|
|||
|
Sorry for double post, can I use delimiter to separate a sentence word by word and add them to memo? If yes, then would U please give me an example of using it?
|
|
#6
|
|||
|
|||
|
How is Translator going ?
Hello ,
I am also trying to do something similar to you. Have you had any success yet ? Could you send me a copy of your project (delphi 5) to caruanar@acay.com.au thanks Richard Caruana |
|
#7
|
|||
|
|||
|
Hello
Why don't u join delphi.about.com?
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Delphi Programming > Translator |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|