Help Center » Developing Applications » The MQL Cookbook » Perform transitive queries

Perform transitive queries

Let's say you want to find all the Freebase users who live in the USA, but they have their locations set to things like "San Francisco" or "New Orleans".  How do you ask for "USA, and anything within the USA"?

While MQL doesn't currently support transitive closure, the /location/
location/containedby property model was designed to make the type of
query you are attempting to write possible. When creating /location/
location topics the idea is to provide (at least) two levels of
hierarchical containment in the containedby property. For example,
in the US, cities should specify what county they are in as well as
what state they are contained in.

As your query indicates universities should be co-typed as locations
and should specify the city they are contained in. Using the two-
level of hierarchy containment model, cities should be contained in
states, and similarly states should be contained in the US.
Therefore, you should be able to get what you are looking for with
the query:

#Note: the ID for the US /guid/9202a8c04000641f8000000000959f60
{
"query":[{
"/location/location/containedby":[{
"/location/location/containedby":[{
"/location/location/containedby":[{
"id":"/guid/9202a8c04000641f8000000000959f60"
}],
"name":null
}],
"name":null
}],
"name":null,
"type":"/education/university"
}]
}

Someday, MQL will probably handle transitivity operations - but until
then it is possible to construct queries which utilize the
containment models based on some minimal assumptions about the data.
I am happy to work with you (and others) to make sure the data
conforms to these minimal assumptions to meet your needs.

 

Recent Discussions about Perform transitive queries

There are no conversations on this topic. Would you like to start one?

Start the Discussion

Related Help Topics

empty