golfram

package module
v0.0.0-...-7959ffb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 9, 2015 License: MIT Imports: 8 Imported by: 0

README

GOLFRAM

A Wolfram Alpha API lib wrote in go.

Installation

Simply Import "github.com/alexgirdler/golfram"

Example Usage

c := golfram.NewClient("APP-KEY", golfram.wolframDefaultURL)
result, err := c.NewQuery("plot sinx")
if err != nil {
  c.GetPlot(result, 0, "")
}

This example will query Wolfram Alpha with input "plot sinx" and will save the graph to "imgs/plot_sinx"(default save path, can be changed by passing path to the third argument in GetPlot)

Contributing

Please feel free to contribute simply checkout a feature branch commit your changes and open a pull request.

License

Copyright (c) 2015 Alex Girdler

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Documentation

Overview

Package golfram provides a go interface with the wolfram alpha api

Index

Constants

View Source
const (
	DefaultURL string = "http://api.wolframalpha.com/v2/query"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Assumption

type Assumption struct {
	Type     string   `xml:"type,attr"`
	Word     string   `xml:"word,attr"`
	Template string   `xml:"template,attr"`
	Values   []*Value `xml:"value"`
}

type Client

type Client struct {
	AppID      string
	Results    []*Queryresult
	WolframURL string
	// contains filtered or unexported fields
}

Client that connects to the wolfram api

func NewClient

func NewClient(appID string, wolframURL string) *Client

Constructs a new client given an api key Returns pointer to client

func (*Client) GetImage

func (c *Client) GetImage(result *Queryresult, title string, subpod int, filename string) (string, error)

Downloads image from subpod at given index of pod in given result with given title Most cases will want to use result.GetPlot instead

func (*Client) GetPlot

func (c *Client) GetPlot(result *Queryresult, index int, filename string) (string, error)

Downloads the plot from the given queryresult at the given index Most cases will want to use index of 0(e.q. c.GetPlot(result, 0) Returns path to saved plot image and error

func (*Client) NewQuery

func (c *Client) NewQuery(query string) (*Queryresult, error)

Constructs and sends a query to wolfram api from given string Returns pointer to query result and error.

type Img

type Img struct {
	Src    string `xml:"src,attr"`
	Width  string `xml:"width,attr"`
	Height string `xml:"height,attr"`
}

Image in subpod Src: Url of image

type Pod

type Pod struct {
	Error      string    `xml:"error,attr"`
	Id         string    `xml:"id,attr"`
	Title      string    `xml:"title,attr"`
	Numsubpods int       `xml:"numsubpods,attr"`
	Subpod     []*Subpod `xml:"subpod"`
}

Pod generated by wolfram for the query Contains subpods, and title of the pod

func (*Pod) String

func (p *Pod) String() string

type Queryresult

type Queryresult struct {
	Input       string
	Success     string `xml:"success,attr"`
	Error       string `xml:"error,attr"`
	Numpods     int    `xml:"numpods,attr"`
	Datatypes   string `xml:"datatypes,attr"`
	Pod         []*Pod `xml:"pod"`
	Podtitles   []string
	Assumptions []*Assumption `xml:"assumptions>assumption"`
	Sources     []*Source     `xml:"sources>source"`
}

Result of query Input: query string Success Error Datatypes: types of pods returned Pod[]: array of pods returned Podtitles[]: array of titles of pods(not to be used externally instead use result.GetPodByTitle(title)

func (*Queryresult) GenerateTitles

func (r *Queryresult) GenerateTitles() *Queryresult

Not to be used externally called when result is being unmarshalled in NewQuery Generates the Podtitles array of the Queryresult

func (*Queryresult) GetPodByTitle

func (r *Queryresult) GetPodByTitle(title string) (*Pod, error)

Returns pod with given title Used to find which pod contains plots

func (*Queryresult) String

func (r *Queryresult) String() string

type Source

type Source struct {
	Url  string `xml:"url,attr"`
	Text string `xml:"text,attr"`
}

type Subpod

type Subpod struct {
	Title     string `xml:"title,attr"`
	Plaintext string `xml:"plaintext"`
	Img       Img    `xml:"img"`
}

Subpod in pod Img: Image inside of subpod(if exists) Title: Title of subpod Plaintext: Plaintext response for subpod(if exists)

func (*Subpod) String

func (s *Subpod) String() string

type Value

type Value struct {
	Name  string `xml:"name,attr"`
	Desc  string `xml:"desc,attr"`
	Input string `xml:"input,attr"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL