Freebase's metaweb query language can be used to retreive future events if you pass in an ISO8601 formatted date.
[{
"id": null,
"name": null,
"start_date" : null,
"type": "/time/event",
"start_date>" : "2011-09-02"
}]
^ run this query
Does MQL support an equivalent to SQL's NOW() or CURDATE()?
You can also use __now__ in timestamp fields as a special shortcut:
[{
"id": null,
"name": null,
"start_date" : null,
"type": "/time/event",
"start_date>" : "__now__"
}]
You can see a live demo of this via this Freebase Query Editor snippet.
There is no equivalent to SQL's NOW() or CURDATE in MQL. Whichever programming language you're using to send the query should have an equivalent function which you can use.
You can kind of get a list of future events by sorting them in descending order of start_date like this:
[{
"id": null,
"name": null,
"type": "/time/event",
"start_date": {
"value": null,
"optional": false
},
"sort": "-start_date.value"
}]
Related
a complete beginner with freebase here, trying to understand how to make a query to find a /book/book by /book_edition/media_common/cataloged_instance/isbn13.
I tried this query and got this error: Type /book/book_edition does not have property media_common:
[{
"type": "/book/book",
"editions": [{
"media_common": [{
"cataloged_instance": [{
"isbn13": "9780812519112" //example isbn13 from ender's game - https://www.freebase.com/m/04v8gr6
}]
}]
}],
"id": null
}]
EDIT: this is the query I used to get the deprecated ISBN field on book_edition
[{
"type": "/book/book",
"editions": [{
"ISBN": "0312932081"
}],
"id": null
}]
The property is actually /media_common/cataloged_instance/isbn13 which you can discover by exploring the schema. Because it's from a different type than the expected type of /book/book/editions (which is /book/book_edition you need to use the fully qualified name. Ditto for the author property I added to the query below.
[{
"type": "/book/book",
"editions": [{
"/media_common/cataloged_instance/isbn13": "9780812519112"
}],
"id": null,
"name": null,
"/book/written_work/author": null
}]
without using the shorthand notation that allows us to drop type prefixes on property names, this query would look like:
[{
"/book/book/editions": [{
"/media_common/cataloged_instance/isbn13": "9780812519112"
}],
"/type/object/id": null,
"/type/object/name": null,
"/book/written_work/author": null
}]
The expansion of the property names to their fully qualified versions gets done mechanically by the query processor without any real knowledge of the schema. Conversely, graph traversal treats the property names as opaque strings.
I'd like to pull information (MID and US English name) about all locations in Freebase AND also their Korean names and any Korean aliases via an MQL query. This is as far as I've gotten:
[{
"id": null,
"name": null,
"mid": null,
"type": "/location/location",
"Korean:name": [{
"lang": "/lang/ko",
"value": null
}]
}]
I'm only getting the Korean name, but not any Korean aliases. I don't know how to write a query that outputs properties of 2 different types in the same query. Can you get data about both /location/location AND common/topic/alias for the same entity in the same MQL query/output? Is my approach just wrong here?
Any help appreciated.
When you need to combine properties from many different types you need to use the fully qualified property ID like this:
[{
"id": null,
"name": null,
"mid": null,
"type": "/location/location",
"Korean:name": [{
"lang": "/lang/ko",
"value": null
}],
"/common/topic/alias": [{
"lang": "/lang/ko",
"value": null,
"optional": true
}]
}]
Whenever you use shortened property IDs they are assumed to be in the same type as the type you specify in your query (or /type/object if no type is given). So for example, if you were to use "geolocation" in your query it would be interpreted as "/location/location/geolocation". The only excepts are "id", "name" and "type" which you can use without using the full IDs eg. "/type/object/name".
You'll also note that I made aliases "optional" so that it would return results for locations that don't have any aliases.
I'm new to Freebase mql querying and would like to get the /time/recurring_event/current_frequency for all awards (/award/award).
That query looks like this in MQL:
[{
"type": "/award/award",
"name": null,
"/time/recurring_event/current_frequency": [{
"id": null,
"name": null
}]
}]
In order to get all the results, you'll need to use a cursor to page through the results set.
Good day!
I want to obtain information about several disasters. So, I ask this query:
[{
"type": "/event/disaster",
"*": null,
"limit": 10
}]
Ok, but I also need /time/event properties such as start_date. I'm trying this:
[{
"type": "/event/disaster",
"type": "/time/event",
"*": null,
"limit": 10
}]
and again got only /event/disaster properties because type : time/event inherently translated to "ns0:type". I've tried also this:
[{
"type": ["/event/disaster", /time/event"],
"*": null,
"limit": 10
}]
but got error. How I should formulate the query?
The MQL property wildcard (*) can only be applied to one type so you'll need to individually list the properties that you want to see like this:
[{
"type": "/event/disaster",
"/time/event/start_date": null,
"*": null,
"limit": 10
}]
Another way to do this would be to use the Search API to specify which property values to return (by type or domain) like this:
?filter=(all type:/event/disaster)
&output=(all:/event/disaster all:/time/event)
Is it possible to do one query in MQL to obtain the name and the wikipedia ID for a certain language from Freebase? If that's possible, is it also possible to do this for a set of languages (eg. german & english)?
Asked and answered, but here's a slightly better form of the query:
[{
"id": "/en/white_house",
"mid": null,
"de:name": {
"lang": "/lang/de",
"value": null
},
"en:name": null,
"wiki_de:key": {
"/type/key/namespace": "/wikipedia/de_id",
"value": null,
"optional": True,
},
"wiki_en:key": {
"/type/key/namespace": "/wikipedia/en_id",
"value": null,
"optional": True,
}
}]
The Wikipedia keys will be escaped if they contain special characters, so you should consult
http://wiki.freebase.com/wiki/MQL_key_escaping for how to unescape them.
Some of the reasons this query is better include:
English is the default language, so it doesn't need to be specified for names
it removes the ambiguity of the namespace lookup. Your original query is actually looking for the key "white_house" in any namespace (and finding it in "/en" which is equivalent to the id "/en/white_house")
Note that you don't need to do the lookup by ID. You can use any lookup facility that MQL provides such as looking up by one of the Wikipedia keys or using "name~=":"white house" to find all topics containing that string or anything else that works for your starting data and your use case.
After playing around with MQL I finally came up with the following query (for white_house):
[{
"id": null,
"mid": null,
"de:name": {
"lang": "/lang/de",
"value": null
},
"en:name": {
"lang": "/lang/en",
"value": null
},
"key": {
"value": "white_house"
},
"wiki_de:key": {
"/type/key/namespace": "/wikipedia/de_id",
"value": null
},
"wiki_en:key": {
"/type/key/namespace": "/wikipedia/en_id",
"value": null
}
}]