16 | Real‐World Data |
A central feature of the Wolfram Language is that it’s got immense amounts of real-world data built in. It’s got data on countries and animals and movies, and lots more. It gets all this from the Wolfram Knowledgebase, which is being updated all the time—and is what powers Wolfram|Alpha and services based on it.
But how can you talk about a country in the Wolfram Language? The easiest way is just to use plain English. You can tell the Wolfram Language you’re going to be giving it plain English by pressing ctrl+= (hold down the Control key and press the = key), or on a touch device, by pressing the button.
In[{}]:=
Enter the plain English “united states”:
In[{}]:=
As soon as you press (or click away), the Wolfram Language will try to interpret what you typed. Assuming it succeeds, it’ll display a little yellow box that represents a Wolfram Language entity. In this case, it’s the entity corresponding to the United States.
In[{}]:=
Press the check mark to confirm that’s what you want:
In[{}]:=
Now you can ask for lots of properties of this entity. Like you could ask for the US flag.
Ask for the flag property of the United States:
In[1]:=
Out[1]=
The result you get is something you can go on doing computation with—like in this case image processing.
Color-negate the US flag:
In[2]:=
Out[2]=
In[3]:=
Out[3]=
EntityValue is a more flexible way to ask for the values of properties.
Use EntityValue to get the US flag:
In[4]:=
Out[4]=
EntityValue also works with lists of entities.
Get flags for a list of countries:
In[5]:=
Out[5]=
The Wolfram Language has deep knowledge about countries, as about many other things.
Find out how many radio stations there are in the list of countries:
In[6]:=
Out[6]=
Make a pie chart of the results:
In[7]:=
Out[7]=
In[8]:=
Out[8]=
Find their flags:
In[9]:=
Out[9]=
Sometimes you’ll want to talk about a class of entities—like, say, planets.
Ask for planets, and get the class of entities corresponding to planets:
In[10]:=
Out[10]=
Classes of entities are indicated by . You can get a list of all entities in a class using EntityList.
Get the list of planets:
In[11]:=
Out[11]=
Get images of all of the planets:
In[12]:=
Out[12]=
EntityValue can actually handle entity classes directly, so you don’t need to use EntityList with it.
Get the radius of each of the planets, and make a bar chart of them:
In[13]:=
Out[13]=
It’s very convenient to use plain English to describe things. But a downside is that it can be ambiguous. If you say “mercury”, do you mean the planet Mercury or the chemical element mercury or something else called “mercury”? When you use ctrl+=, it’ll always make an initial choice. But if you press the you can change to another choice. Press the check mark to accept a choice.
In[{}]:=
In[{}]:=
To see how the Wolfram Language internally represents entities you can use InputForm.
Show the internal form of the entity that represents the United States:
In[14]:=
Out[14]=
Show the internal form for New York City:
In[15]:=
Out[15]=
There are millions of entities in the Wolfram Language, each with a definite internal form. In principle you could enter any entity using its internal form. But unless you’re using the same entity over and over again, it’s much more practical just to use ctrl+= and enter a name for the entity in plain English.
There are thousands of different types of entities in the Wolfram Language, covering all sorts of areas of knowledge. To find out about them, check out the Wolfram Language documentation, or the Wolfram|Alpha examples pages. Each type of entity then has a list of properties—often hundreds of them. One way to find this list is to use EntityProperties.
In[16]:=
Out[16]=
In practice, though, a good approach is to ask in plain English for a property of some entity, then to look at the interpretation that’s found, and reuse the property from it.
Ask for the height of the Eiffel Tower:
In[{}]:=
In[17]:=
Out[17]=
Reuse the "Height" property, applied to the Great Pyramid:
In[18]:=
Out[18]=
Different types of entities have different properties. One common property for many types of entities is "Image".
Get images of various entities:
In[19]:=
Out[19]=
In[20]:=
Out[20]=
In[21]:=
Out[21]=
In[22]:=
Out[22]=
Other types of objects have other properties.
A plot of a caffeine molecule:
In[23]:=
Out[23]=
Rotatable 3D graphics of a skull:
In[24]:=
Out[24]=
In[25]:=
Out[25]=
You can use RandomEntity to find random entities of a given type.
5 random musical instruments:
In[27]:=
Out[27]=
Poster images for 5 random movies:
In[28]:=
In[28]:=
Production note for Todd: the ... looks off center
There’s a Missing in the list to indicate that a poster for one of the movies that was randomly picked wasn’t available in the Wolfram Knowledgebase. You can use DeleteMissing to get rid of Missing[...] elements in a list.
ctrl+= | plain English input | |
EntityList[class] | entities in a class | |
EntityValue[entities,property] | value of a property of an entity | |
EntityProperties[type] | list of properties for an entity type | |
RandomEntity[type,n] | a list of n random entities of a given type | |
InputForm[entity] | internal Wolfram Language representation of an entity |
16.1Find the flag of Switzerland. »
16.2Get an image of an elephant. »
16.4Make a bar chart of the masses of the planets. »
16.5Make an image collage of images of the planets. »
16.6Edge detect the flag of China. »
16.7Find the height of the Empire State Building. »
16.8Compute the height of the Empire State Building divided by the height of the Great Pyramid. »
16.9Compute the elevation of Mount Everest divided by the height of the Empire State Building. »
16.10Find the dominant colors in the painting The Starry Night. »
16.11Find the dominant colors in an image collage of the flag images of all countries in Europe. »
16.12Make a pie chart of the GDP of countries in Europe. »
16.13Add an image of a koala to an image of the Australian flag. »
+16.1Make an image collage of the flags of all countries in Europe, using the "FlagImage" property. »
+16.2Edge detect an image of the painting The Starry Night. »
+16.3Color negate the Mona Lisa painting. »
Where does the Wolfram Language get its real-world data?
It’s all from the central Wolfram Knowledgebase. We’ve been building this knowledgebase for many years, carefully curating data from thousands of primary sources.
Is the data in the Wolfram Language regularly updated?
Yes. We put a lot of effort into keeping it all up to date. And in fact there’s new data flowing in every second—about market prices, weather, earthquakes, aircraft positions and lots more.
How accurate is the data in the Wolfram Language?
We go to a lot of trouble to make it as accurate as possible, and we check it extensively. But ultimately we often have to rely on what governments and other outside organizations report.
What is the relation to Wolfram|Alpha?
Wolfram|Alpha uses the same knowledgebase as the Wolfram Language.
How should I ask for a particular entity?
However you want to. The Wolfram Language is set up to understand all common ways to refer to entities. (“New York City”, “NYC”, “the big apple”, etc., all work.)
How should I cite data that I get from the Wolfram Language?
Wolfram Knowledgebase (2023) (or whatever year you retrieve it). You can also link to the documentation for the entity type you’re using, such as https://reference.wolfram.com/language/ref/entity/Country.html.
How can I find all properties and values for a given entity?
Use entity["Dataset"] or entity["PropertyAssociation"]. You can also look up documentation about any type of entity in the Wolfram Language Documentation Center.
Most often it’s because the value needed simply isn’t available from any source that’s been curated for the Wolfram Knowledgebase. Sometimes it’s because the value doesn’t apply, like the boiling point of a chemical that decomposes but never boils.
Can I set up my own entities, and put in my own data about them?
Yes, using EntityStore.
- The Wolfram Knowledgebase is stored in the cloud, so even if you’re using a desktop version of the Wolfram Language, you’ll need to connect to the network to start getting real-world data.
- The Wolfram Knowledgebase contains many trillions of specific facts and values, stored in a Wolfram Language symbolic framework, with a variety of underlying database technologies.
- The Wolfram Knowledgebase has been systematically built and curated from large numbers of primary sources of data. It doesn’t come from web searching.
- Real-world data often involves units, which we’ll discuss in the next section.
- If you want to find more information about the original source of a particular piece of data, you can look at the documentation for that entity type, or you can ask for the data in Wolfram|Alpha and follow source links. You can find it programmatically using EntityValue[entity, property, "Source"].
- Sometimes you want to talk about a special instance of an entity, like a country in a particular year, or a certain amount of a substance. You can do this using constructs like Dated (discussed in Section 19) or EntityInstance.
- There’s a symmetry between entities and properties. entity[property] gives the same result as property[entity]. To get values of several properties, use entity[{p1, p2, ...}]; to get values for several entities, use property[{e1, e2, ...}]. (Note that for property[entity] you need the full property object, as obtained from ctrl+=, not just the name of the property as a string.)
- The Wolfram Language supports implicit entity classes such as “countries with more than 100 million people”. Access these using natural language, or using constructs like propertyGreaterThan[10^7], etc.