|
Epzilon Newbie
Joined: 07 Nov 2005 Posts: 4
|
Posted: Mon Nov 07, 2005 11:47 pm
Translator (Database) |
Keep in mind, I'm rather new to this scripting.
I am currently populating a database with the drow language, along with the english translation (2 columns).
The way I had in mind for it to work is like this:
dsay Welcome. Nice to see you again.
'dsay' being an alias, of course, which should scan through the database for each word and replace it with the drow translation. If a translation can't be found, it should send the english word as written.
I haven't really studied the commands for DB, but I'm not quite sure either how to figure out how many words there are in the sentence for me to replace. |
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Tue Nov 08, 2005 12:40 am |
To figure out how many words are there, use %numwords():
%numwords("%-1") //divides words by spaces (two consecutive spaces counts as one word)
%numwords("%-1", "a") //divides words by the letter "a", "a tangled web we weave" = "", " t", ngled web we we", and "ve" for a total of 4 words |
|
_________________ EDIT: I didn't like my old signature |
|
|
|
Epzilon Newbie
Joined: 07 Nov 2005 Posts: 4
|
Posted: Tue Nov 08, 2005 6:49 am |
With you so far. But how can I process each word after that? I suppose I need some kind of loop, starting from 1 to whatever number is aquired from your example.
|
|
|
|
Kiasyn Apprentice
Joined: 05 Dec 2004 Posts: 196 Location: New Zealand
|
Posted: Tue Nov 08, 2005 9:03 am |
#forall %replace("%-1"," ","|") {dowhatever}
|
|
|
|
Epzilon Newbie
Joined: 07 Nov 2005 Posts: 4
|
Posted: Tue Nov 08, 2005 10:08 am |
I've fiddled around like crazy, with some progress but still not complete.
You'll probably laugh when you see this script, but hey, I use logic thinking with the commands and functions I'm familiar with :)
This is how my 'dsay' alias looks like.
Code: |
#VAR var_tempdrow ""
#VAR var_speakdrow ""
#FORALL %replace( "%-1", " ", "|") {
#VAR var_drowchar 0
#IF (%right( "%i", 1) = "!") {#VAR var_drowchar 1}
#IF (%right( "%i", 1) = ",") {#VAR var_drowchar 2}
#IF (%right( "%i", 1) = ".") {#VAR var_drowchar 3}
#IF (%right( "%i", 1) = "?") {#VAR var_drowchar 4}
#FORALL %replace( %replace( %replace( %replace( %find( "%i"), "!", ""), ",", ""), ".", ""), "?", "") {
#VAR var_tempdrow %db( %dbget( %i), "Drow")
#IF (%len( @var_tempdrow) > 0) {
#IF (@var_drowchar = 1) {#VAR var_tempdrow {@var_tempdrow "!"}}
#IF (@var_drowchar = 2) {#VAR var_tempdrow {@var_tempdrow ","}}
#IF (@var_drowchar = 3) {#VAR var_tempdrow {@var_tempdrow "."}}
#IF (@var_drowchar = 4) {#VAR var_tempdrow {@var_tempdrow "?"}}
#VAR var_speakdrow {@var_speakdrow @var_tempdrow}
} {#VAR var_speakdrow {@var_speakdrow "%i"}}
}
}
#say @var_speakdrow
|
So far this works with words only. If the sentence contains any of "! , . ?", then it doesn't work.
I also noticed that this doesn't perform an exact match search in the DB. How can I force that?
If a match is not found in the DB, I wish to keep the original word. This doesn't work either.
Ideas anyone? Ideas to simplify this script are also appreciated :) |
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Tue Nov 08, 2005 10:54 pm |
First idea is to eliminate the database and use just a record variable. This stores things in coordinated key-value pairs which is exactly what you need without the overhead of a full database. You can access the values of the pair by using the keys in either a dot-notation, with the %db function, or the #LOOPDB command.
Next is use %match and another variable. If you %match with a pattern of "(%w)%p" then translate and %remove the %w part, on your next loop you will find a match for just %p and can simply %concat that portion. This allows for a much wider range of punctuations and other symbol characters.
Finally after making the above adjustments you will want to change to a #WHILE loop. Your condition should be (@SourceVariable!=""). Personally though I never use #WHILE without including at least 2 conditions ((a!="")&(b>0)) or some such. This is because that second condition is something triggerable within the loop to indicate an error state. A throruoughly debugged script rarely errors but if you haven't included a reasonable error state you likely won't make it through debugging, and even if you do then unexpected inputs can cause problems. I definitely suggest including such a error state in a #WHILE loop. The further benefit of this is that an error can be reported in such a fashion that more of the input value is returned to the user. In your case that will help with debugging, #FORALL on the other hand will simply plow right through. It does mean a few extra variables to keep track of, but in this age of computers having 20GB of RAM yopu may as well make use of the smarter loop and add the variables. |
|
_________________ The only good questions are the ones we have never answered before.
Search the Forums |
|
|
|
Slaem Apprentice
Joined: 20 Sep 2005 Posts: 135
|
Posted: Wed Nov 09, 2005 4:37 am |
Has anyone given Vijilante any <3 yet?
|
|
|
|
Epzilon Newbie
Joined: 07 Nov 2005 Posts: 4
|
Posted: Wed Nov 09, 2005 4:54 pm |
Vijilante wrote: |
First idea is to eliminate the database and use just a record variable. This stores things in coordinated key-value pairs which is exactly what you need without the overhead of a full database. You can access the values of the pair by using the keys in either a dot-notation, with the %db function, or the #LOOPDB command.
Next is use %match and another variable. If you %match with a pattern of "(%w)%p" then translate and %remove the %w part, on your next loop you will find a match for just %p and can simply %concat that portion. This allows for a much wider range of punctuations and other symbol characters.
Finally after making the above adjustments you will want to change to a #WHILE loop. Your condition should be (@SourceVariable!=""). Personally though I never use #WHILE without including at least 2 conditions ((a!="")&(b>0)) or some such. This is because that second condition is something triggerable within the loop to indicate an error state. A throruoughly debugged script rarely errors but if you haven't included a reasonable error state you likely won't make it through debugging, and even if you do then unexpected inputs can cause problems. I definitely suggest including such a error state in a #WHILE loop. The further benefit of this is that an error can be reported in such a fashion that more of the input value is returned to the user. In your case that will help with debugging, #FORALL on the other hand will simply plow right through. It does mean a few extra variables to keep track of, but in this age of computers having 20GB of RAM yopu may as well make use of the smarter loop and add the variables. |
I'm reading up on the commands and functions you mentioned, but I'd appreciate a small example from scratch to a search, if you don't mind :) |
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Wed Nov 09, 2005 9:34 pm |
#CLASS DrowSpeech
#VARIABLE Translations {}
#VARIABLE tempDrow {} {}
#VARIABLE tempWord {} {}
#VARIABLE DrowSpeech {} {}
#VARIABLE PassCounter {0} {0}
#ALIAS drowSay {tempDrow="%-1";DrowSpeech="";PassCounter=%numwords(@tempDrow);#WHILE ((@PassCounter>0)&(@tempDrow!="")) {tempWord="";#CALL %regex(@tempDrow,"([a-zA-Z]*)\b?",tempWord);#IF (@tempWord) {#IF (%db(@Translations,@tempWord)) {DrowSpeech=%concat(@DrowSpeech,%db(@Translations,@tempWord));tempDrow=%remove(@tempWord,@tempDrow)} {DrowSpeech=%concat(@DrowSpeech,@tempWord);tempDrow=%remove(@tempWord,@tempDrow)}};#WHILE ((@tempDrow!="")&(%match(%left(@tempDrow,1),"%p")!=0)) {DrowSpeech=%concat(@DrowSpeech,%left(@tempDrow,1));tempDrow=%leftback(@tempDrow,1)};#ADD PassCounter -1};#IF (@tempDrow!="") {#ECHO Error with drowSay: DrowSpeech is @DrowSpeech, tempDrow is @tempDrow} {#SAY @DrowSpeech}}
#CLASS 0
That is off the top of my head. Hopefully no major errors. I used a combination of %regex and %match since regulard expression allow for matching a text that either contains or doesn't contain a punctuation. This was likely to happen at some point for the last word, so I thought it better to handle it from the start. |
|
_________________ The only good questions are the ones we have never answered before.
Search the Forums |
|
|
|
elbryan683 Newbie
Joined: 06 Oct 2006 Posts: 1 Location: VA
|
Posted: Fri Oct 06, 2006 5:03 am |
Heres a question. Im trying to input a translator to translate inputs into a RP language. for example drow. how do you go about doing that? and do you need some kind of pre-set database of words to do it?
|
|
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|