Step by step MQL with Jimi Hendrix
How to extract all the data on a Freebase topic
Let's say that we're building an app that displays interesting info on any Freebase topic. We don't know in advance which topics the user will view so we have to write general queries.- The first section deals with standard queries. We show how to extract all the info about Jimi Hendrix from Freebase but this requires n+1 queries (one to get his types and then one per type).
- In the section on "Reflection" we show how this can be acheived in one query using advanced features of MQL.
Standard Queries
We start from the beginning using very basic MQL.Where's Jimi?
First we search Freebase for topics called Jimi Hendrix:
- multiple records
{
"query":[{
"id":null,
"type":[],
"name":"Jimi Hendrix"
}]
}
Response:
{
"code":"/api/status/ok",
"result":[{
"id":"#9202a8c04000641f8000000000020d94",
"name":"Jimi Hendrix",
"type":["/music/guitarist","/music/artist","/common/topic","/people/person","/music/group_member","/people/deceased_person"]
},{
"id":"#9202a8c04000641f80000000017bc040",
"name":"Jimi Hendrix",
"type":["/music/track"]
},{
"id":"#9202a8c04000641f8000000001dcec17",
"name":"Jimi Hendrix",
"type":["/music/track"]
},{
"id":"#9202a8c04000641f8000000002c48872",
"name":"Jimi Hendrix",
"type":["/music/track"]
},{
"id":"#9202a8c04000641f8000000002f5e287",
"name":"Jimi Hendrix",
"type":["/music/album","/common/topic"]
},{
"id":"#9202a8c04000641f8000000002f5e441",
"name":"Jimi Hendrix",
"type":["/music/album","/common/topic"]
},{
"id":"#9202a8c04000641f80000000044b15fd",
"name":"Jimi Hendrix",
"type":["/music/track"]
}]
}
Use
id, that's unique
{
"query":{
"*":null,
"id":"#9202a8c04000641f8000000000020d94"
}
}
"*":null expands to /common/topic properties:
{
"code":"/api/status/ok",
"result":{
"creator":"/user/metaweb",
"guid":"#9202a8c04000641f8000000000020d94",
"id":"#9202a8c04000641f8000000000020d94",
"key":["16095","Jimi_Hendrix","Jimmy_hendrix","Jimmi_Hendrix","Al_Hendrix","Live_at_Berkely","James_Marshall_Hendrix","James_Hendrix","Jim_Hendrix","Hendrix","Room_full_of_mirrors","06fb1c8b-566e-4cb2-985b-b467c90781d4","ARTIST184","Jimi_hendrix","Jimmy_Hendrix","Johnny_Allen_Hendrix"],
"name":"Jimi Hendrix",
"permission":"/boot/all_permission",
"timestamp":"2006-10-22T09:07:37.0017Z",
"type":["/music/guitarist","/music/artist","/common/topic","/people/person",
"/music/group_member","/people/deceased_person"]
}
}
What does this all mean?
TODO: go through each entry TODO:guidv id? key? permission?
snip key, highlight new stuff
Why is there so little info about Jimi?
All we are seeing is the Common Object Properties But if we specify the type then the"*":null will expand to all of the properties of that type:
Jimi as a guitarist
Let's take the first type
{
"query":{
"*":null,
"id":"#9202a8c04000641f8000000000020d94",
"type":"/music/guitarist"
}
}
Which gives:
{
"code":"/api/status/ok",
"result":{
"creator":"/user/metaweb",
"guid":"#9202a8c04000641f8000000000020d94",
"guitars_played":["Fender Stratocaster"],
"id":"#9202a8c04000641f8000000000020d94",
"key":["16095","Jimi_Hendrix","Jimmy_hendrix","Jimmi_Hendrix","Al_Hendrix","Live_at_Berkely","James_Marshall_Hendrix","James_Hendrix","Jim_Hendrix","Hendrix","Room_full_of_mirrors","06fb1c8b-566e-4cb2-985b-b467c90781d4","ARTIST184","Jimi_hendrix","Jimmy_Hendrix","Johnny_Allen_Hendrix"],
"name":"Jimi Hendrix",
"permission":"/boot/all_permission",
"timestamp":"2006-10-22T09:07:37.0017Z",
"type":"/music/guitarist"
}
}
Let's try "*":[]
{
"query":{
"*":[],
"id":"#9202a8c04000641f8000000000020d94",
"type":"/music/guitarist"
}
}
{
"code":"/api/status/ok",
"result":{
"creator":["/user/metaweb"],
"guid":["#9202a8c04000641f8000000000020d94"],
"guitars_played":["Fender Stratocaster"],
"id":"#9202a8c04000641f8000000000020d94",
"key":["16095","Jimi_Hendrix","Jimmy_hendrix","Jimmi_Hendrix","Al_Hendrix","Live_at_Berkely","James_Marshall_Hendrix","James_Hendrix","Jim_Hendrix","Hendrix","Room_full_of_mirrors","06fb1c8b-566e-4cb2-985b-b467c90781d4","ARTIST184","Jimi_hendrix","Jimmy_Hendrix","Johnny_Allen_Hendrix"],
"name":["Jimi Hendrix"],
"permission":["/boot/all_permission"],
"timestamp":["2006-10-22T09:07:37.0017Z"],
"type":"/music/guitarist"
}
}
"*":null magically switches between single values and array values.
So we won't use "*":[] for now.
Let's try "*":{}
{
"query":{
"*":{},
"id":"#9202a8c04000641f8000000000020d94",
"type":"/music/guitarist"
}
}
{
"code":"/api/status/error",
"messages":[{
"code":"/api/status/error/mql/result",
"info":{
"count":6,
"result":[{
"lang":"#9202a8c04000641f8000000000003b42",
"type":"/type/text",
"value":"Jimi Hendrix"
},{
"lang":"#9202a8c04000641f8000000000000092",
"type":"/type/text",
"value":"Jimi Hendrix"
},{
"lang":"#9202a8c04000641f8000000000003b2e",
"type":"/type/text",
"value":"Jimi Hendrix"
},{
"lang":"#9202a8c04000641f8000000000003b4c",
"type":"/type/text",
"value":"Jimi Hendrix"
},{
"lang":"#9202a8c04000641f8000000000003b56",
"type":"/type/text",
"value":"ジミ・ヘンドリックス"
},{
"lang":"#9202a8c04000641f8000000000003b38",
"type":"/type/text",
"value":"Jimi Hendrix"
}]
},
"message":"Unique query may have at most one result. Got 6",
"path":"name",
"query":{
"*":{
"error_inside":"."
},
"id":"#9202a8c04000641f8000000000020d94",
"type":"/music/guitarist"
}
}]
}
What went wrong?
"*":{} expands each property into a single object. The error message is complaining that property name has 6 values.
Solving the problem, use an array of objects - "*":[{}]
{
"query":{
"*":[{}],
"id":"#9202a8c04000641f8000000000020d94",
"type":"/music/guitarist"
}
}
{
"code":"/api/status/ok",
"result":{
"creator":[{
"id":"/user/metaweb",
"name":"Metaweb",
"type":["/type/user"]
}],
"guid":[{
"type":"/type/id",
"value":"#9202a8c04000641f8000000000020d94"
}],
"guitars_played":[{
"id":"#9202a8c04000641f800000000029a0e3",
"name":"Fender Stratocaster",
"type":["/common/topic","/music/guitar","/music/instrument"]
}],
"id":"#9202a8c04000641f8000000000020d94",
"key":[{
"namespace":"/wikipedia/en_id",
"type":"/type/key",
"value":"16095"
},{
"namespace":"/wikipedia/en",
"type":"/type/key",
"value":"Jimi_Hendrix"
},{
"namespace":"/wikipedia/en",
"type":"/type/key",
"value":"Jimmy_hendrix"
},{
"namespace":"/wikipedia/en",
"type":"/type/key",
"value":"Jimmi_Hendrix"
},{
"namespace":"/wikipedia/en",
"type":"/type/key",
"value":"Al_Hendrix"
},{
"namespace":"/wikipedia/en",
"type":"/type/key",
"value":"Live_at_Berkely"
},{
"namespace":"/wikipedia/en",
"type":"/type/key",
"value":"James_Marshall_Hendrix"
},{
"namespace":"/wikipedia/en",
"type":"/type/key",
"value":"James_Hendrix"
},{
"namespace":"/wikipedia/en",
"type":"/type/key",
"value":"Jim_Hendrix"
},{
"namespace":"/wikipedia/en",
"type":"/type/key",
"value":"Hendrix"
},{
"namespace":"/wikipedia/en",
"type":"/type/key",
"value":"Room_full_of_mirrors"
},{
"namespace":"/user/metaweb/datasource/MusicBrainz",
"type":"/type/key",
"value":"06fb1c8b-566e-4cb2-985b-b467c90781d4"
},{
"namespace":"/user/metaweb/datasource/MusicBrainz/name",
"type":"/type/key",
"value":"ARTIST184"
},{
"namespace":"/wikipedia/en",
"type":"/type/key",
"value":"Jimi_hendrix"
},{
"namespace":"/wikipedia/en",
"type":"/type/key",
"value":"Jimmy_Hendrix"
},{
"namespace":"/wikipedia/en",
"type":"/type/key",
"value":"Johnny_Allen_Hendrix"
}],
"name":[{
"lang":"/lang/fr",
"type":"/type/text",
"value":"Jimi Hendrix"
},{
"lang":"/lang/en",
"type":"/type/text",
"value":"Jimi Hendrix"
},{
"lang":"/lang/de",
"type":"/type/text",
"value":"Jimi Hendrix"
},{
"lang":"/lang/it",
"type":"/type/text",
"value":"Jimi Hendrix"
},{
"lang":"/lang/ja",
"type":"/type/text",
"value":"ジミ・ヘンドリックス"
},{
"lang":"/lang/es",
"type":"/type/text",
"value":"Jimi Hendrix"
}],
"permission":[{
"id":"/boot/all_permission",
"name":"Global Write Permission",
"type":["/type/permission"]
}],
"timestamp":[{
"type":"/type/datetime",
"value":"2006-10-22T09:07:37.0017Z"
}],
"type":"/music/guitarist"
}
}
You cannot nest "*" queries
If we wanted to expand the objects inside Jimi's properties then we be tempted to use a query like this:
{
"query":{
"*":[{
"*":null
}],
"id":"#9202a8c04000641f8000000000020d94",
"type":"/music/guitarist"
}
}
Alas, you cannot nest "*" queries.
You have to name the properties you wish to expand:
{
"query":{
"guitars_played":[{
"*":null
}],
"id":"#9202a8c04000641f8000000000020d94",
"type":"/music/guitarist"
}
}
Jimi as an artist
* Let's use the same query as above, but change thetype to artist
{
"query":{
"*":null,
"id":"#9202a8c04000641f8000000000020d94",
"type":"/music/artist"
}
}
Which gives:
{
"code":"/api/status/ok",
"result":{
"acquire_webpage":[],
"active_end":[],
"active_start":[],
"album":["Live at the Royal Albert Hall","Band of Gypsys","Rainbow Bridge","The Cry of Love","The Essential Jimi Hendrix, Volume 1","The Story of Jimi Hendrix","The Essential Jimi Hendrix, Volume 2","The Jimi Hendrix Concerts","The Ultimate Experience","Blues","Woodstock","Voodoo Soup","Experience Hendrix: The Best of Jimi Hendrix","The Jimi Hendrix Experience (disc 1)","The Jimi Hendrix Experience (disc 2)","The Jimi Hendrix Experience (disc 3)","The Jimi Hendrix Experience (disc 4)","The Last Experience (disc 1)","The Last Experience (disc 2)","The Last Experience (disc 3)","Martin Scorsese Presents the Blues","Most Famous Hits (disc 1)","... At His Best 1","16 Greatest Classics","8 Original Hits of Jimi Hendrix, Volume II: Free Spirit","A Film About Jimi Hendrix-DeLuxe Edition - Disc 1","A Film About Jimi Hendrix-DeLuxe Edition - Disc 2","A Film About Jimi Hendrix-DeLuxe Edition - Disc 3","American Dream","Astro Man (disc 1)","Astro Man (disc 1: Studio outtakes, Volume 1: 1966-1968)","Astro Man (disc 2: Studio Outtakes, Volume 2: 1969)","Astro Man (disc 3: Studio Outtakes, Volume 3: 1969-1970)","Astro Man (disc 4: 1968-01-29: Paris, France)","Astro Man (disc 5: 1969-01-09: Stockholm, Sweden, First Show)","Ball & Chain","Band of Gypsys, Volume 3 (disc 1)","Band of Gypsys, Volume 3 (disc 2)","Before the Experience","Best of Jimi Hendrix (disc 1)","Best of Jimi Hendrix (disc 2)","Best Of","Black Gold, Volume 1 (disc 1)","Black Gold, Volume 2 (disc 1)","Black Gold, Volume 2 (disc 2)","Blue Wild Angel: Live at the Isle of Wight (disc 1)","Blue Wild Angel: Live at the Isle of Wight (disc 2)","Burnin' Soul","Cornerstones 1967-1970","Crash Landing","Drivin' South","Experience Hendrix: The Best of Jimi Hendrix (bonus disc)","Experience","Eye's and Imagination","Gold Collection (disc 1)","Gold Collection (disc 2)","Hear My Music","Hendrix in the West","Historic Hendrix","Jimi Hendrix (Volume IV)","Jimi Hendrix Collection","Jimi Hendrix: The Singles Album (disc 1)","Jimi Hendrix: The Singles Album (disc 2)","Jimi Hendrix","Jimi Hendrix","Jimi in Denmark","Jimi Isle of Wight","Jimi Plays Monterey","Kiss the Sky","Last Experience","Lifelines: The Jimi Hendrix Story (disc 1)","Lifelines: The Jimi Hendrix Story (disc 2)","Lifelines: The Jimi Hendrix Story (disc 3)","Lifelines: The Jimi Hendrix Story (disc 4: L.A. Forum Concert)","Live & Unreleased: The Radio Show (disc 1)","Live & Unreleased: The Radio Show (disc 2)","Live & Unreleased: The Radio Show (disc 3)","Live at Los Angeles Forum 1969","Live at Maple Leaf Gardens '69","Live at The \"Scene\" Club (disc 1)","Live at The \"Scene\" Club (disc 2)","Live at the Fillmore East (disc 1)","Live at the Fillmore East (disc 2)","Live at Woodstock (disc 1)","Live at Woodstock (disc 2)","Live Isle of Wight '70","Live USA (disc 1)","Live USA (disc 2)","Merry Christmas and Happy New Year","Message From Nine to the Universe","Morning Symphony Ideas","Multicolored Blues, Volume 1","Multicolored Blues, Volume 2","New York Session","Paris Jan 29th 1968 Experience","Purple Haze - Black Box (disc 2)","Purple Haze","Real Gold (disc 1)","Real Gold (disc 2)","Red House (Live)"],
"artist_similar":[],
"contribution":[],
"creator":"/user/metaweb",
"genre":[],
"guid":"#9202a8c04000641f8000000000020d94",
"home_page":["Official website"],
"id":"#9202a8c04000641f8000000000020d94",
"key":["16095","Jimi_Hendrix","Jimmy_hendrix","Jimmi_Hendrix","Al_Hendrix","Live_at_Berkely","James_Marshall_Hendrix","James_Hendrix","Jim_Hendrix","Hendrix","Room_full_of_mirrors","06fb1c8b-566e-4cb2-985b-b467c90781d4","ARTIST184","Jimi_hendrix","Jimmy_Hendrix","Johnny_Allen_Hendrix"],
"label":[],
"member":[],
"name":"Jimi Hendrix",
"origin":[],
"permission":"/boot/all_permission",
"similar_artist":[],
"timestamp":"2006-10-22T09:07:37.0017Z",
"track":["Red House","Purple Haze","Good Times","Hey Joe","Purple Haze","Voodoo Chile","Voodoo Chile","Little Wing","The Wind Cries Mary","If Six Was Nine","Purple Haze","Hey Joe","Love or Confusion","Voodoo Chile","Voodoo Child (Slight Return)","Star Spangled Banner / Purple Haze / Instrumental Solo","Interlude","Catfish Blues","Purple Haze","Hey Joe","Outside Woman Blues","Sunshine of Your Love","Red House","House of the Rising Sun","Sunshine of Your Love","Little Wing","Voodoo Chile (Slight Return)","Purple Haze","Red House","Purple Haze","Can You See Me","Spanish Castle Magic","All Along the Watchtower","What'd I Say?","Voodoo Chile (Slight Return)","Voodoo Chile (Slight Return) (live)","Jam Back at the House","Izabella","Get My Heart Back Together","Voodoo Chile (Slight Return)","Red House","All Along the Watchtower","Message To Love","Fire","I Don't Live Today","Foxey Lady","Voice in the Wind","Voodoo Chile (Slight Return) / Stepping Stone","Star Spangled Banner","Purple Haze","Voodoo Chile","Foxey Lady","All Along the Watchtower","Wild Thing","Voodoo Chile","Smashing of the Amps","Killing Floor","Foxey Lady","Like a Rolling Stone","Rock Me Baby","Hey Joe","Can You See Me","The Wind Cries Mary","Purple Haze","Wild Thing","Voodoo Chile (slight return)","Voodoo Chile","Purple Haze","Crosstown Traffic","Star Spangled Banner / Purple Haze","Purple Haze","Little Wing","Hey Joe","Hey Joe","Catfish Blues","Fire","Fire","Voodoo Chile","Voodoo Chile (live)","Purple Haze","Purple Haze","All Along the Watchtower","Fire","Hot Trigger","Hot Trigger","The Sunshine of Your Love","Voodoo Chile (Slight Return)","Foxey Lady","Little Wing","Voodoo Chile (Slight Return, Short version)","Purple Haze","Born Under a Bad Sign","Purple haze","Angel","Purple Haze","Spanish Castle Magic","Hey Joe","Purple Haze","Little Wing","All Along the Watchtower"],
"type":"/music/artist"
}
}
Conclusion: You need to use multiple queries
We are getting lots of info now on Jimi, but each time we have to supply the relevanttype. The only way to do this is to make multiple queries.
Query 1 to get Jimi's types:
{
"query":{
"type":[],
"id":"#9202a8c04000641f8000000000020d94"
}
}
Followed by n queries:
{
"query":{
"*":[{}],
"id":"#9202a8c04000641f8000000000020d94",
"type":"/music/guitarist"
}
}
/music/guitarist,/music/artist,/common/topic,/people/person,/music/group_member,/people/deceased_person
Is there a better way?
Introducing reflection
Mirror mirror on the wall... There are 3 "virtual" properties on any object:any_master, any_reverse and any_value
/type/reflect/any_master- All the outgoing links to other topics/type/reflect/any_reverse- The incoming links from other topics to Jimi/type/reflect/any_value- Properties of Jimi that are basic datatypes (not topics)
TODO:
Note that:
1) "optional" in each of any_master, any_reverse, any_value - otherwise
it will constrain the whole query to make sure there's one of each of these
2) this gets ALL properties, including the type of an object, so there
can be a lot of information. You can however, constrain the particular
types by constraining the 'schema' of the master_property or
reverse_property like
{"master_property": {"schema": "/film/actor"}}
Let's look at the virtual properties one by one.
Using any_master
{
"query":[{
"/type/reflect/any_master":[{
"*":null
}],
"id":"#9202a8c04000641f8000000000020d94",
}]
}
(TODO: "type":"/music/artist" doesn't make a difference at top level - you still get all the master properties)
Result is:
{
"code":"/api/status/ok",
"result":[{
"/type/reflect/any_master":[{
"creator":"/user/root",
"guid":"#9202a8c04000641f8000000000000089",
"id":"#9202a8c04000641f8000000000000089",
"key":["all_permission"],
"name":"Global Write Permission",
"permission":"/boot/user_permission",
"timestamp":"2006-10-22T07:34:26.0042Z",
"type":["/type/permission"]
},{
"creator":"/user/mwcl_wikipedia_en",
"guid":"#9202a8c04000641f8000000000020d9e",
"id":"#9202a8c04000641f8000000000020d9e",
"key":[],
"name":null,
"permission":"/boot/all_permission",
"timestamp":"2006-10-22T09:07:37.0027Z",
"type":["/common/document"]
},{
"creator":"/user/mw_typer",
"guid":"#9202a8c04000641f80000000011af728",
"id":"#9202a8c04000641f80000000011af728",
"key":["guitarist"],
"name":"Guitarist",
"permission":"#9202a8c04000641f80000000011ae805",
"timestamp":"2006-12-07T02:12:52.0120Z",
"type":["/type/type","/freebase/type_profile"]
},{
"creator":"/user/metaweb",
"guid":"#9202a8c04000641f80000000011ae833",
"id":"#9202a8c04000641f80000000011ae833",
"key":["artist"],
"name":"Musical Artist",
"permission":"#9202a8c04000641f80000000011ae805",
"timestamp":"2006-12-06T09:19:34.0030Z",
"type":["/type/type","/freebase/type_profile"]
},{
"creator":"/user/metaweb",
"guid":"#9202a8c04000641f8000000000000565",
"id":"#9202a8c04000641f8000000000000565",
"key":["topic"],
"name":"Topic",
"permission":"#9202a8c04000641f800000000000039f",
"timestamp":"2006-10-22T07:34:52.0018Z",
"type":["/type/type","/freebase/type_profile"]
},{
"creator":"/user/metaweb",
"guid":"#9202a8c04000641f8000000000001237",
"id":"#9202a8c04000641f8000000000001237",
"key":["person"],
"name":"Person",
"permission":"#9202a8c04000641f8000000003e046ac",
"timestamp":"2006-10-22T07:35:19.0000Z",
"type":["/type/type","/freebase/type_profile"]
},{
"creator":"/user/metaweb",
"guid":"#9202a8c04000641f80000000011ae83f",
"id":"#9202a8c04000641f80000000011ae83f",
"key":["group_member"],
"name":"Musical Group Member",
"permission":"#9202a8c04000641f80000000011ae805",
"timestamp":"2006-12-06T09:19:34.0042Z",
"type":["/type/type","/freebase/type_profile"]
},{
"creator":"/user/mwcl_musicbrainz",
"guid":"#9202a8c04000641f8000000003919b8c",
"id":"#9202a8c04000641f8000000003919b8c",
"key":[],
"name":"Official website",
"permission":"/boot/all_permission",
"timestamp":"2006-12-10T14:50:01.0210Z",
"type":["/common/webpage"]
},{
"creator":"/user/mwcl_musicbrainz",
"guid":"#9202a8c04000641f8000000003919b91",
"id":"#9202a8c04000641f8000000003919b91",
"key":[],
"name":"Discography",
"permission":"/boot/all_permission",
"timestamp":"2006-12-10T14:50:01.0215Z",
"type":["/common/webpage"]
},{
"creator":"/user/mwcl_musicbrainz",
"guid":"#9202a8c04000641f8000000003919b96",
"id":"#9202a8c04000641f8000000003919b96",
"key":[],
"name":"Jimi Hendrix: Discography, Track index, Set lists provides access to several Jimi Hendrix related lists. The first two lists are a catalog of releases and a song cross-reference. The third list is a set list for live performances. Finally, I list releases and private recordings that the author owns. ",
"permission":"/boot/all_permission",
"timestamp":"2006-12-10T14:50:01.0220Z",
"type":["/common/webpage"]
},{
"creator":"/user/mwcl_musicbrainz",
"guid":"#9202a8c04000641f8000000003919b9b",
"id":"#9202a8c04000641f8000000003919b9b",
"key":[],
"name":"Randy Foley's Amazing Jimi Hendrix Chronology A list of tracks, on what album they were first released and when they were recorded. ",
"permission":"/boot/all_permission",
"timestamp":"2006-12-10T14:50:01.0225Z",
"type":["/common/webpage"]
},{
"creator":"/user/mwcl_musicbrainz",
"guid":"#9202a8c04000641f8000000003919ba0",
"id":"#9202a8c04000641f8000000003919ba0",
"key":[],
"name":"The Jimi Hendrix Experience A page with a lot of information on the Jimi Hendrix Experience ",
"permission":"/boot/all_permission",
"timestamp":"2006-12-10T14:50:01.0230Z",
"type":["/common/webpage"]
},{
"creator":"/user/mwcl_musicbrainz",
"guid":"#9202a8c04000641f8000000003919ba5",
"id":"#9202a8c04000641f8000000003919ba5",
"key":[],
"name":"http://www.discogs.com/artist/Jimi+Hendrix",
"permission":"/boot/all_permission",
"timestamp":"2006-12-10T14:50:01.0235Z",
"type":["/common/webpage"]
},{
"creator":"/user/danm",
"guid":"#9202a8c04000641f80000000042cb6f1",
"id":"#9202a8c04000641f80000000042cb6f1",
"key":["deceased_person"],
"name":"Deceased Person",
"permission":"#9202a8c04000641f8000000003e046ac",
"timestamp":"2007-03-19T22:35:20.0015Z",
"type":["/type/type","/freebase/type_profile"]
},{
"creator":"/user/patrick",
"guid":"#9202a8c04000641f8000000004390e3f",
"id":"#9202a8c04000641f8000000004390e3f",
"key":[],
"name":"Inhalation of vomit",
"permission":"/boot/all_permission",
"timestamp":"2007-03-23T01:23:59.0358Z",
"type":["/people/cause_of_death","/common/topic"]
},{
"creator":"/user/mwcl_images",
"guid":"#9202a8c04000641f800000000497dab3",
"id":"#9202a8c04000641f800000000497dab3",
"key":[],
"name":null,
"permission":"/boot/all_permission",
"timestamp":"2007-04-15T02:59:16.0007Z",
"type":["/type/content","/common/image"]
},{
"creator":"/user/metaweb",
"guid":"#9202a8c04000641f8000000000062617",
"id":"#9202a8c04000641f8000000000062617",
"key":["50276","Seattle$002C_Washington","Seattle","Seattle$002C_WA","Seattleite","Seattleites","Seattle$002C_Wash$002E","Seattle_$0028WA$0029","Jet_City","Seatle","5809844","UN$002FLOCODE$003AUSSEA"],
"name":"Seattle, Washington",
"permission":"/boot/all_permission",
"timestamp":"2006-10-22T09:53:48.0047Z",
"type":["/common/topic","/location/location","/location/citytown","/location/us_citytown","/user/joehughes/default_domain/transit_service_area","/film/film_location","/fictional_universe/fictional_setting"]
},{
"creator":"/user/metaweb",
"guid":"#9202a8c04000641f80000000000242b2",
"id":"#9202a8c04000641f80000000000242b2",
"key":["17867","London","London$002C_Great_Britain","London$002C_United_Kingdom","Capital_of_the_United_Kingdom","Capital_of_the_UK","London$002C_UK","England_London","London_Britain","GBLON","What_is_the_capital_of_England","Leondeon","The_big_smoke","Modern_Babylon","Brimsdown_house","London_$0028England$0029","London$002C_England","London_England","Capital_of_England","Llundain","London$002C_england","London_england","London_$0028Great_Britain$0029","London_$0028Britain$0029","Londra","United_Kingdom$002FLondon","LONDON","London_$0028United_Kingdom$0029","South_Bank$002C_London","UN$002FLOCODE$003AGBLON","London_$0028UK$0029"],
"name":"London",
"permission":"/boot/all_permission",
"timestamp":"2006-10-22T09:10:03.0059Z",
"type":["/common/topic","/location/citytown","/location/location","/user/juniorbonner/default_domain/capital_city","/fictional_universe/fictional_setting"]
},{
"creator":"/user/metaweb",
"guid":"#9202a8c04000641f80000000005f56be",
"id":"#9202a8c04000641f80000000005f56be",
"key":["1822282","Male","Males"],
"name":"Male",
"permission":"/boot/all_permission",
"timestamp":"2006-10-23T04:55:08.0011Z",
"type":["/common/topic","/people/gender","/fictional_universe/character_gender"]
}],
"id":"#9202a8c04000641f8000000000020d94",
}]
}
(And that's without using
"*":[{}] to expand the objects)
So what are we seeing? These are the Common Object Properties of the topics pointed to by Jimi's topic. (Recall that when the type is not set "*":null expands to the common properties).
any_master - locations only
If you wanted to see only locations refered to by Jimi's topic then you could make a query like this:
{
"query":[{
"/type/reflect/any_master":[{
"*":null,
"type":"/location/location"
}],
"id":"#9202a8c04000641f8000000000020d94"
}]
}
result:
{
"code":"/api/status/ok",
"result":[{
"/type/reflect/any_master":[{
"adjoining":[],
"adjoins":[],
"containedby":["King County","United States","Washington"],
"contains":["Ballard, Seattle, Washington","Space Needle","Real Networks","University of Washington","Capitol Hill, Seattle, Washington","South Lake Union, Seattle, Washington"],
"creator":"/user/metaweb",
"geolocation":null,
"gnis_feature_id":[],
"gns_ufi":[],
"guid":"#9202a8c04000641f8000000000062617",
"id":"#9202a8c04000641f8000000000062617",
"key":["50276","Seattle$002C_Washington","Seattle","Seattle$002C_WA","Seattleite","Seattleites","Seattle$002C_Wash$002E","Seattle_$0028WA$0029","Jet_City","Seatle","5809844","UN$002FLOCODE$003AUSSEA"],
"name":"Seattle, Washington",
"permission":"/boot/all_permission",
"street":[],
"timestamp":"2006-10-22T09:53:48.0047Z",
"type":"/location/location",
"usbg_name":[]
},{
"adjoining":[],
"adjoins":[],
"containedby":["Greater London"],
"contains":["London Borough of Camden","London Borough of Islington","London Borough of Hackney","London Borough of Greenwich","London Borough of Southwark","London Borough of Hounslow","London Borough of Ealing","London Borough of Haringey","London Borough of Enfield"],
"creator":"/user/metaweb",
"geolocation":null,
"gnis_feature_id":[],
"gns_ufi":[],
"guid":"#9202a8c04000641f80000000000242b2",
"id":"#9202a8c04000641f80000000000242b2",
"key":["17867","London","London$002C_Great_Britain","London$002C_United_Kingdom","Capital_of_the_United_Kingdom","Capital_of_the_UK","London$002C_UK","England_London","London_Britain","GBLON","What_is_the_capital_of_England","Leondeon","The_big_smoke","Modern_Babylon","Brimsdown_house","London_$0028England$0029","London$002C_England","London_England","Capital_of_England","Llundain","London$002C_england","London_england","London_$0028Great_Britain$0029","London_$0028Britain$0029","Londra","United_Kingdom$002FLondon","LONDON","London_$0028United_Kingdom$0029","South_Bank$002C_London","UN$002FLOCODE$003AGBLON","London_$0028UK$0029"],
"name":"London",
"permission":"/boot/all_permission",
"street":[],
"timestamp":"2006-10-22T09:10:03.0059Z",
"type":"/location/location",
"usbg_name":[]
}],
"id":"#9202a8c04000641f8000000000020d94"
}]
}
The link pseudo type
{
"query":[{
"/type/reflect/any_master":[{
"link":{
"*":null
},
"type":"/location/location"
}],
"id":"#9202a8c04000641f8000000000020d94"
}]
}
response:
{
"code":"/api/status/ok",
"result":[{
"/type/reflect/any_master":[{
"link":{
"creator":"/user/mwcl_infobox",
"master_property":"/people/person/place_of_birth",
"operation":"insert",
"reverse":false,
"timestamp":"2007-05-28T19:37:38.0055Z",
"type":"/type/link",
"valid":true
},
"type":"/location/location"
},{
"link":{
"creator":"/user/mwcl_infobox",
"master_property":"/people/deceased_person/place_of_death",
"operation":"insert",
"reverse":false,
"timestamp":"2007-05-28T19:38:54.0085Z",
"type":"/type/link",
"valid":true
},
"type":"/location/location"
}],
"id":"#9202a8c04000641f8000000000020d94"
}]
}
link refer to the link itself, so creator and timestamp tell you who filled in Jimi's birthday place and when.
TODO: what do operation and valid mean ?? Document reverse
Which location is which?
{
"query":[{
"/type/reflect/any_master":[{
"link":{
"*":null
},
"name":null,
"type":"/location/location"
}],
"id":"#9202a8c04000641f8000000000020d94"
}]
}
Which gives:
{
"code":"/api/status/ok",
"result":[{
"/type/reflect/any_master":[{
"link":{
"creator":"/user/mwcl_infobox",
"master_property":"/people/person/place_of_birth",
"operation":"insert",
"reverse":false,
"timestamp":"2007-05-28T19:37:38.0055Z",
"type":"/type/link",
"valid":true
},
"name":"Seattle, Washington",
"type":"/location/location"
},{
"link":{
"creator":"/user/mwcl_infobox",
"master_property":"/people/deceased_person/place_of_death",
"operation":"insert",
"reverse":false,
"timestamp":"2007-05-28T19:38:54.0085Z",
"type":"/type/link",
"valid":true
},
"name":"London",
"type":"/location/location"
}],
"id":"#9202a8c04000641f8000000000020d94"
}]
}
/people/person/place_of_birth property is Seattle and his /people/deceased_person/place_of_death is London.
How could we get the human-readable names for these properties?
Expanding master_property
{
"query":[{
"/type/reflect/any_master":[{
"link":{
"master_property":{
"*":null
}
},
"name":null,
"type":"/location/location"
}],
"id":"#9202a8c04000641f8000000000020d94"
}]
}
Which gives:
{
"code":"/api/status/ok",
"result":[{
"/type/reflect/any_master":[{
"link":{
"master_property":{
"creator":"/user/metaweb",
"expected_type":"/location/location",
"guid":"#9202a8c04000641f8000000000001268",
"id":"/people/person/place_of_birth",
"key":["place_of_birth"],
"master_property":null,
"name":"Place of Birth",
"permission":"#9202a8c04000641f800000000000039f",
"reverse_property":[],
"schema":"/people/person",
"timestamp":"2006-10-22T07:35:19.0049Z",
"type":["/type/property"],
"unique":true,
"unit":null
}
},
"name":"Seattle, Washington",
"type":"/location/location"
},{
"link":{
"master_property":{
"creator":"/user/metaweb",
"expected_type":"/location/location",
"guid":"#9202a8c04000641f8000000000001276",
"id":"/people/deceased_person/place_of_death",
"key":["place_of_death"],
"master_property":null,
"name":"Place of Death",
"permission":"#9202a8c04000641f800000000000039f",
"reverse_property":[],
"schema":"/people/deceased_person",
"timestamp":"2006-10-22T07:35:19.0063Z",
"type":["/type/property"],
"unique":true,
"unit":null
}
},
"name":"London",
"type":"/location/location"
}],
"id":"#9202a8c04000641f8000000000020d94"
}]
}
Place of Birth: Seattle
Place of Death: London
TODO: document unique, schema, unit?? TODO: When would you specify the schema? (after all, if you know the schema then you could just construct a specific query)
Using any_reverse
We can also find all topics that link to Jimi.
Note: There are more than 100 incoming links so we have to use "limit":0 to see them all.To reduce the size of the reponse, I'm only asking for
name and type rather than all the Common Object Properties.
{
"query":[{
"/type/reflect/any_reverse":[{
"limit":0,
"name":null,
"type":[]
}],
"id":"#9202a8c04000641f8000000000020d94"
}]
}
I only show part of the result here:
{
"code":"/api/status/ok",
"result":[{
"/type/reflect/any_reverse":[{
"name":"Live at the Royal Albert Hall",
"type":["/music/album","/common/topic"]
},{
"name":"Band of Gypsys",
"type":["/music/album","/common/topic"]
},{
"name":"Rainbow Bridge",
"type":["/music/album","/common/topic","/music/soundtrack"]
// ... snipped ....
},{
"name":"Voodoo Chile",
"type":["/music/track"]
},{
"name":"Little Wing",
"type":["/music/track"]
},{
"name":"The Wind Cries Mary",
"type":["/music/track"]
// ... snipped ....
},{
"name":null,
"type":["/music/group_membership"]
},{
"name":null,
"type":["/music/group_membership"]
},{
"name":null,
"type":["/music/group_membership"]
},{
"name":"Fender Stratocaster",
"type":["/common/topic","/music/guitar","/music/instrument"]
},{
"name":"Band of Gypsys",
"type":["/music/release"]
// ... snipped ....
},{
"name":"theleafs",
"type":["/type/user","/type/namespace","/freebase/user_profile"]
},{
// ... snipped ....
"name":"iftash",
"type":["/type/user","/type/namespace","/freebase/user_profile"]
}],
"id":"#9202a8c04000641f8000000000020d94"
}]
}
Why are the users linking to Jimi?
Just as with theany_master exmaples above we can use link's master_property to find out the relationship between the users and Jimi:
{
"query":[{
"/type/reflect/any_reverse":[{
"link":{
"master_property":{
"name":null
}
},
"name":null,
"type":"/type/user"
}],
"id":"#9202a8c04000641f8000000000020d94"
}]
}
{
"code":"/api/status/ok",
"result":[{
"/type/reflect/any_reverse":[{
"link":{
"master_property":{
"name":"Favorite Music Artists"
}
},
"name":"theleafs",
"type":"/type/user"
},{
"link":{
"master_property":{
"name":"Favorite Music Artists"
}
},
"name":"burny",
"type":"/type/user"
},{
"link":{
"master_property":{
"name":"Favorite Music Artists"
}
},
"name":"fzyda",
"type":"/type/user"
},{
"link":{
"master_property":{
"name":"Favorite Music Artists"
}
},
"name":"bradpatrick",
"type":"/type/user"
},{
"link":{
"master_property":{
"name":"Favorite Music Artists"
}
},
"name":"iftash",
"type":"/type/user"
}],
"id":"#9202a8c04000641f8000000000020d94"
}]
}
reverse_property ??TODO: show that
"reverse":true
any_reverse and any_master
+------------------------------------+ +---------------------+ | Jimi | | Rainbow Bridge | | ==== | | | | | | | | .any_reverse ------------------------->| | | | | | | .link | | | | | | | | .master_property = Artist | | | | | | | | .reverse_property = Albums | | | | | | | +------------------------------------+ +---------------------+ TODO: this needs more work!
And finally, using any_value
Jimi also has properties which are values rather than objects. For example his date of birth.
We query the values:
{
"query":[{
"/type/reflect/any_value":[{
"*":null
}],
"id":"#9202a8c04000641f8000000000020d94"
}]
}
Response:
{
"code":"/api/status/ok",
"result":[{
"/type/reflect/any_value":[{
"type":"/type/text",
"value":"Jimi Hendrix"
},{
"type":"/type/text",
"value":"Jimi Hendrix"
},{
"type":"/type/text",
"value":"Jimi Hendrix"
},{
"type":"/type/text",
"value":"Jimi Hendrix"
},{
"type":"/type/text",
"value":"ジミ・ヘンドリックス"
},{
"type":"/type/text",
"value":"Jimi Hendrix"
},{
"type":"/type/text",
"value":"Jimi Hendricks"
},{
"type":"/type/text",
"value":"Hendrix"
},{
"type":"/type/text",
"value":"Jimi Hendrix"
},{
"type":"/type/text",
"value":"ジミ・ヘンドリックス"
},{
"type":"/type/text",
"value":"Jimmy Hendrix"
},{
"type":"/type/text",
"value":"Jimmie Henderix"
},{
"type":"/type/text",
"value":"Jimi Henriks"
},{
"type":"/type/text",
"value":"Jimy Hendrix"
},{
"type":"/type/text",
"value":"Jimmi Hendrix"
},{
"type":"/type/datetime",
"value":"1970-09-18"
},{
"type":"/type/datetime",
"value":"1942-11-27"
}],
"id":"#9202a8c04000641f8000000000020d94"
}]
}>
type and value
Using link with any_value
TODO: what does link mean in this case? It's not a link to another topic but a link to the property description? What did link mean in the previous cases?
{
"query":[{
"/type/reflect/any_value":[{
"*":null,
"link":{
"*":null
}
}],
"id":"#9202a8c04000641f8000000000020d94"
}]
}
Result:
{
"code":"/api/status/ok",
"result":[{
"/type/reflect/any_value":[{
"link":{
"creator":"/user/mwcl_wikipedia_en",
"master_property":"/type/object/name",
"operation":"insert",
"reverse":false,
"timestamp":"2006-10-22T09:07:37.0021Z",
"type":"/type/link",
"valid":true
},
"type":"/type/text",
"value":"Jimi Hendrix"
},{
"link":{
"creator":"/user/mwcl_wikipedia_en",
"master_property":"/type/object/name",
"operation":"insert",
"reverse":false,
"timestamp":"2006-10-22T09:07:37.0022Z",
"type":"/type/link",
"valid":true
},
"type":"/type/text",
"value":"Jimi Hendrix"
},{
"link":{
"creator":"/user/mwcl_wikipedia_en",
"master_property":"/type/object/name",
"operation":"insert",
"reverse":false,
"timestamp":"2006-10-22T09:07:37.0023Z",
"type":"/type/link",
"valid":true
},
"type":"/type/text",
"value":"Jimi Hendrix"
},{
"link":{
"creator":"/user/mwcl_wikipedia_en",
"master_property":"/type/object/name",
"operation":"insert",
"reverse":false,
"timestamp":"2006-10-22T09:07:37.0024Z",
"type":"/type/link",
"valid":true
},
"type":"/type/text",
"value":"Jimi Hendrix"
},{
"link":{
"creator":"/user/mwcl_wikipedia_en",
"master_property":"/type/object/name",
"operation":"insert",
"reverse":false,
"timestamp":"2006-10-22T09:07:37.0025Z",
"type":"/type/link",
"valid":true
},
"type":"/type/text",
"value":"ジミ・ヘンドリックス"
},{
"link":{
"creator":"/user/mwcl_wikipedia_en",
"master_property":"/type/object/name",
"operation":"insert",
"reverse":false,
"timestamp":"2006-10-22T09:07:37.0026Z",
"type":"/type/link",
"valid":true
},
"type":"/type/text",
"value":"Jimi Hendrix"
},{
"link":{
"creator":"/user/metaweb",
"master_property":"/people/person/date_of_birth",
"operation":"insert",
"reverse":false,
"timestamp":"2006-11-14T18:05:26.0026Z",
"type":"/type/link",
"valid":false
},
"type":"/type/datetime",
"value":"1942"
},{
"link":{
"creator":"/user/metaweb",
"master_property":"/people/deceased_person/date_of_death",
"operation":"insert",
"reverse":false,
"timestamp":"2006-11-14T18:05:26.0028Z",
"type":"/type/link",
"valid":false
},
"type":"/type/datetime",
"value":"1970"
},{
"link":{
"creator":"/user/mwcl_musicbrainz",
"master_property":"/common/topic/alias",
"operation":"insert",
"reverse":false,
"timestamp":"2006-12-10T14:50:01.0199Z",
"type":"/type/link",
"valid":true
},
"type":"/type/text",
"value":"Jimi Hendricks"
},{
"link":{
"creator":"/user/mwcl_musicbrainz",
"master_property":"/common/topic/alias",
"operation":"insert",
"reverse":false,
"timestamp":"2006-12-10T14:50:01.0200Z",
"type":"/type/link",
"valid":true
},
"type":"/type/text",
"value":"Hendrix"
},{
"link":{
"creator":"/user/mwcl_musicbrainz",
"master_property":"/common/topic/alias",
"operation":"insert",
"reverse":false,
"timestamp":"2006-12-10T14:50:01.0201Z",
"type":"/type/link",
"valid":true
},
"type":"/type/text",
"value":"Jimi Hendrix"
},{
"link":{
"creator":"/user/mwcl_musicbrainz",
"master_property":"/common/topic/alias",
"operation":"insert",
"reverse":false,
"timestamp":"2006-12-10T14:50:01.0202Z",
"type":"/type/link",
"valid":true
},
"type":"/type/text",
"value":"ジミ・ヘンドリックス"
},{
"link":{
"creator":"/user/mwcl_musicbrainz",
"master_property":"/common/topic/alias",
"operation":"insert",
"reverse":false,
"timestamp":"2006-12-10T14:50:01.0203Z",
"type":"/type/link",
"valid":true
},
"type":"/type/text",
"value":"Jimmy Hendrix"
},{
"link":{
"creator":"/user/mwcl_musicbrainz",
"master_property":"/common/topic/alias",
"operation":"insert",
"reverse":false,
"timestamp":"2006-12-10T14:50:01.0204Z",
"type":"/type/link",
"valid":true
},
"type":"/type/text",
"value":"Jimmie Henderix"
},{
"link":{
"creator":"/user/mwcl_musicbrainz",
"master_property":"/common/topic/alias",
"operation":"insert",
"reverse":false,
"timestamp":"2006-12-10T14:50:01.0205Z",
"type":"/type/link",
"valid":true
},
"type":"/type/text",
"value":"Jimi Henriks"
},{
"link":{
"creator":"/user/mwcl_musicbrainz",
"master_property":"/common/topic/alias",
"operation":"insert",
"reverse":false,
"timestamp":"2006-12-10T14:50:01.0206Z",
"type":"/type/link",
"valid":true
},
"type":"/type/text",
"value":"Jimy Hendrix"
},{
"link":{
"creator":"/user/mwcl_musicbrainz",
"master_property":"/common/topic/alias",
"operation":"insert",
"reverse":false,
"timestamp":"2006-12-10T14:50:01.0207Z",
"type":"/type/link",
"valid":true
},
"type":"/type/text",
"value":"Jimmi Hendrix"
},{
"link":{
"creator":"/user/mwcl_musicbrainz",
"master_property":"/people/deceased_person/date_of_death",
"operation":"insert",
"reverse":false,
"timestamp":"2006-12-10T14:50:01.0208Z",
"type":"/type/link",
"valid":true
},
"type":"/type/datetime",
"value":"1970-09-18"
},{
"link":{
"creator":"/user/mwcl_musicbrainz",
"master_property":"/people/person/date_of_birth",
"operation":"insert",
"reverse":false,
"timestamp":"2006-12-10T14:50:01.0209Z",
"type":"/type/link",
"valid":true
},
"type":"/type/datetime",
"value":"1942-11-27"
},{
"link":{
"creator":"/user/jamie",
"master_property":"/people/person/date_of_birth",
"operation":"delete",
"reverse":false,
"timestamp":"2007-02-21T23:17:52.0004Z",
"type":"/type/link",
"valid":null
},
"type":"/type/datetime",
"value":"1942"
},{
"link":{
"creator":"/user/alexander",
"master_property":"/people/deceased_person/date_of_death",
"operation":"delete",
"reverse":false,
"timestamp":"2007-06-26T01:08:48.0010Z",
"type":"/type/link",
"valid":null
},
"type":"/type/datetime",
"value":"1970"
}],
"id":"#9202a8c04000641f8000000000020d94"
}]
}
Once again we use master_property to show the property name
{
"query":[{
"/type/reflect/any_value":[{
"*":null,
"link":{
"master_property":{
"name":null
}
}
}],
"id":"#9202a8c04000641f8000000000020d94"
}]
}
Result:
{
"code":"/api/status/ok",
"result":[{
"/type/reflect/any_value":[{
"link":{
"master_property":{
"name":"name"
}
},
"type":"/type/text",
"value":"Jimi Hendrix"
},{
"link":{
"master_property":{
"name":"name"
}
},
"type":"/type/text",
"value":"Jimi Hendrix"
},{
"link":{
"master_property":{
"name":"name"
}
},
"type":"/type/text",
"value":"Jimi Hendrix"
},{
"link":{
"master_property":{
"name":"name"
}
},
"type":"/type/text",
"value":"Jimi Hendrix"
},{
"link":{
"master_property":{
"name":"name"
}
},
"type":"/type/text",
"value":"ジミ・ヘンドリックス"
},{
"link":{
"master_property":{
"name":"name"
}
},
"type":"/type/text",
"value":"Jimi Hendrix"
},{
"link":{
"master_property":{
"name":"Also known as"
}
},
"type":"/type/text",
"value":"Jimi Hendricks"
},{
"link":{
"master_property":{
"name":"Also known as"
}
},
"type":"/type/text",
"value":"Hendrix"
},{
"link":{
"master_property":{
"name":"Also known as"
}
},
"type":"/type/text",
"value":"Jimi Hendrix"
},{
"link":{
"master_property":{
"name":"Also known as"
}
},
"type":"/type/text",
"value":"ジミ・ヘンドリックス"
},{
"link":{
"master_property":{
"name":"Also known as"
}
},
"type":"/type/text",
"value":"Jimmy Hendrix"
},{
"link":{
"master_property":{
"name":"Also known as"
}
},
"type":"/type/text",
"value":"Jimmie Henderix"
},{
"link":{
"master_property":{
"name":"Also known as"
}
},
"type":"/type/text",
"value":"Jimi Henriks"
},{
"link":{
"master_property":{
"name":"Also known as"
}
},
"type":"/type/text",
"value":"Jimy Hendrix"
},{
"link":{
"master_property":{
"name":"Also known as"
}
},
"type":"/type/text",
"value":"Jimmi Hendrix"
},{
"link":{
"master_property":{
"name":"Date of Death"
}
},
"type":"/type/datetime",
"value":"1970-09-18"
},{
"link":{
"master_property":{
"name":"Date of Birth"
}
},
"type":"/type/datetime",
"value":"1942-11-27"
}],
"id":"#9202a8c04000641f8000000000020d94"
}]
}
Putting it all together
TODO:
- Add links to Query Editor using Javascript
- Toggle size of query boxes?
- Make different boxes for query + result. Use non-repeating background image to say which is which?
- Mouse over view of topic
- WISH: auto-diff JSON
- TODO: check the highlighting of response and query are the same - could this be automatic??