Freebase is the world's database that stores millions of topics (data entries), thousands of types of topics (e.g., from music albums to political campaigns), and another order of magnitude of properties (e.g., from duration of a music track to architect of a skyscraper). It is no doubt difficult to know how to query the data you want out of Freebase. This new version of the query editor provides you with a lot of help to do just that.
Freebase can be queried using MQL (Metaweb Query Language), which is a JSON-syntax query language.
Try the Query Editor!
The query editor can help you find topics, properties, and types wherever you need them inside your query. Put your text cursor where you want assistance and hit the Tab key.
| The query editor will suggest topics for you whenever you hit Tab after "id", "guid", or "name". The topics are restricted by the topic types of the current query node. If you hit Tab after "type", then the query editor will suggest topic types. | If your text cursor is located where a property should be found, then the query editor suggests properties available on the topic types of the current query node. (It also suggests properties of CVTs.) |
| The query editor also knows to suggest keywords (e.g., "optional") and their allowed values (e.g., "forbidden"). | For convenience, you can also hit Tab and auto-complete to common MQL constructs, such as [{ }]. |
The result panel on the right provides an interactive tree view (in addition to the bare text view).
|
When you hover over a topic id or guid in the tree view, you get a popup that shows some information about that topic. When you hover over the id or guid of an image, you get a small thumbnail popup. When you hover over the id or guid of an article, you get its blurb. Ids and guids in the tree view are also linked to their Freebase topic pages. Types (e.g., "/music/artist") are linked to their Freebase schema pages. |
Obviously, you can expand/collapse tree nodes. Additionally, you can flip through an array of results one element at a time by clicking on the corresponding "1-by-1" link, and then using the "next" and "previous" links. |
| MQL, which has JSON syntax, is not so hard to write, but sometimes you can make minor syntax mistakes that renders your query invalid. The query editor automatically tries to clean up such syntax errors behind the scene before running the query, so that you can still make mistakes, such as forgetting quotation marks and commas (illustrated in screenshot below), and your query still runs most of the time. | You can also tell the query editor to explicitly clean up your query by clicking the Clean Up button. It will quote unquoted strings and property names, insert missing commas, and remove trailing commas. (Tip: the keyboard shortcut Shift-Ctrl-Enter will clean up your query explicitly and then run it.) |
| We're experimenting with a few power tools that let you do advanced things more easily. One of these tools is the "turn inside out" tool, and it can be used as follows. Say, you have the query on the right: |
[{
"album": {
"artist": [],
"name": null, |
"id": null,
"release_date": null
},
"limit": 25,
"name": null,
"name~=": "Love*",
"type": "/music/track"
}]
| |
| As written, it will return an array of music tracks, within which nested are their albums. Instead, you want to get an array of albums within which nested are their tracks. Then, put your text cursor somewhere inside the "album" query node (such as where the red blinking bar is), and click the "Turn Inside Out" button in the Tools tab. You'll get this query on the right: |
[{
"artist": [],
"name": null,
"id": null,
"release_date": null,
"type": "/music/album",
"!/music/track/album": [{
"limit": 25,
"name": null,
"name~=": "Love*",
"type": "/music/track"
}]
}]
|
Another power tool is the tool for generating an ACRE template that would render the query into HTML. For example, given the query that has been turned inside out, clicking on "Generate ACRE Template" would give you this ACRE template code to copy into an ACRE Template file:
The template includes both the query call as well as the HTML rendering code, all in a single button click.
You can leave Javascript variables in your query and specify them in the Variables tab; they get resolved when the query is run.