[Developers] query for values vs name/id
Alec Flett
alecf at metaweb.com
Thu May 24 17:41:12 UTC 2007
Another great question - this brings up the general concept of
"default_property"
If I ask for two property values with null and []:
{
"q":{
"query":{
"active_start":null,
"genre":[],
"name":"The Police",
"type":"/music/artist"
}
}
}
I get the response:
{
"q":{
"result":{
"active_start":"1977-01",
"genre":["Rock music","Ska","Reggae"],
"name":"The Police",
"type":"/music/artist"
},
"status":"/mql/status/ok"
},
"status":"200 OK"
}
What's interesting here is that "genre" is a reference to other topics
and "active_start" is a primitive datetime type. But how could we
possibly know this? And how does MQL know to put the name of the genre
topic, instead of the id? The answer is in the "default_property" of a type.
Let's inspect these properties:
{
"q":{
"query":{
"id":"/music/artist",
"properties":[{
"expected_type":{
"default_property":null,
"id":null
},
"id":null,
"id|=":["/music/artist/genre","/music/artist/active_start"]
}],
"type":"/type/type"
}
}
}
And the response:
{
"q":{
"result":{
"id":"/music/artist",
"properties":[{
"expected_type":{
"default_property":"value",
"id":"/type/datetime"
},
"id":"/music/artist/active_start"
},{
"expected_type":{
"default_property":null,
"id":"/music/genre"
},
"id":"/music/artist/genre"
}],
"type":"/type/type"
},
"status":"/mql/status/ok"
},
"status":"200 OK"
}
Note that "active_start" is a datetime, and the default property is
"value".. in the case of /music/genre, there is no "default_property" -
when this happens, MQL defaults to the "name" property.
Because MQL has this built in, you get the "right" value if you don't
expand the property clause (i.e. if you just put 'null' or '[]')
But MQL has a way of blowing out the default property and automatically
asking for the right set of properties - it's {} or [{}] instead of null
or []:
{
"q":{
"query":{
"active_start":{},
"genre":[{}],
"name":"The Police",
"type":"/music/artist"
}
}
}
Look at the result:
{
"q":{
"result":{
"active_start":{
"type":"/type/datetime",
"value":"1977-01"
},
"genre":[{
"id":"#9202a8c04000641f8000000000032ba7",
"name":"Rock music",
"type":["/common/topic","/music/genre"]
},{
"id":"#9202a8c04000641f8000000000035edb",
"name":"Ska",
"type":["/common/topic","/music/genre"]
},{
"id":"#9202a8c04000641f8000000000032eca",
"name":"Reggae",
"type":["/common/topic","/music/genre"]
}],
"name":"The Police",
"type":"/music/artist"
},
"status":"/mql/status/ok"
},
"status":"200 OK"
}
For all values, it includes "id" and "type" - for primitive types, it
includes "name" or "value" as appropriate.
But what you're doing (expanding all the properties of a particular
type) can actually be accomplished with the "*" property, which expands
to all properties. I'll let you run the query because the response is
quite large:
{
"q":{
"query":{
"*":[{}],
"name":"The Police",
"type":"/music/artist"
}
}
}
Hope this helps,
Alec
Steve Sak wrote:
> Given that I've performed a query to get the properties of some class,
> say /music/artist and now want to get the "values" and maybe some other
> attributes of those properties what does the query look like? The
> problem I'm running into is when asking for attributes explicitly I
> can't tell if the property refers to a primitive attibute or another
> object. Perhaps I'm just missing something obvious.
>
> For instance:
>
> {"query0": { "query":[{
> "limit":1,
> "name":"The Police",
> "type":"/music/artist",
> "/music/artist/active_start":[{"name":null,"id":null}],
> "/music/artist/acquire_webpage":[{"name":null,"id":null}],
> "/music/artist/album":[{"name":null,"id":null}],
> "/music/artist/similar_artist":[{"name":null,"id":null}],
> "/music/artist/origin":[{"name":null,"id":null}],
> "/music/artist/home_page":[{"name":null,"id":null}],
> "/music/artist/active_end":[{"name":null,"id":null}],
> "/music/artist/label":[{"name":null,"id":null}],
> "/music/artist/artist_similar":[{"name":null,"id":null}],"
> /music/artist/genre":[{"name":null,"id":null}],
> "/music/artist/track":[{"name":null,"id":null}],
> "/music/artist/contribution":[{"name":null,"id":null}],
> "/music/artist/member":[{"name":null,"id":null}]}]}}
>
> gives the error:
>
> {
> "status": "/mql/status/error",
> "messages": [ {
> "info": {
> "property": "name",
> "expected_type": "/type/datetime"
> },
> "query": [ {
> "/music/artist/active_start": [ {
> "error_inside": ".",
> "name": null,
> "id": null
> }],
> "/music/artist/acquire_webpage": [ {
> "name": null,
> "id": null
> }],
> "limit": 1,
> "type": "/music/artist",
> "/music/artist/album": [ {
> "name": null,
> "id": null
> }],
> "/music/artist/similar_artist": [ {
> "name": null,
> "id": null
> }],
> "/music/artist/home_page": [ {
> "name": null,
> "id": null
> }],
> "/music/artist/origin": [ {
> "name": null,
> "id": null
> }],
> "/music/artist/active_end": [ {
> "name": null,
> "id": null
> }],
> "/music/artist/label": [ {
> "name": null,
> "id": null
> }],
> "/music/artist/genre": [ {
> "name": null,
> "id": null
> }],
> "/music/artist/artist_similar": [ {
> "name": null,
> "id": null
> }],
> "/music/artist/track": [ {
> "name": null,
> "id": null
> }],
> "/music/artist/contribution": [ {
> "name": null,
> "id": null
> }],
> "name": "The Police",
> "/music/artist/member": [ {
> "name": null,
> "id": null
> }]
> }],
> "type": "/mql/error",
> "message": "Type /type/datetime does not have property name",
> "path": "/music/artist/active_start",
> "status": "/mql/status/type_error"
> }]
> }
> _______________________________________________
> Developers mailing list
> Developers at freebase.com
> http://lists.freebase.com/mailman/listinfo/developers
>
More information about the Developers
mailing list