Author Topic: Q & A with wolframalpha and duckduckgo  (Read 13763 times)

0 Members and 3 Guests are viewing this topic.

Hellow

  • Contributor
  • ***
  • Posts: 50
  • Karma: 0
    • View Profile
Q & A with wolframalpha and duckduckgo
« on: December 31, 2013, 09:27:55 PM »
I have made a python script that uses a wolframalphas https://bitbucket.org/jaraco/wolframalpha and duckduckgos api https://pypi.python.org/pypi/duckduckgo2. The script first checks if wa has a answer (best solution), it not it uses duckduckgo, if that fails aswell vox tells your that is it couldnt find any answer to (Your question), Please rephrase.

I take no credit for making the python apis. All credit goes to the original authors. However you do need to download the files i provided, some are slightly changes in order to make it work with VC

1.Go register on the link below to get a apikey to wa (Please, do not use the one included. It's just for testing purpose)
https://developer.wolframalpha.com/portal/apisignup.html

2. Download duckduckgo.py and wolframalpha.py attached to the post. Move them to \plugins\PY\Lib

3. Download tellme.py and move it to \plugins\PY

4. Paste the group command to your lgb.

5. Do a full restart

6. Take it for a spin. Test it with, tell me "your question"

I have only tested with english

« Last Edit: February 06, 2014, 05:36:31 PM by Hellow »

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Q & A with wolframalpha and duckduckgo
« Reply #1 on: January 01, 2014, 11:08:24 AM »
Looks like a good start.  Unfortunately I get a lot of errors for questions that Wolfram should be able to answer.

Here is a snippet of my log.  As you can see the question is simply: 'what is the distance from montreal to New York', which I know Wolfram can answer.  Even if it can't I think it should be passing the question on to duck duck rather than failing on the error.

How much did you actually test this?  Did you try a variety of questions?

Code: [Select]
1/1/2014 10:03:52 AM 746 [action] PY.ExecString:tellme('what is the distance from montreal to New York')

1/1/2014 10:03:56 AM 585 [plugin] Python Error:IronPython.Runtime.UnboundLocalException: Local variable 'failed_answer' referenced before assignment.
   at IronPython.Runtime.Operations.PythonOps.CheckUninitialized(Object value, String name)
   at Microsoft.Scripting.Interpreter.FuncCallInstruction`3.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.Interpreter.HandleException(InterpretedFrame frame, Exception exception)
   at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
   at IronPython.Runtime.FunctionCaller`1.Call1(CallSite site, CodeContext context, Object func, T0 arg0)
   at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
   at Microsoft.Scripting.Interpreter.DynamicInstruction`4.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
   at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)
   at IronPython.Compiler.PythonScriptCode.Run(Scope scope)
   at IronPython.Compiler.RuntimeScriptCode.InvokeTarget(Scope scope)
   at IronPython.Compiler.RuntimeScriptCode.Run(Scope scope)
   at Microsoft.Scripting.Hosting.CompiledCode.Execute(ScriptScope scope)
   at vcPlugin.iPy.execString(String strCode)

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Q & A with wolframalpha and duckduckgo
« Reply #2 on: January 01, 2014, 11:14:24 AM »
FYI, The same question works fine with the non-python version that we previously posted to the forum:

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<command id="612" name="wolfram" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>Scrape</cmdType>
    <cmdString>http://api.wolframalpha.com/v2/query?appid=[yourAPIkey]&amp;input={1}&amp;format=plaintext</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.RegExSingle</cmdType>
    <cmdString>&lt;plaintext&gt;([^&lt;].*?)&lt;/plaintext&gt;</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <if ifBlockDisabled="False" ifNot="False">
    <ifType>LastActionSuccess</ifType>
    <ifParams>&amp;&amp;</ifParams>
    <then>
      <action>
        <cmdType>Results.MatchConcat</cmdType>
        <cmdString>{CR}&amp;&amp;3</cmdString>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>Results.Replace</cmdType>
        <cmdString>&amp;quot;&amp;&amp;"</cmdString>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>Results.Replace</cmdType>
        <cmdString>&amp;apos;&amp;&amp;'</cmdString>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>Results.Replace</cmdType>
        <cmdString> |</cmdString>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>OSD.ShowText</cmdType>
        <cmdString>{LastResult}</cmdString>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>TTS.Speak</cmdType>
        <cmdString>{LastResult}</cmdString>
        <cmdRepeat>1</cmdRepeat>
      </action>
    </then>
    <else>
      <action>
        <cmdType>TTS.Speak</cmdType>
        <cmdString>I'm sorry, I don't know the answer to: {1} Could you speak more clearly, or perhaps try to rephrase your question.</cmdString>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>OSD.ShowText</cmdType>
        <cmdString>I'm sorry, I don't know the answer to: {CR}{1}{CR}Could you speak more clearly, or perhaps try to rephrase your question.</cmdString>
        <cmdRepeat>1</cmdRepeat>
      </action>
    </else>
  </if>
  <phrase>Wolfram, Winklethorpe, Hey Jeeves, Dearie, Can you tell me</phrase>
  <payloadDictation>payloadDictation: Regular</payloadDictation>
</command>
« Last Edit: March 15, 2014, 08:36:42 AM by nime5ter »

Hellow

  • Contributor
  • ***
  • Posts: 50
  • Karma: 0
    • View Profile
Re: Q & A with wolframalpha and duckduckgo
« Reply #3 on: January 01, 2014, 11:58:43 AM »
I tested it alot, in cpython. the same question works with the same code in cpython(with print statements instead of voxcalls). This just makes me insane.. Ill see what i can do.
« Last Edit: January 01, 2014, 12:54:26 PM by jitterjames »

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Q & A with wolframalpha and duckduckgo
« Reply #4 on: January 01, 2014, 12:33:42 PM »
You can't define a variable in your 'try' block and then use it in the 'except' block.  The whole point of the code in the 'except' is that the 'try' failed so you can't assume that your variable was defined correctly.
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

Hellow

  • Contributor
  • ***
  • Posts: 50
  • Karma: 0
    • View Profile
Re: Q & A with wolframalpha and duckduckgo
« Reply #5 on: January 01, 2014, 04:25:38 PM »
Yeah, i saw that from the log. The problem seems to be with the answer, Action:  OSD.ShowText - Error:: Error('Syntax error at line 82: illegal character in content',)&&10000&&-10. The answer is encoded from wa as utf-8. <plaintext>5.403×10^7 cm  (centimeters)</plaintext>. The code works perfect in cpython. I have no ide how to fix this error. Only thing i can find is this http://support.microsoft.com/kb/238833
« Last Edit: January 01, 2014, 06:00:44 PM by Hellow »

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Q & A with wolframalpha and duckduckgo
« Reply #6 on: January 01, 2014, 05:52:25 PM »
The error has nothing to do with the TTS Action.  I believe it is being thrown based entirely on what is coming back from wolfram.  For some reason the wolframalpha.py is unable to process what it is getting back from wolfram.  It seems to have something to do with results that have numbers in them.

This simple code will throw the error :

Code: [Select]
import wolframalpha

def tellme(s=''):
    client = wolframalpha.Client('XXXXXX-XXXXXX')
    res = client.query(s)
    for p in res.pods:
        print p.text


tellme("what is 3 times 6")

The error occurs on the line:
Code: [Select]
res = client.query(s)Changing the question will result in either, getting a correct response, or getting an error on a different line number.  I think the line number actually refers to the line of text that is being returned by wolfram.

I have no idea how to fix it either.
« Last Edit: January 01, 2014, 05:55:15 PM by jitterjames »

Hellow

  • Contributor
  • ***
  • Posts: 50
  • Karma: 0
    • View Profile
Re: Q & A with wolframalpha and duckduckgo
« Reply #7 on: January 02, 2014, 05:12:54 AM »
I was editing the post at the same time as you wrote your. So far it seems that the parser has problems with × (u'00D7'). Ill see if i can replace it with x before document gets parsed.

Hellow

  • Contributor
  • ***
  • Posts: 50
  • Karma: 0
    • View Profile
Re: Q & A with wolframalpha and duckduckgo
« Reply #8 on: February 06, 2014, 05:40:56 PM »
The scripts now works thanks to Simon Opelt. It was a bug in ironpython, but he provided a workaround.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Q & A with wolframalpha and duckduckgo
« Reply #9 on: February 06, 2014, 11:09:55 PM »
Thanks, but, provided it where?


Etrust

  • Jr. Member
  • **
  • Posts: 45
  • Karma: 1
    • View Profile
Re: Q & A with wolframalpha and duckduckgo
« Reply #11 on: November 17, 2014, 02:49:01 PM »
Hi Guys,

I would like to use Wolframalpha in combination with voxcommand but I am a little bit confused..

I have allready an API Key and I would like to know the steps exactly to make wolframalpha work with voxcommand. The post from the author is old and I would like to know where I can find the steps to setup.

Can somebody help?

I am loving voxcommand. My wife can not hear my tests anymore :=)))))

Hellow

  • Contributor
  • ***
  • Posts: 50
  • Karma: 0
    • View Profile
Re: Q & A with wolframalpha and duckduckgo
« Reply #12 on: November 17, 2014, 02:55:13 PM »
Have you tried the step by step instruction? I posted?

Etrust

  • Jr. Member
  • **
  • Posts: 45
  • Karma: 1
    • View Profile
Re: Q & A with wolframalpha and duckduckgo
« Reply #13 on: November 18, 2014, 04:56:31 AM »
Have you tried the step by step instruction? I posted?

Hi Hellow!!

not yet because james have reported some errors and I was not sure if this is the latest versoin and tutorial  ;D

But if you can confirm that it will work using the version 2.1 than I will try ;D

Are you able to make questions and are you able to have the answer with TTS? Or have you a video on youtube?

Hellow

  • Contributor
  • ***
  • Posts: 50
  • Karma: 0
    • View Profile
Re: Q & A with wolframalpha and duckduckgo
« Reply #14 on: November 18, 2014, 05:01:02 AM »
Been a while since I have used it. But when it worked I could ask questions and get a reply from vox.
There is no video.