Delphi Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreDelphi Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 18th, 2004, 12:24 AM
Ruh Ruh is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 113 Ruh User rank is Private First Class (20 - 50 Reputation Level)Ruh User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Day 7 h 53 m 33 sec
Reputation Power: 5
Send a message via MSN to Ruh
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.

Reply With Quote
  #2  
Old August 19th, 2004, 05:26 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Click here for more information.
 
Join Date: Nov 2001
Location: Glendale, Los Angeles County, California, USA
Posts: 7,713 Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 3 Days 11 h 21 m 11 sec
Reputation Power: 1179
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

Reply With Quote
  #3  
Old August 24th, 2004, 02:05 AM
Ruh Ruh is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 113 Ruh User rank is Private First Class (20 - 50 Reputation Level)Ruh User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Day 7 h 53 m 33 sec
Reputation Power: 5
Send a message via MSN to Ruh
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..

Reply With Quote
  #4  
Old August 24th, 2004, 02:18 AM
Ruh Ruh is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 113 Ruh User rank is Private First Class (20 - 50 Reputation Level)Ruh User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Day 7 h 53 m 33 sec
Reputation Power: 5
Send a message via MSN to Ruh
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..

Reply With Quote
  #5  
Old August 24th, 2004, 02:25 AM
Ruh Ruh is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 113 Ruh User rank is Private First Class (20 - 50 Reputation Level)Ruh User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Day 7 h 53 m 33 sec
Reputation Power: 5
Send a message via MSN to Ruh
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?

Reply With Quote
  #6  
Old January 12th, 2005, 07:13 PM
blavatsky blavatsky is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 1 blavatsky User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #7  
Old January 28th, 2005, 11:39 AM
cool_keno cool_keno is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 9 cool_keno User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 35 m 20 sec
Reputation Power: 0
Hello

Why don't u join delphi.about.com?

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreDelphi Programming > Translator


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT