Author Topic: Siri like functionality i.e. ask your computer any question  (Read 17928 times)

0 Members and 1 Guest are viewing this topic.

Hellow

  • Contributor
  • ***
  • Posts: 50
  • Karma: 0
    • View Profile
Re: Siri like functionality i.e. ask your computer any question
« Reply #30 on: November 06, 2013, 06:20:07 AM »
I just found the python api, seems cool. I have to test this. https://pypi.python.org/pypi/duckduckgo2/0.2

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7713
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Siri like functionality i.e. ask your computer any question
« Reply #31 on: November 06, 2013, 10:10:44 AM »
https://duckduckgo.com/api

Quote
Our Instant Answer API gives you free access to many of our instant answers like: topic summaries (API example), categories (API example), disambiguation (API example), !bang redirects (API example), and definitions (API example).
This API does not include all of our links, however. That is, it is not a full search results API or a way to get DuckDuckGo results into your applications beyond our instant answers. Because of the way we generate our search results, we unfortunately do not have the rights to fully syndicate our results. For the same reason, we cannot allow framing our results without our branding. Please see our partnerships page for more info on guidelines and getting in touch with us.

Hellow

  • Contributor
  • ***
  • Posts: 50
  • Karma: 0
    • View Profile
Re: Siri like functionality i.e. ask your computer any question
« Reply #32 on: November 06, 2013, 12:43:45 PM »
https://duckduckgo.com/api


Yeah, i saw it. It still good regarding non abstract question. I tried to find a api for http://www.kgbanswers.com/ cus i think its awesoem, but i failed to find anything.

jb5349

  • Jr. Member
  • **
  • Posts: 46
  • Karma: 2
    • View Profile
Re: Siri like functionality i.e. ask your computer any question
« Reply #33 on: November 14, 2013, 01:51:27 AM »
Hello everyone,

I am new to this forum and VC but I did decide that tonight I would solve the issue of using Wolfram Alpha in VC. I have actually been working on an unofficial add-on or expansion to VC since I came across it which is designed to make it more human like. When I came across VoxCommando I was impressed to say the least at just how polished it is and loved the integration of plugins and logic.

So to get on with the original reason for this post. I have decided to provide the code and basic instructions for using Wolfram Alpha with your own system using some of the code I developed for the cloud based home automation "intelligence" platform I am working on. This is only the beginning as I also plan to expand the options to control a variety of "Internet of Things" that are currently available on the market today.

So it works and I will explain just how to use it right now in your own system.

1. You need a free Wolfram Alpha Developer ID.  Get one here if you don't have one already --> https://developer.wolframalpha.com/portal/apisignup.html
2. You need to enable the RoboBrowser Plugin (if it isn't already)
3. You will need a web host or server that runs PHP (or use your Windows PC running PHP and Apache. Use as http://localhost
3. You will need to copy and paste the code below into a new Command

Code: [Select]
<command id="393" name="General Test" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
            <action>
                <cmdType>RoboB.Select</cmdType>
                <cmdString>WolframAlpha</cmdString>
                <cmdRepeat>1</cmdRepeat>
            </action>
            <action>
                <cmdType>RoboB.Show</cmdType>
                <cmdString />
                <cmdRepeat>0</cmdRepeat>
            </action>
            <action>
                <cmdType>RoboB.Navigate</cmdType>
                <cmdString>http://YOUR_WEB_SERVER_HERE/wolfram.php?k=YOUR_ID_GOES_HERE&amp;t=4&amp;q={1}</cmdString>
                <cmdRepeat>1</cmdRepeat>
            </action>
            <action>
                <cmdType>RoboB.Wait</cmdType>
                <cmdString />
                <cmdRepeat>1</cmdRepeat>
            </action>
            <action>
                <cmdType>RoboB.ElementByID</cmdType>
                <cmdString>result</cmdString>
                <cmdRepeat>1</cmdRepeat>
            </action>
            <if ifBlockDisabled="False" ifNot="False">
                <ifType>LastActionSuccess</ifType>
                <ifParams>&amp;&amp;</ifParams>
                <then>
                    <action>
                        <cmdType>RoboB.GetText</cmdType>
                        <cmdString />
                        <cmdRepeat>1</cmdRepeat>
                    </action>
                    <action>
                        <cmdType>TTS.Speak</cmdType>
                        <cmdString>{LastResult}</cmdString>
                        <cmdRepeat>1</cmdRepeat>
                    </action>
                    <action>
                        <cmdType>VC.StopMacro</cmdType>
                        <cmdString />
                        <cmdRepeat>1</cmdRepeat>
                    </action>
                </then>
                <else>
                    <action>
                        <cmdType>TTS.Speak</cmdType>
                        <cmdString>I'm sorry, I don't understand</cmdString>
                        <cmdRepeat>1</cmdRepeat>
                    </action>
                </else>
            </if>
            <phrase>tell me, define, lookup</phrase>
            <payloadDictation>payloadDictation: Regular</payloadDictation>
        </command>

4. Next modify the URL to include your web host/server address and your own Wolfram Alpha Developer ID (Application ID)

Now for a quick breakdown of the URL:

k=YOUR_ID_GOES_HERE   (this part should be obvious but make sure the & is left after the ID)
t=4    (There are 4 settings, 1 = Result Only, 2 = Details Only, 3 = Notable Only, 4 = Result + Details + Notable) - You will need to use the robo getelementbyID and gettext options demonstrated in the example code to get the data you want, options are (result, detail, notable)

And yes, a short explanation on what these are.. 1. result is the short answer (i.e. if the question was "who was the first man on the moon" then result would be Neil Armstrong.  2. details are like the full persons name and their DOB and maybe some other details.  3. Notable is a summary of the persons achievements or what they are known for. This can also be the meat of the text response.

q={1}   ( this is the query string that comes from the dictation payload - note you can add static text before or after the {1} such as "who is " or "what is " if you want)

I have attached the PHP script you will need to this post. Feel free to modify it and improve upon it.

Just wanted to help solve one of these feature requests and make it future proof and easily updatable and now your system can be as smart as Wolfram Alpha. Remember you have up to 2,000 free requests per month with the developer ID so have fun with it! Let me know if you have any questions.

« Last Edit: November 14, 2013, 12:32:17 PM by jb5349 »

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2009
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Siri like functionality i.e. ask your computer any question
« Reply #34 on: November 14, 2013, 09:55:50 AM »
Hi jb5349, and welcome to the forum.

Thanks for pointing out that users can get their own API keys from Wolfram|A and use it for their own non-commercial purposes. That's a good point.

The problem for us was in offering a solution to our users that relied on a VoxCommando API key, but as jb says, anyone can easily sign up for their own non-commercial, free account on the W|A site.

Note, however, that if you do that, you can actually use Wolfram Alpha's server directly rather than posting your query through a third-party site.

For those of you keen to try out the WA "Siri-like" option, it's a pretty fun solution. Experienced VC users should have no problems making their own, custom commands using VoxCommando's usual tools. No expert programming skills are required -- all you need is a scrape action and some basic RegEx.

Of course, the same speech recognition caveat as always applies when relying on free dictation to pose your queries.

Here is what we've been using at home:

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>


The advantages for VC users of this type of command, rather than a RoboB version relying on a third-party server on top of Wolfram's would be:

  • Some people might not be comfortable providing their API key information to a third-party.
  • It eliminates an additional point of potential failure (e.g. if the third-party server is down) and it's also probably faster to directly query the Wolfram Alpha site.
  • There's more opportunity for users to customize their commands (i.e. extent of results retrieved, formatting, etc.)--not just phrasing.
  • As mentioned above, one can use the scrape action rather than having to use the RoboBrowser plugin. The RoboB plugin is a great tool when regular scraping is not an option, but straight-up scraping is faster/more efficient.

NOTE: If you use "Jarvis" as your regular VC prefix or for other commands, you'll want to delete that one from the command phrases in my code!

[Edit: Plain text doesn't actually mean plain text in the W|A api, so I've added a few punctuation catchers. You may want to add more in your own code. This could also be fixed more elegantly with some Python probably, for those who know how to do that. But this way works for all the non-coders out there.]
« Last Edit: November 14, 2013, 11:49:41 AM by nime5ter »
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)

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2009
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Siri like functionality i.e. ask your computer any question
« Reply #35 on: November 14, 2013, 10:51:03 AM »
I'd be curious how the W|A api works in non-English-speaking countries. I can't find any documentation about other supported languages on their site.

I tried entering a few very basic questions in French and German.

1. For «Quel heure est-il ? » it replied: "Wolfram|Alpha does not yet support French." But it did ask if I was asking what time it was, or whether I was interested in more information on "IL state". :-)

2. For «Comment allez-vous? » it replied: "Wolfram|Alpha doesn't understand your query."

3. For 'Wie geht es dir?' it interpreted the question correctly (Input interpretation > How are you?), and replied in English: "I am doing well, thank you."

4. For 'Wieviel Uhr ist es?', it oddly returned: "Wolfram|Alpha doesn't understand your query," but it interpreted the input correctly (Input interpretation > What time is it). And then gave me the time.

5. For 'Wie spät ist es?', it asked, "Did you mean: what time is it" -- But it did not try to give an answer.

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)

jb5349

  • Jr. Member
  • **
  • Posts: 46
  • Karma: 2
    • View Profile
Re: Siri like functionality i.e. ask your computer any question
« Reply #36 on: November 14, 2013, 12:41:25 PM »
Love the scrape function. Thanks for giving such a great example how to use it. I was having a hard time finding any documentation on it on the wiki site or this forum. How could you use this to separate out the simple response from the more detailed data? You don't always want every fact about something when you ask a question. I see the RegEx command seems to compile all of the plaintext data into one long string. How could this be separated out and used later.

For example.. I say "tell me who is George lucas" and lets say I just want the details section which should be full name and DOB, etc. and then I can follow up with... "tell me more.." and then it shows/speaks the rest of the data.  How can this be done?

Thanks!

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7713
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Siri like functionality i.e. ask your computer any question
« Reply #37 on: November 14, 2013, 12:48:01 PM »
You can do this by using different regex expressions (there are countless guides online that explain RegEx, but use ones that use C# syntax) and logic blocks, or you can use the python plugin if you want more fine grained control.

I usually start here when my regex gets rusty: http://www.mikesdotnetting.com/Article/46/CSharp-Regular-Expressions-Cheat-Sheet

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2009
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Siri like functionality i.e. ask your computer any question
« Reply #38 on: November 14, 2013, 01:11:54 PM »
Part of it is also that my command simply concatenates the first 3 matches into one response.

Match.1 is the W|A interpretation of the question. Match.2 is the primary response that you mentioned.

If you wanted to, you could concatenate the first 2 matches and store {Match.3} as a variable, which you can call later on request.

So, you could have VC initially respond with {Match.1} [the query as WA understood it] and {Match.2}, and then it can ask if you want to hear more.

Then you'd create a second command that requires confirmation, which would provide {Match.3} as stored in the variable you created. You can call it from the first command using the VC.TellVox action. This would be similar to what we do with the "Coming home from work" scenario or other 2-way conversation commands that you can find here on the forum.

And as James says, there's probably lots one can do with more elaborate regex and with Python code.
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)

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7713
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Siri like functionality i.e. ask your computer any question
« Reply #39 on: November 14, 2013, 01:29:18 PM »
or you could skip the whole tellvox / confirm thing and simply have a "tell me more" command which reads the contents of the "moreinfo" variable that holds the 3rd match.

If you used python, you could either do all the scraping in python directly, and use regex or beautiful soup, or whatever, or if you wanted to do the scrape and regex in VC you could then have a python script which requests the matches as a list of strings and do with them what you will.

From what I could see of your web based tool, it seemed like it was just returning the 2 and 3rd non-blank <plaintext/> items.

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2009
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Siri like functionality i.e. ask your computer any question
« Reply #40 on: November 14, 2013, 01:36:10 PM »
or you could skip the whole tellvox / confirm thing and simply have a "tell me more" command which reads the contents of the "moreinfo" variable that holds the 3rd match.

Right on. Good point!
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)

jb5349

  • Jr. Member
  • **
  • Posts: 46
  • Karma: 2
    • View Profile
Re: Siri like functionality i.e. ask your computer any question
« Reply #41 on: November 14, 2013, 02:22:45 PM »
Great thanks for the great information! Just a thought, could there be a place where other users share their commands/actions? Like some kind of exchange? Maybe a specific thread for this?

Also, what is the best way to send single HTTP requests using RESTful commands from VC? I can see opening a link in a web browser, but I don't want to see it open. I also have the same issue with getting data.  Is TCP the best option or should there be some other method used?

I have a wifi enabled thermostat that uses JSON formatted responses. I would like to query it and get the current temp and then send a command back to adjust it up or down. These are all HTTP requests directly to the IP address of the thermostat within my network. Any thoughts would be appreciated.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7713
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Siri like functionality i.e. ask your computer any question
« Reply #42 on: November 14, 2013, 02:34:25 PM »
Great thanks for the great information! Just a thought, could there be a place where other users share their commands/actions? Like some kind of exchange? Maybe a specific thread for this?
:biglaugh :biglaugh :biglaugh

Maybe explore the forum a tiny bit and you will see the board titled "xml exchange".

Also, what is the best way to send single HTTP requests using RESTful commands from VC? I can see opening a link in a web browser, but I don't want to see it open. I also have the same issue with getting data.  Is TCP the best option or should there be some other method used?

I have a wifi enabled thermostat that uses JSON formatted responses. I would like to query it and get the current temp and then send a command back to adjust it up or down. These are all HTTP requests directly to the IP address of the thermostat within my network. Any thoughts would be appreciated.

This is exactly what we are doing in the wolfram alpha command we just posted in this very thread, using scrape.  Scrape is useful any time you want to query any http server using an url and get parameters.  You can do what you want with the results that are returned.  Sometimes you can just ignore the results.  In the case of a json response, you can usually use regex to get info just as you would for an xml response.  There are no generic VC actions for dealing with json.  Again if you want to use the python plugin there are json libraries that you can leverage.

jb5349

  • Jr. Member
  • **
  • Posts: 46
  • Karma: 2
    • View Profile
Re: Siri like functionality i.e. ask your computer any question
« Reply #43 on: November 14, 2013, 02:45:27 PM »
Great, sorry I have not looked at the forum in much detail yet and missed that section.

I didn't realize that scrape could be used in that way but it makes sense. Thanks!

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7713
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Siri like functionality i.e. ask your computer any question
« Reply #44 on: November 14, 2013, 02:51:32 PM »
One thing that you can't do (yet) with scrape is send POST data.  In this case, I *THINK* you can use the TCP plugin, but I'm not 100% sure.  This is probably something I will add eventually but usually GET is all you need.  Worst case you can always use python.  It is pretty easy to find some code online for doing stuff like that in python.