[Developers] Merge two queries
Tim Sturge
tsturge at metaweb.com
Wed Dec 5 21:12:36 UTC 2007
Hi Arthur,
There is some internal documentation; unfortunately we haven't
yet engaged a writer to include it into the MQL manual on freebase
itself.
Here is the internal documentation and a brief example:
Tim
---
/type/reflect
=============
/type/reflect provides MQL with limited introspection facilities. In
particular, if you have an object you can ask what properties it has
without needing to know the types of the property in advance.
Ideally, MQL would provide a single keyword (probably "any") which
would contain all attached objects and values. However due to
internal systematic limitations, you must ask for three distinct
properties to find everything attached to the node.
- /type/reflect/any_master
This lists all master properties attached to the node.
- /type/reflect/any_reverse
This lists all reverse properties pointing to the node.
- /type/reflect/any_value
This lists all values attached to the node, of any type.
It is common to combine /type/reflect/any_XXX with the "link"
directive. This allows you to enquire what property has been
located using the "master_property" default property of /type/link.
Caveats:
--------
Some of the properties of /type/object are specially implemented by
the system and will not appear when the object is reflected on.
In particular:
- /type/object/key (incoming keys)
- /type/namespace/keys (outgoing keys -- changed in bug 2353)
- /type/object/id (generated path)
- /type/object/guid (unique database identifier)
- /type/object/timestamp (object creation timestamp)
- /type/object/creator (user who created the object)
are *not* reflectable.
In fact, any attempt to reflect on /type/key or /type/id
will fail as they are system generated properties
- /type/object/type
- /type/object/permission
*are* reflectable, (in /type/reflect/any_master) as is
- /type/object/name
(in /type/reflect/any_value)
All 3 of these are expected to remain reflectable.
Examples:
=========
U2 master properties:
---------------------
{ "id": "/wikipedia/en/U2",
"/type/reflect/any_master": [ { "limit": 5, "id": null, "type": [],
"name": null, "link": null } ]
}
Response:
{
"\/type\/reflect\/any_master" : [
{
"id" : "#9202a8c04000641f8000000000000089",
"link" : "\/type\/object\/permission",
"name" : "Global Write Permission",
"type" : [ "\/type\/permission" ]
},
{
"id" : "#9202a8c04000641f8000000000066c98",
"link" : "\/common\/topic\/article",
"name" : null,
"type" : [ "\/common\/document" ]
},
{
"id" : "#9202a8c04000641f80000000011ae833",
"link" : "\/type\/object\/type",
"name" : "Musical Artist",
"type" : [ "\/type\/type" ]
},
{
"id" : "#9202a8c04000641f8000000000000565",
"link" : "\/type\/object\/type",
"name" : "Topic",
"type" : [ "\/type\/type" ]
},
{
"id" : "#9202a8c04000641f80000000011ae83f",
"link" : "\/type\/object\/type",
"name" : "Musical Group Member",
"type" : [ "\/type\/type" ]
}
],
"id" : "\/wikipedia\/en\/U2"
}
U2 has permission Global Write Permission, an article and the types
Musical Artist, Topic, and Musical Group Member.
U2 reverse properties:
----------------------
{ "id": "/wikipedia/en/U2",
"/type/reflect/any_reverse": [ { "limit": 5, "id": null, "type": [],
"name": null, "link": null } ]
}
Response:
{
"\/type\/reflect\/any_reverse" : [
{
"id" : "#9202a8c04000641f8000000002f65165",
"link" : "\/music\/album\/orig_artist",
"name" : "Boy",
"type" : [ "\/music\/album" ]
},
{
"id" : "#9202a8c04000641f8000000002f6578d",
"link" : "\/music\/album\/orig_artist",
"name" : "I Will Follow",
"type" : [ "\/music\/album" ]
},
{
"id" : "#9202a8c04000641f8000000002f65799",
"link" : "\/music\/album\/orig_artist",
"name" : "I Will Follow",
"type" : [ "\/music\/album" ]
},
{
"id" : "#9202a8c04000641f8000000002f65210",
"link" : "\/music\/album\/orig_artist",
"name" : "New Year's Day",
"type" : [ "\/music\/album" ]
},
{
"id" : "#9202a8c04000641f8000000002f65e4a",
"link" : "\/music\/album\/orig_artist",
"name" : "Two Hearts Beat as One",
"type" : [ "\/music\/album" ]
}
],
"id" : "\/wikipedia\/en\/U2"
}
Notice that the result of "link" is the master property (from album to artist).
U2 Values:
----------
{ "id": "/wikipedia/en/U2",
"/type/reflect/any_value": [ { "limit": 5, "value": null, "type": null, "link"
: null } ]
}
{
"\/type\/reflect\/any_value" : [
{
"link" : "\/type\/object\/name",
"type" : "\/type\/text",
"value" : "U2 (groupe)"
},
{
"link" : "\/type\/object\/name",
"type" : "\/type\/text",
"value" : "U2"
},
{
"link" : "\/type\/object\/name",
"type" : "\/type\/text",
"value" : "U2"
},
{
"link" : "\/type\/object\/name",
"type" : "\/type\/text",
"value" : "U2"
},
{
"link" : "\/type\/object\/name",
"type" : "\/type\/text",
"value" : "U2"
}
],
"id" : "\/wikipedia\/en\/U2"
}
Here we see the names of U2. Note that they are in different languages, even
though the lang is not part of the result.
{ "id": "/wikipedia/en/U2",
"/type/reflect/any_value": [ { "limit": 5, "value": null, "type": "/type/text"
, "lang": null, "link": null } ]
}
{
"\/type\/reflect\/any_value" : [
{
"lang" : "\/lang\/fr",
"link" : "\/type\/object\/name",
"type" : "\/type\/text",
"value" : "U2 (groupe)"
},
{
"lang" : "\/lang\/en",
"link" : "\/type\/object\/name",
"type" : "\/type\/text",
"value" : "U2"
},
{
"lang" : "\/lang\/de",
"link" : "\/type\/object\/name",
"type" : "\/type\/text",
"value" : "U2"
},
{
"lang" : "\/lang\/it",
"link" : "\/type\/object\/name",
"type" : "\/type\/text",
"value" : "U2"
},
{
"lang" : "\/lang\/ja",
"link" : "\/type\/object\/name",
"type" : "\/type\/text",
"value" : "U2"
}
],
"id" : "\/wikipedia\/en\/U2"
}
gives the languages, at the cost of restricting the output to values of /type/text only.
----- Original Message -----
From: "Arthur van Hoff" <AVH at zing.net>
To: "For discussions about MQL, Freebase API and apps built on Freebase" <developers at freebase.com>
Sent: Wednesday, December 5, 2007 8:49:34 AM (GMT-0800) America/Los_Angeles
Subject: Re: [Developers] Merge two queries
Is there an explanation of /type/reflect/any_reverse?
The best I can find is this:
http://www.freebase.com/view/guid/9202a8c04000641f80000000041ea213
-----Original Message-----
From: developers-bounces at freebase.com
[mailto:developers-bounces at freebase.com] On Behalf Of Sebastian Kurt
Sent: Wednesday, December 05, 2007 4:34 AM
To: For discussions about MQL,Freebase API and apps built on Freebase
Subject: Re: [Developers] Merge two queries
Thanks for your help, but it is not what i was looking for. Perhaps not
exactly defined by me. I will try again:
I query for ID's belonging to a <keyword>
{
"someids":{
"query":[{
"name":null,
"name~=":"<keyword>",
"type":[{
"id":null,
}]
}]
}
}
after that (extracting IDs with PHP), I query foreach ID what CATEGORY
it is in and whats its name:
{
"category":{
"query":[{
"/type/type/domain":{
"/type/reflect/any_reverse":[{
"name":null,
"type":"/freebase/domain_category"
}],
"name":null
},
"id":"myIdForKeyword",
"name":null
}]
}
}
Now the question is, if it is possible to merge both:
"Query for CATEGORIES (and name of given IDs) of a given <keyword>"
Examplequery for "id" == "/location/country",
{
"category" : {
"query" : [
{
"/type/type/domain" : {
"/type/reflect/any_reverse" : [
{
"name" : null,
"type" : "/freebase/domain_category"
}
],
"name" : null
},
"id" : "/location/country",
"name" : null
}
]
}
}
John Giannandrea schrieb:
>> Sebastian Kurt wrote:
>>> What should it do?
>>> "[1] answering ID an DOMAIN of <keyword>, ID is used in [2] (as
>>> myIdForKeyword) to ask for CATEGORY of it"
>>>
>
>
> it wasnt clear to me if you are trying to find a domain or a type.
> Here is an example of constraining both the domain name and the type
> name and getting the enclosing category. You can remove the
> constraints you dont want
> -jg
>
> {
> "query" : [
> {
> "domains" : {
> "name" : null,
> "name~=" : "film",
> "type" : "/type/domain",
> "types" : [
> {
> "name" : null,
> "name~=" : "director"
> }
> ]
> },
> "name" : null,
> "type" : "/freebase/domain_category"
> }
> ]
> }
>
>
> _______________________________________________
> Developers mailing list
> Developers at freebase.com
> http://lists.freebase.com/mailman/listinfo/developers
--
mailto:kurt at inf.fu-berlin.de
0179 7923088
http://vIdentity.de
http://skurt.de
_______________________________________________
Developers mailing list
Developers at freebase.com
http://lists.freebase.com/mailman/listinfo/developers
_______________________________________________
Developers mailing list
Developers at freebase.com
http://lists.freebase.com/mailman/listinfo/developers
More information about the Developers
mailing list