# Data Formats in Wolfram|Alpha

## Introduction

In addition to its graphical results, Wolfram|Alpha can provide alternative representations that contain additional information or are well suited to particular tasks. These alternative representations are collectively referred to as data formats. Not all results have all these formats; indeed, it is difficult to conceive of a single result that could have all these representations. Therefore, there exist both interactive and programmatic mechanisms to determine and request the various formats.

There is a subgroup of the data formats known as "exposed data formats". Their purpose is to make it possible to extract useful data from Wolfram|Alpha. For example, the data points used to make a plot may be returned, allowing custom visualizations to be created. Some or all formatting, comments, and other extraneous details are omitted to focus on the data. The current exposed data formats, including a description of the elements extracted, are listed in the table below.

| |

| the data represented by the results, including numerical, textual, and mathematical elements. This format attempts to strip as much formatting as possible to make the result machine processible. This means Grid, Column, etc. are stripped; units are removed from quantities, leaving only the numeric portion; and dates are returned in the format of DateList. |

| the data represented by the results, including numerical, textual, and mathematical elements; it attempts to preserve the appearance of the result as much as possible, including the use of the special heads and |

| a list of mathematical and *Mathematica* expressions in the result, in held form |

| a list of singleton numbers and the numeric portion of singleton quantities in the result |

| a list of singleton quantities (numbers with units) in the result |

| a list of the sound objects appearing in the result |

| a list of time series appearing in the result |

Exposed data formats.

The other data formats are more specialized. Two provided

*Mathematica* forms, and are in fact used by the Free-form Input mechanism. The final one provides a plaintext representation of non-graphical elements in the results.

| |

| *Mathematica* expression to perform the computation that led to the result |

| an ordinary *Mathematica* expression representing the result |

| a plaintext representation of the result |

Additional data formats.

## Exploring Data Formats Interactively

Both Wolfram|Alpha Query and Free-form Input give you means to request the various data formats where available. Since Wolfram|Alpha Query shows all results by default, it is often a more convenient method for accessing these formats.

### Wolfram|Alpha Query

#### Basic Workflow

Consider the following input to a Wolfram|Alpha query.

integrate sinx from 0 to 2pi

There are two results generated. Each white area with a rounded gray border is referred to as a pod. Clicking on the plus sign in the upper-right corner of each pod provides a context menu for requesting that pod in various formats. For example, the "Definite integral" pod has a context menu that looks like this:

The first two items, and , are always available. The items after the first divider indicate that the pod contains , , and . Finally, after the second divider, the available exposed data formats are listed—in this case, , , and .

If you select from the context menu, a cell will be created right below the results of the Wolfram|Alpha Query just like the one below, which will automatically evaluate. The cell evaluates to the integral on the left-hand side of the equation, which is, indeed, the input given to Wolfram|Alpha.

Out[23]= | |

Repeating the process for produces the right-hand side of the equation or the output from the requested computation.

Out[24]= | |

Finally, produces a formula—the complete equation in standard

*Mathematica* syntax.

Out[30]= | |

Clicking on the plus sign for the "Visual representation of the integral" pod produces a much shorter menu. This pod has no available exposed data formats, and only of the other data formats:

As shown below, the Input for the pod is an ordinary

Plot expression to produce the graph. Allowing the

Plot expression to evaluate shows that there is no filling. It is often the case that the Input format is simplified relative to the result returned by Wolfram|Alpha, so you can apply your own styling.

Out[33]= | |

Out[34]= | |

#### Exposed Data Need Not Resemble the Graphical Result

In the above example, the exposed data looks essentially the same as the result. This is not always the case. Consider the following query.

msft close Jan 1, 2011 to Jan 21 2011

Clicking on the plus sign in the "History" pod and selecting produces the following. Instead of a plot, the actual data points used to create the plot are listed; the underlying data has been exposed.

Out[23]= | |

The

InputForm of the previous output contains the special formatting wrappers

and

. These heads, as well as the type of output to expect from exposed data formats, are discussed further in the section

Examples of Exposed Data.
Out[3]//InputForm= |

| |

#### The Structure of the Second Argument

It is worth noting the structure of the second argument to the

WolframAlpha function, which was generated by clicking the context menu:

. The

is a string created by Wolfram|Alpha to identify the pod, and

is the name of a property to extract. The

subpodid is an integer indicating the position of a particular result within the pod. All of the above examples had a single subpod within the pod so the index was always one. Here is an example of a query that produces multiple subpods per pod.

The thin gray line running with the width of the pod between the two plots is the tell-tale sign of multiple subpods. In this case, selecting from the "Plots" pod context menu produces two calls to

WolframAlpha, one for each subpod.

Out[6]= | |

This syntax can be extended to extract multiple formats from multiple pods, as explained below in the section

Obtaining Data Formats Programmatically.
### Free-form Input

Consider the first example of the previous subsection entered using Free-form Input. The first thing to notice is that the expression generated in the bottom half of the input cell is nothing other than the Input format discovered above. This is precisely how Free-form Input works: it searches for Input or Output expressions in the result from Wolfram|Alpha, and evaluates those expressions locally.

Out[102]= | |

Clicking on the plus sign to the right of the input reveals all the results. Because the Input format plays such a central rule in Free-form Input, the Input expressions, if any, for each result are displayed directly above the result in a gray box.

To access, for example, the

Computable data for the integral, right-click on it and select .

You can now paste the data anywhere you would like—for example, the cell below.

You can produce an input cell similar to how the context menu for Wolfram|Alpha Query works by selecting instead.

This will create, directly below the results, the following cell. However, unlike Wolfram|Alpha Query the cell will not automatically evaluate.

Out[42]= | |

## Obtaining Data Formats Programmatically

### Data Formats as Subpod Properties

The data formats are properties associated with particular subpods (as the above examples have made clear), although you can certainly request the data from all subpods or even the complete query simultaneously. The property names are strings obtained from the format names by camel casing each format name. Thus, becomes

, becomes

, and so forth.

### Determining Available Formats

The data formats available for a particular subpod are contained in the

property of each subpod. They can therefore be requested using the standard

and

syntaxes of the

WolframAlpha function.

Each subpod here only has a single data format, a plaintext version for the Input pod, and a

*Mathematica* Input form for the two Plot subpods.

Out[16]= | |

Each pod in this query has multiple data formats available, including multiple exposed data formats for the second and third pods.

Out[17]= | |

The list of formats returned by the

property can then be used in place of the string

to request the actual data.

Out[46]= | |

As is standard with the

WolframAlpha function, if you select a single property of a single subpod, only the value will be returned.

Out[47]= | |

### Requesting Data Directly

Rather than first determining which formats are available and then requesting them, you can also request the data formats directly. This is typically accomplished using the

syntax of the

WolframAlpha function, as illustrated below.

If you ask for certain properties of all pods, only pods that actually contain those formats will appear.

Out[92]= | |

Out[93]= | |

You can also request all properties of a particular pod, then select particular results as desired. Again, only properties that are actually available will appear.

Out[96]= | |

Finally, you can request particular formats from a particular subpod. In this case (when there is no

All in the specification), if a particular format is not available, you will still get a rule for it with the right-hand side of

Missing.

Out[88]= | |

Note that if you give only a pod ID without a subpod, you have an implicit

All requesting all subpods.

Out[97]= | |

If you are interested in the exposed data, the

format of

WolframAlpha will return all available exposed data, in the normal

form. Using

ensures that if new exposed data formats are added, they will be listed as well.

Out[98]= | |

The

and

formats of

WolframAlpha can be easily reproduced using the

syntax of

WolframAlpha.

is the right-hand side of the rules returned by

{All, "PodPlaintext"}.

Out[103]= | |

Out[104]= | |

is the right-hand side of the rules returned by

{All, {"Input", "Output"}}.

Out[105]= | |

Out[106]= | |

## Examples of Exposed Data

### General Notes

Not all Wolfram|Alpha results have data format representations, much less any exposed data, although its results are being refined to provide data formats all the time. Also, when there are multiple exposed data formats available, there are cases where two or even three of the formats coincide. This is all dependent on the contents of the individual pods. Generally speaking, computable data and formatted data are the most general; they are typically present if any exposed data is present, and they may contain heterogeneous data. The other formats seek to drill down and provide specific elements types of data and are therefore much more predictable. The examples below are organized according to the types of data that they contain.

### Quantities and Numbers

Quantities in Wolfram|Alpha are either pure numbers or numbers together with units. The first pod from the financial example above provides a nice illustration of how these are handled in exposed data.

Out[21]= | |

Formatted data and computable data give different takes on the entire result.

The formatted data looks almost exactly like the output. The date annotations have been stripped, the grid dividers are gone, and the display of quantities has been standardized to number-unit, but otherwise the differences are minimal. As noted in the introduction, the stripping of formatting and extraneous details is quite deliberate. As further detailed in the quantity data example below, the second column consists of

objects.

Out[24]= | |

By contrast, the computable data is significantly simplified. Instead of a

Grid, it returns a plain matrix; also, only the numeric part of the quantity is returned so that the numbers may be passed to additional functions without further processing.

Out[28]= | |

On the other hand, Quantity data and Number data will zoom in only on the quantitative part of the result, ignoring the text. Their relationship is quite similar to the relationship between Formatted data and Computable data.

Number data returns only pure numbers and the numeric portion of quantities (as is the case here).

Out[29]= | |

Quantity data returns only quantities. It uses the

wrapper to pass along additional information, such as the unit and precision, as does formatted data.

Out[26]= | |

Out[30]//InputForm= |

| |

### Time Series

History plots are the prototypical example of time series, which give a

-value for each in a series of dates. The following is the history plot seen above.

Out[31]= | |

As seen above, the formatted data contains a table of values, complete with headings indicating the unit for the

-values. The comment, as per usual, has been removed. The dates in the first column use the

wrapper, but the

InputForm below shows they each contain an ordinary

DateList.

Out[33]= | |

Out[107]//InputForm= |

| |

Computable data returns the time series in the standard

*Mathematica* format for time series: a list of pairs whose first element is a

DateList and second element is a numeric value.

Out[34]= | |

In this case, the time series data is identical to the computable data because the entire result consisted of the plot. If there were additional elements in the result, the time series data might be a strict subset.

Out[32]= | |

Notice that there is no number data in this pod. Even though many numbers appear in the data, there are no numbers that stand on their own as results. This is quite different from the table in the previous example, where 19.83 was the volatility (in percent).

Out[12]= | |

### Formulas

The introductory examples in

"Exploring Data Formats Interactively" showed how formula data can return a single equation. It can, however, also return multiple equations, which the "Equation" pod of the query does below.

Newton's second law 5 kg 2 gs

The formatted data in this case is, again, very similar to the result returned by Wolfram|Alpha. However, several formulas have been identified and wrapped in

Hold.

Out[8]= | |

Formula data will return only the formulas, in a flat list, ignoring the textual elements.

Out[36]= | |

### Sounds

The pulsar LGM-1 has many interesting properties known to Wolfram|Alpha. One of these is an audio schematic of its pulsing.

For this particular pod, the only exposed data is Sound data; this format is the one most likely to appear without a corresponding formatted data or computable data.

Sound data produces a normal

Sound object.

Particularly interesting in this case is the

InputForm of the sound returned. The

SampledSoundFunction produced by Wolfram|Alpha is transmitted losslessly into

*Mathematica*.

Out[5]//InputForm= |

| |

Wolfram|Alpha can produce music in addition to sampled sounds.

Again, such sounds can be imported into

*Mathematica* with no loss.

Out[11]//InputForm= |

| |