Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/leopiccionia/lua-wolfram
A library for Wolfram|Alpha API.
https://github.com/leopiccionia/lua-wolfram
lua wolfram-alpha wolfram-alpha-api
Last synced: 10 days ago
JSON representation
A library for Wolfram|Alpha API.
- Host: GitHub
- URL: https://github.com/leopiccionia/lua-wolfram
- Owner: leopiccionia
- License: mit
- Created: 2017-07-14T17:14:34.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-06-06T21:12:49.000Z (over 5 years ago)
- Last Synced: 2023-02-26T19:42:11.252Z (almost 2 years ago)
- Topics: lua, wolfram-alpha, wolfram-alpha-api
- Language: Lua
- Size: 54.7 KB
- Stars: 8
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# lua-wolfram
**lua-wolfram** is an unofficial library for accessing plaintext results from [Wolfram|Alpha](https://www.wolframalpha.com), world's top computational knowledge engine.
## Installing
lua-wolfram is available in [LuaRocks](https://luarocks.org/modules/leopiccionia/lua-wolfram).
```
luarocks install lua-wolfram
```## How to use
The API requires an AppID, that can be obtained [here](https://products.wolframalpha.com/api/).
```lua
local WolframAlpha = require "wolfram"
local client = WolframAlpha("YOUR-API-KEY-HERE")local short_answer = assert(wolfram:query("What's the capital of USA?"))
local long_answer = assert(wolfram:full_query("square root of 2"))
```Method `query()` returns the the most immediate interpretation of the query, as a string:
```lua
"Washington, District of Columbia, United States"
```The method `full_query()`, on the other side, returns many views about the same query. It returns a table:
```lua
{
["Constant name"] = {
"Pythagora's constant"
},
["Continued fraction"] = {
"[1; 2^_]"
},
["All 2nd roots of 2"] = {
"sqrt(2)≈1.4142 (real, principal root)",
"-sqrt(2)≈-1.4142 (real root)"
},
["Input"] = {
"sqrt(2)"
},
["Decimal approximation"] = {
"1.414213562373095048801688724209698078569671875376948073176…"
}
}
```Please notice that subtables can contain both numerical and textual indexes (i.e. act as array, dictionary, or both).
## Examples
Please look at [examples](/examples) folder.