WolframAlpha是开发计算数学应用软件的沃尔夫勒姆研究公司开发出的新一代的搜索引擎,能根据问题直接给出答案的网站,于 2009年5月15日晚7点(美国中部当地时间,北京时间5月16日上午8点)提前上线,用户在搜索框键入需要查询的问题后,该搜索引擎将直接向用户返回答案,而不是返回一大堆网页链接。
需要注意的是:
Raspberry Pi默认是安装了Wolfram-engine
,当然只是在新的版本里。
新建一个queryprocess.py
#!/usr/bin/python
import wolframalpha
import sys
app_id='******-***********'
client = wolframalpha.Client(app_id)
query = ' '.join(sys.argv[1:])
res = client.query(query)
if len(res.pods) > 0:
texts = ""
pod = res.pods[1]
if pod.text:
texts = pod.text
else:
texts = "I have no answer for that"
# to skip ascii character in case of error
texts = texts.encode('ascii', 'ignore')
print texts
else:
print "Sorry, I am not sure."
上面的app_id
要到 http://products.wolframalpha.com/api/ 申请,申请很简单,当然如果你足够的懒的话,提供一个原作者的HYO4TL-A9QOUALOPX
。
接着让我们来几个简单的问答吧:
pi@raspberrypi ~ $ ./wolf.py "who are you"
My name is Wolfram|Alpha.
pi@raspberrypi ~ $ ./wolf.py "who is siri"
Siri is a personal assistant application for iOS. The application was first available from the App Store, then came standard on Apple's mobile devices starting with iPhone 4S. Siri uses natural language processing to answer questions and perform actions by delegating requests to an expanding set of web services, including Wolfram|Alpha.
pi@raspberrypi ~ $ ./wolf.py "who is cortana"
Sorry, I am not sure.
pi@raspberrypi ~ $ ./wolf.py "who is bill gates"
full name | William Henry Gates III
date of birth | Friday, October 28, 1955 (age: 58 years)
place of birth | Seattle, Washington, United States
pi@raspberrypi ~ $ ./wolf.py "do you sleep"
No, I can't.
(Can you?)
围观我的Github Idea墙, 也许,你会遇到心仪的项目