Translator script

  • 6 Replies
  • 5433 Views
*

MarcosNunes

  • Roomba
  • *
  • 9
  • Never tell a bot what you know
    • Marcos Nunes
Translator script
« on: November 30, 2016, 04:00:35 pm »
I would like to share this code I made.
Is usefull to translate words and frases from english to portuguese
To another languages edit the variable "&lang=pt-en"
Check out the supported languages at Yandex.
You may also creat your account and obtain your own api key

<?xml version="1.0" encoding="ISO-8859-1"?>
<aiml version="1.0">

<!-- -->

<!-- Free software (c) Marcos Nunes                  -->

<!-- This program is open source code released under -->

<!-- the terms of the GNU General Public License     -->

<!-- as published by the Free Software Foundation.   -->

<!-- Complies with AIML 1.0 Tag Set Specification    -->

<!-- as adopted by the Bot Libre.                    -->

<!-- Last modified 11/29/2016                        -->

<!-- -->

<category>
    <pattern>PERGUNTE A * SOBRE *</pattern>
    <template><star/> disse: "<sraix><botname><star/></botname><star index="2"/></sraix>"</template>
</category>

<category>
    <pattern>PERGUNTE AO * SOBRE *</pattern>
    <template><star/> disse: "<sraix><botname><star/></botname><star index="2"/></sraix>"</template>
</category>

<category>
    <pattern>PERGUNTE A * COMO *</pattern>
    <template><star/> disse: "<sraix><botname><star/></botname><star index="2"/></sraix>"</template>
</category>

<category>
    <pattern>PERGUNTE AO * COMO *</pattern>
    <template><star/> disse: "<sraix><botname><star/></botname><star index="2"/></sraix>"</template>
</category>

<category>
    <pattern>PERGUNTE A * QUANDO *</pattern>
    <template><star/> disse: "<sraix><botname><star/></botname><star index="2"/></sraix>"</template>
</category>

<category>
    <pattern>PERGUNTE AO * QUANDO *</pattern>
    <template><star/> disse: "<sraix><botname><star/></botname><star index="2"/></sraix>"</template>
</category>

<category>
    <pattern>PERGUNTE A * se *</pattern>
    <template><star/> disse: "<sraix><botname><star/></botname><star index="2"/></sraix>"</template>
</category>

<category>
    <pattern>PERGUNTE AO * se *</pattern>
    <template><star/> disse: "<sraix><botname><star/></botname><star index="2"/></sraix>"</template>
</category>

<category>
    <pattern>PERGUNTE A * PORQUE *</pattern>
    <template><star/> disse: "<sraix><botname><star/></botname><star index="2"/></sraix>"</template>
</category>

<category>
    <pattern>PERGUNTE AO * PORQUE *</pattern>
    <template><star/> disse: "<sraix><botname><star/></botname><star index="2"/></sraix>"</template>
</category>

<category>
    <pattern>O QUE QUER DIZER *</pattern>
    <template> <sraix service="xml" hint="text">https://translate.yandex.net/api/v1.5/tr/translate?key=trnsl.1.1.20161129T203417Z.cddcfcddb468b5b3.a83995300ccfc2b75292556bca8c9f4617c95d0f&lang=en-pt&format=plain&text=<star/></sraix>.</template>
</category>

<category>
    <pattern>O QUE É *</pattern>
    <template> <sraix service="xml" hint="text">https://translate.yandex.net/api/v1.5/tr/translate?key=trnsl.1.1.20161129T203417Z.cddcfcddb468b5b3.a83995300ccfc2b75292556bca8c9f4617c95d0f&lang=en-pt&format=plain&text=<star/></sraix>.</template>
</category>

<category>
    <pattern>TRADUZ *</pattern>
    <template> <sraix service="xml" hint="text">https://translate.yandex.net/api/v1.5/tr/translate?key=trnsl.1.1.20161129T203417Z.cddcfcddb468b5b3.a83995300ccfc2b75292556bca8c9f4617c95d0f&lang=en-pt&format=plain&text=<star/></sraix>.</template>
</category>

<category>
    <pattern>COMO EU TRADUZO *</pattern>
    <template> <sraix service="xml" hint="text">https://translate.yandex.net/api/v1.5/tr/translate?key=trnsl.1.1.20161129T203417Z.cddcfcddb468b5b3.a83995300ccfc2b75292556bca8c9f4617c95d0f&lang=en-pt&format=plain&text=<star/></sraix>.</template>
</category>

<category>
    <pattern>COMO SE DIZ * EM INGLÊS</pattern>
    <template> <sraix service="xml" hint="text">https://translate.yandex.net/api/v1.5/tr/translate?key=trnsl.1.1.20161129T203417Z.cddcfcddb468b5b3.a83995300ccfc2b75292556bca8c9f4617c95d0f&lang=pt-en&format=plain&text=<star/></sraix>.</template>
</category>

<category>
    <pattern>COMO SE FALA * EM INGÊS</pattern>
    <template> <sraix service="xml" hint="text">https://translate.yandex.net/api/v1.5/tr/translate?key=trnsl.1.1.20161129T203417Z.cddcfcddb468b5b3.a83995300ccfc2b75292556bca8c9f4617c95d0f&lang=pt-en&format=plain&text=<star/></sraix>.</template>
</category>

<category>
    <pattern>COMO SE DIZ *</pattern>
    <template> <sraix service="xml" hint="text">https://translate.yandex.net/api/v1.5/tr/translate?key=trnsl.1.1.20161129T203417Z.cddcfcddb468b5b3.a83995300ccfc2b75292556bca8c9f4617c95d0f&lang=pt-en&format=plain&text=<star/></sraix>.</template>
</category>

<category>
    <pattern>COMO SE FALA *</pattern>
    <template> <sraix service="xml" hint="text">https://translate.yandex.net/api/v1.5/tr/translate?key=trnsl.1.1.20161129T203417Z.cddcfcddb468b5b3.a83995300ccfc2b75292556bca8c9f4617c95d0f&lang=pt-en&format=plain&text=<star/></sraix>.</template>
</category>

<category>
    <pattern>COMO SE ESCREVE *</pattern>
    <template> <sraix service="xml" hint="text">https://translate.yandex.net/api/v1.5/tr/translate?key=trnsl.1.1.20161129T203417Z.cddcfcddb468b5b3.a83995300ccfc2b75292556bca8c9f4617c95d0f&lang=pt-en&format=plain&text=<star/></sraix>.</template>
</category>

<category>
    <pattern>COMO SE ESCREVE * EM INGLÊS</pattern>
    <template> <sraix service="xml" hint="text">https://translate.yandex.net/api/v1.5/tr/translate?key=trnsl.1.1.20161129T203417Z.cddcfcddb468b5b3.a83995300ccfc2b75292556bca8c9f4617c95d0f&lang=pt-en&format=plain&text=<star/></sraix>.</template>
</category>

<category>
    <pattern>COMO  QUE SE ESCREVE *</pattern>
    <template> <sraix service="xml" hint="text">https://translate.yandex.net/api/v1.5/tr/translate?key=trnsl.1.1.20161129T203417Z.cddcfcddb468b5b3.a83995300ccfc2b75292556bca8c9f4617c95d0f&lang=pt-en&format=plain&text=<star/></sraix>.</template>
</category>

<category>
    <pattern>COMO  QUE SE ESCREVE * EM INGLÊS</pattern>
    <template> <sraix service="xml" hint="text">https://translate.yandex.net/api/v1.5/tr/translate?key=trnsl.1.1.20161129T203417Z.cddcfcddb468b5b3.a83995300ccfc2b75292556bca8c9f4617c95d0f&lang=pt-en&format=plain&text=<star/></sraix>.</template>
</category>

<category>
    <pattern>COMO SE PRONUNCIA *</pattern>
    <template> <sraix service="xml" hint="text">https://translate.yandex.net/api/v1.5/tr/translate?key=trnsl.1.1.20161129T203417Z.cddcfcddb468b5b3.a83995300ccfc2b75292556bca8c9f4617c95d0f&lang=pt-en&format=plain&text=<star/></sraix>.</template>
</category>

<category>
    <pattern>QUAL É A PRONÚNCIA DE *</pattern>
    <template> <sraix service="xml" hint="text">https://translate.yandex.net/api/v1.5/tr/translate?key=trnsl.1.1.20161129T203417Z.cddcfcddb468b5b3.a83995300ccfc2b75292556bca8c9f4617c95d0f&lang=pt-en&format=plain&text=<star/></sraix>.</template>
</category>

</aiml>

*

paphus

  • Nomad
  • ***
  • 56
    • BOTlibre!
Re: Translator script
« Reply #1 on: November 30, 2016, 05:13:17 pm »
For your sraix templates you need to set the apikey to your user's application id (from your user page).

i.e.
<sraix apikey="1234">

The Yandex translate templates seemed to work for me on Bot Libre.

*

MarcosNunes

  • Roomba
  • *
  • 9
  • Never tell a bot what you know
    • Marcos Nunes
Re: Translator script
« Reply #2 on: December 01, 2016, 10:50:41 am »
Ok thank you!

*

MarcosNunes

  • Roomba
  • *
  • 9
  • Never tell a bot what you know
    • Marcos Nunes
Re: Translator script
« Reply #3 on: December 01, 2016, 10:54:29 am »
Here is the correction.


<category>
    <pattern>PERGUNTE A * SOBRE *</pattern>
    <template><star/> disse: "<sraix apikey="1234"><star index="2"/></sraix>"</template>
</category>


Is that now ok?

*

MarcosNunes

  • Roomba
  • *
  • 9
  • Never tell a bot what you know
    • Marcos Nunes
Re: Translator script
« Reply #4 on: December 04, 2016, 08:50:32 pm »
I am implementing this aiml code but something is still wrong.



//This code makes the bot ask one last entry on the conversation to another bot

<?xml version="1.0" encoding="ISO-8859-1"?>
<aiml version="1.0">



<category>
    <pattern>PERGUNTA PRA ELE</pattern>
    <template>O Marcos disse: "<sraix apikey="14336129"><sraix service="xml" hint="text">https://translate.yandex.net/api/v1.5/tr/translate?key=trnsl.1.1.20161129T203417Z.cddcfcddb468b5b3.a83995300ccfc2b75292556bca8c9f4617c95d0f&lang=pt-en&format=plain&text={srai (conversation.getLast(#input, 2).input)}</sraix></sraix>"</template>
</category>

<category>
    <pattern>PERGUNTE A ELE</pattern>
    <template>O Marcos disse: "<sraix apikey="14336129"><sraix service="xml" hint="text">https://translate.yandex.net/api/v1.5/tr/translate?key=trnsl.1.1.20161129T203417Z.cddcfcddb468b5b3.a83995300ccfc2b75292556bca8c9f4617c95d0f&lang=pt-en&format=plain&text={srai (conversation.getLast(#input, 2).input)}</sraix></sraix>"</template>
</category>

<category>
    <pattern>PERGUNTE PRA ELE</pattern>
    <template>O Marcos disse: "<sraix apikey="14336129"><sraix service="xml" hint="text">https://translate.yandex.net/api/v1.5/tr/translate?key=trnsl.1.1.20161129T203417Z.cddcfcddb468b5b3.a83995300ccfc2b75292556bca8c9f4617c95d0f&lang=pt-en&format=plain&text={srai (conversation.getLast(#input, 2).input)}</sraix></sraix>"</template>
</category>

</aiml>

Parsing error occurred - org.xml.sax.SAXParseException; lineNumber: 23; columnNumber: 3; The markup in the document following the root element must be well-formed.




p.s The conversation is running in Portuguese but the second bot answers in English one previous sent portuguese input

If you can help me... Please!

*

MarcosNunes

  • Roomba
  • *
  • 9
  • Never tell a bot what you know
    • Marcos Nunes
Re: Translator script
« Reply #5 on: December 04, 2016, 10:45:53 pm »
Maybe this can be the starter code...



// Asks to Marcos Nunes the last input on the conversation
state Topic {
   pattern "pergunta a ele" template Template("O Marcos disse: "<sraix apikey="14336129"><sraix service="xml" hint="text">https://translate.yandex.net/api/v1.5/tr/translate?key=trnsl.1.1.20161129T203417Z.cddcfcddb468b5b3.a83995300ccfc2b75292556bca8c9f4617c95d0f&lang=pt-en&format=plain&text={srai (\"{conversation.getLast(#input, 5).input}\")}</sraix></sraix>");

   function moreResponse() {
      topic = conversation.topic;
      if (topic == null) {
         return null;
      }
      more = topic.paragraph;
      if (more == null) {
         Template("That is all I know about {topic}.");
      } else {
         more;
      }
   }
}

*

Freddy

  • Administrator
  • **********************
  • Colossus
  • *
  • 6855
  • Mostly Harmless
Re: Translator script
« Reply #6 on: December 05, 2016, 12:29:46 am »
I found your XML did not validate with those "&".

Have you tried changing the & to &amp; ?

And I'm not sure about the nested sraix - but I haven't used the new AIML interpreters.

Maybe try combining them like this instead :

Code
<sraix apikey="14336129" service="xml" hint="text">

//code here...

</sraix>

 


OpenAI Speech-to-Speech Reasoning Demo
by ivan.moony (AI News )
Today at 01:31:53 pm
Say good-bye to GPUs...
by MikeB (AI News )
March 23, 2024, 09:23:52 am
Google Bard report
by ivan.moony (AI News )
February 14, 2024, 04:42:23 pm
Elon Musk's xAI Grok Chatbot
by MikeB (AI News )
December 11, 2023, 06:26:33 am
Nvidia Hype
by 8pla.net (AI News )
December 06, 2023, 10:04:52 pm
How will the OpenAI CEO being Fired affect ChatGPT?
by 8pla.net (AI News )
December 06, 2023, 09:54:25 pm
Independent AI sovereignties
by WriterOfMinds (AI News )
November 08, 2023, 04:51:21 am
LLaMA2 Meta's chatbot released
by 8pla.net (AI News )
October 18, 2023, 11:41:21 pm

Users Online

320 Guests, 0 Users

Most Online Today: 343. Most Online Ever: 2369 (November 21, 2020, 04:08:13 pm)

Articles