Example MQL

6 views
Skip to first unread message

Shug Boabby

unread,
Jul 14, 2008, 6:15:57 AM7/14/08
to Freebase Suggest
Hi all,

I think this project is awesome, but unfortunately I cannot use it in
my project as I'm not using Javascript. However, I'd very much like to
implement something similar... I am familiar with the Freebase API and
some of the MQL. I was wondering if you could please give an example
of the query that is sent to freebase for the "Actor with callback"
example on http://mqlx.com/freebase-suggest/examples/suggest_demo2.html

--
Shug

alecf

unread,
Jul 14, 2008, 12:11:31 PM7/14/08
to Freebase Suggest
Hey -
There are a number of libraries for calling the Freebase API, which
language are you working with? There is also complete documentation of
the APIs at http://www.freebase.com/view/freebase/api

One easy way to see the queries in action, even if you don't know/use
JavaScript is to download the "Firebug" extension for Firefox, which
lets you see the HTTP queries as they run. For example, typing "Drum"
into the Album box on that page runs this url:

http://www.freebase.com/api/service/search?callback=jsonp1216051732771&type=%2Fmusic%2Falbum&prefix=drum

which in turn yields this output (the 'callback' stuff is probably
inappropriate without JavaScript)

jsonp1216051732771({
"status": "200 OK",
"query": {
"domain": null,
"surrounds_strict": "any",
"type_strict": "all",
"surrounds": [],
"mql_filter": null,
"explain": false,
"blacklist": null,
"start": 0,
"prefix": "drum",
"limit": 20,
"escape": "html",
"query": "",
"type": [
"/music/album"
],
"strict": "all"
},
"code": "/api/status/ok",
"result": [
{
"name": "Drum",
"image": null,
"alias": [],
"article": null,
"guid": "#9202a8c04000641f800000000356ffcc",
"type": [
{
"id": "/music/album",
"name": "Musical Album"
},
{
"id": "/common/topic",
"name": "Topic"
}
],
"id": "/guid/9202a8c04000641f800000000356ffcc"
},
{
"name": "Tin Drum",
"image": {
"id": "/wikipedia/images/en_id/4629845"
},
"alias": [],
"article": {
"id": "/guid/9202a8c04000641f8000000000578517"
},
"guid": "#9202a8c04000641f8000000000578512",
"type": [
{
"id": "/music/album",
"name": "Musical Album"
},
{
"id": "/common/topic",
"name": "Topic"
}
],
"id": "/en/tin_drum"
},
{
"name": "Drum",
"image": null,
"alias": [],
"article": null,
"guid": "#9202a8c04000641f80000000032e5af1",
"type": [
{
"id": "/music/album",
"name": "Musical Album"
},
{
"id": "/common/topic",
"name": "Topic"
}
],
"id": "/guid/9202a8c04000641f80000000032e5af1"
},
{
"name": "Drum",
"image": {
"id": "/wikipedia/images/en_id/5709745"
},
"alias": [],
"article": {
"id": "/guid/9202a8c04000641f8000000000cee9b3"
},
"guid": "#9202a8c04000641f8000000000cee9ae",
"type": [
{
"id": "/common/topic",
"name": "Topic"
},
{
"id": "/music/album",
"name": "Musical Album"
},
{
"id": "/music/song",
"name": "Song"
},
{
"id": "/music/composition",
"name": "Composition"
}
],
"id": "/guid/9202a8c04000641f8000000000cee9ae"
},
{
"name": "Boss Drum",
"image": {
"id": "/wikipedia/images/en_id/2768501"
},
"alias": [
"Boss Drum"
],
"article": {
"id": "/guid/9202a8c04000641f800000000080c1d2"
},
"guid": "#9202a8c04000641f80000000031c32a0",
"type": [
{
"id": "/music/album",
"name": "Musical Album"
},
{
"id": "/common/topic",
"name": "Topic"
}
],
"id": "/en/boss_drum"
},
{
"name": "Strum & Drum!",
"image": null,
"alias": [],
"article": null,
"guid": "#9202a8c04000641f80000000038da432",
"type": [
{
"id": "/music/album",
"name": "Musical Album"
},
{
"id": "/common/topic",
"name": "Topic"
}
],
"id": "/guid/9202a8c04000641f80000000038da432"
},
{
"name": "Drum[a]",
"image": null,
"alias": [],
"article": null,
"guid": "#9202a8c04000641f800000000362a6f5",
"type": [
{
"id": "/music/album",
"name": "Musical Album"
},
{
"id": "/common/topic",
"name": "Topic"
}
],
"id": "/guid/9202a8c04000641f800000000362a6f5"
},
{
"name": "Drum-believable",
"image": {
"id": "/wikipedia/images/en_id/6928665"
},
"alias": [
"Drum-Believable"
],
"article": {
"id": "/guid/9202a8c04000641f8000000000ee381c"
},
"guid": "#9202a8c04000641f80000000032be07c",
"type": [
{
"id": "/music/album",
"name": "Musical Album"
},
{
"id": "/common/topic",
"name": "Topic"
}
],
"id": "/guid/9202a8c04000641f80000000032be07c"
},
{
"name": "Planet Drum",
"image": {
"id": "/wikipedia/images/en_id/14182213"
},
"alias": [],
"article": {
"id": "/guid/9202a8c04000641f8000000006be40e0"
},
"guid": "#9202a8c04000641f8000000006be40dc",
"type": [
{
"id": "/common/topic",
"name": "Topic"
},
{
"id": "/music/album",
"name": "Musical Album"
}
],
"id": "/guid/9202a8c04000641f8000000006be40dc"
},
{
"name": "Drum & Bass Arena",
"image": null,
"alias": [],
"article": null,
"guid": "#9202a8c04000641f8000000002e6690c",
"type": [
{
"id": "/music/album",
"name": "Musical Album"
},
{
"id": "/common/topic",
"name": "Topic"
}
],
"id": "/guid/9202a8c04000641f8000000002e6690c"
},
{
"name": "This Is... Drum & Bass",
"image": null,
"alias": [],
"article": null,
"guid": "#9202a8c04000641f8000000002e718b1",
"type": [
{
"id": "/music/album",
"name": "Musical Album"
},
{
"id": "/common/topic",
"name": "Topic"
}
],
"id": "/guid/9202a8c04000641f8000000002e718b1"
},
{
"name": "The Drum Battle",
"image": null,
"alias": [],
"article": null,
"guid": "#9202a8c04000641f800000000358b7c4",
"type": [
{
"id": "/music/album",
"name": "Musical Album"
},
{
"id": "/common/topic",
"name": "Topic"
}
],
"id": "/guid/9202a8c04000641f800000000358b7c4"
},
{
"name": "Ultimate Drum and Bass Album",
"image": null,
"alias": [],
"article": null,
"guid": "#9202a8c04000641f8000000002d7e59a",
"type": [
{
"id": "/music/album",
"name": "Musical Album"
},
{
"id": "/common/topic",
"name": "Topic"
}
],
"id": "/guid/9202a8c04000641f8000000002d7e59a"
},
{
"name": "Pure Drum & Bass",
"image": null,
"alias": [],
"article": null,
"guid": "#9202a8c04000641f8000000002ea3a63",
"type": [
{
"id": "/music/album",
"name": "Musical Album"
},
{
"id": "/common/topic",
"name": "Topic"
}
],
"id": "/guid/9202a8c04000641f8000000002ea3a63"
},
{
"name": "100% Drum & Bass",
"image": null,
"alias": [],
"article": null,
"guid": "#9202a8c04000641f8000000002f197a6",
"type": [
{
"id": "/music/album",
"name": "Musical Album"
},
{
"id": "/common/topic",
"name": "Topic"
}
],
"id": "/guid/9202a8c04000641f8000000002f197a6"
},
{
"name": "Eardrum",
"image": {
"id": "/wikipedia/images/en_id/14749551"
},
"alias": [],
"article": {
"id": "/guid/9202a8c04000641f8000000000c4ab69"
},
"guid": "#9202a8c04000641f8000000000c4ab64",
"type": [
{
"id": "/common/topic",
"name": "Topic"
},
{
"id": "/music/album",
"name": "Musical Album"
}
],
"id": "/guid/9202a8c04000641f8000000000c4ab64"
},
{
"name": "The World Of Drum & Bass",
"image": null,
"alias": [],
"article": null,
"guid": "#9202a8c04000641f8000000002f1fb2d",
"type": [
{
"id": "/music/album",
"name": "Musical Album"
},
{
"id": "/common/topic",
"name": "Topic"
}
],
"id": "/guid/9202a8c04000641f8000000002f1fb2d"
},
{
"name": "Dis Is da Drum",
"image": {
"id": "/wikipedia/images/en_id/8597629"
},
"alias": [
"Dis Is Da Drum"
],
"article": {
"id": "/guid/9202a8c04000641f800000000057731a"
},
"guid": "#9202a8c04000641f8000000003000f22",
"type": [
{
"id": "/music/album",
"name": "Musical Album"
},
{
"id": "/common/topic",
"name": "Topic"
}
],
"id": "/guid/9202a8c04000641f8000000003000f22"
},
{
"name": "Drum and Bass: The Collection",
"image": null,
"alias": [],
"article": null,
"guid": "#9202a8c04000641f8000000002d3da96",
"type": [
{
"id": "/music/album",
"name": "Musical Album"
},
{
"id": "/common/topic",
"name": "Topic"
}
],
"id": "/guid/9202a8c04000641f8000000002d3da96"
},
{
"name": "Drum and Bass Warfare",
"image": null,
"alias": [],
"article": null,
"guid": "#9202a8c04000641f8000000003276317",
"type": [
{
"id": "/music/album",
"name": "Musical Album"
},
{
"id": "/common/topic",
"name": "Topic"
}
],
"id": "/guid/9202a8c04000641f8000000003276317"
}
]
})

Shug Boabby

unread,
Jul 14, 2008, 12:45:09 PM7/14/08
to freebase...@googlegroups.com
Thanks for the reply. I actually dug into the source and worked out
the calls myself... I was confused how you were able to get the
article text and a thumbnail image (the Freebase docs on this are
*terrible*), but once I realised the "trans" calls I was able to piece
it together. I was also a little confused on how one could get a link
back to the wikipedia page, but thankfully somebody helped with that
on the freebase-developer list.

--
Shug

alecf

unread,
Jul 14, 2008, 12:55:31 PM7/14/08
to Freebase Suggest
Glad to hear you worked it out - the docs are being updated this
month, and
it would be great to hear more specific feedback - feel free to post
to the
developers list to tell the docs folks stuff like:

- what is missing
- what is confusing
- what is simply incorrect (hopefully not much :))
- how your overall experience went ("I expected stuff here, but found
it
here instead..." or "I needed a section explaining the connection
between...")

We want nothing more than to improve the docs :)

Alec

Shug Boabby

unread,
Jul 15, 2008, 7:31:56 AM7/15/08
to freebase...@googlegroups.com
Some feedback on the docs:-

# what is missing

how the ids/names etc relate to Wikipedia, IMDB or Freebase URLs. I
found it very difficult to work this out, and only discovered how to
do it by asking on this list (for wpid) or by playing around (by wp
key). For example, the examples tend to skip over what you can do with
the various ids once you have them.

I found the queryeditor to be very very useful, I'd suggest talking
about it a lot more instead of encouraging programmatic access in the
tutorials.

# what is confusing

the examples in PHP confuse me, because I am not a PHP coder and I
found this to be heavily language dependent. I was much more
interested in just the JDOM syntax and didn't need to be confused by
code boilerplate.

the entire Trans manual confused the hell out of me... I'd suggest you
start it with an example of obtaining an image id from a JDOM call and
then showing how to obtain the actual image through a simple browser
URL call. Similarly for other content.

# what is simply incorrect

Some out of date stuff such as the licence/cookie arrangement and the
need to escape quote marks in ~= searches.

But I found the docs to be quite good in general. Being a Sting fan
certainly helps ;-)

I have 2 RFEs, do I need to log them somewhere?

1 - When returning ranked results, it would be incredibly useful if
there was some score that measured the popularity of an entity. For
wikipedia articles I would imagine the "number of edits" would be a
good indicator... usage stats would be awesome ;-) I find the
Wikipedia ID to be a crude measure of popularity, as obviously the
more popular stuff was added early (although, due to the cultural bias
of the Wikipedia editors in the early days, this does have some really
weird side effects).

2 - It would be awesome to be able to send off a "fuzzy text match"
query. I tend to use combinations of "a:key~=" etc, but it would be
really really good to be able to basically do a search engine style
search across the keys that can perhaps do simple things like stemming
of words, removal of stop words, rearranging words, minor spelling
corrections, alternative words and arbitrary dropping of some words in
longer queries... like one would expect from a search bar. I believe
Apache Lucene does much of this. As a solid example, I would like it
if a search for "smashin pumpkins" [sic] would return "The Smashing
Pumpkins", or if a search for "The Queen of England" would include
"Elizabeth_II_of_the_United_Kingdom" along with
"Elizabeth_I_of_England".

Thanks for an absolutely incredible incredible resource! Making the
database available for download has finally given me the confidence to
be able to use your API... at least this way, I know I could attempt
to come up with a workaround if your server ever got as unreliable as
twitter ;-)

2008/7/14 alecf <alec...@gmail.com>:

Shug Boabby

unread,
Jul 15, 2008, 7:33:20 AM7/15/08
to freebase...@googlegroups.com
uuh, I guess that last comment should have gone to the freebase list,
sorry! :-) Apologies if you see a cross post soon.
Reply all
Reply to author
Forward
0 new messages