MQL Recipes

From Freebase

Jump to: navigation, search

This page contains a list of recipes for common needs using the MQL query language.

Feel free to add your own!

Contents

Constrain Numeric and Date Properties

Use >, <, >=, or <= after the property ID.

Example 1:

   [{
     "type": "/chemistry/chemical_element",
     "name": null,
     "/chemistry/chemical_element/atomic_mass": {
       "mass<": 10,
       "mass": null
     }
   }]

Example 2:

   [{
     "type": "/film/actor",
     "name": null,
     "/people/person/date_of_birth>": "1970",
     "/people/person/date_of_birth": null
   }]

Counts Results

Use "return" : "count" or "count" : null on the query node you want to count.

Example 1: Counting the number of outermost results

   [{
     "type" : "/language/human_language",
     "return" : "count"
   }]

Example 2: Counting the number of inner nodes for each outer result

   [{
     "type": "/business/company",
     "name": null,
     "founders" : [{
       "return": "count"
     }]
   }]

Getting the Language of a String Value

Use [{ "value" : null, "lang" : null }].

Example:

   [{
     "type": "/location/continent",
     "name": [{
       "value": null,
       "lang": null,
       "limit": 5
     }]
   }]

Match String Properties Against a Pattern

Use ~= after the property ID.

Example:

   [{
     "type": "/film/actor",
     "name~=": "Christian *",
     "name": null
   }]

Require that Property does not Exist

Use "optional" : "forbidden". MQL also requires that you include some other property in the same query node.

Example: Planets without anything (say, a moon) orbiting them

   [{
     "type": "/astronomy/planet",
     "name": null,
     "/astronomy/orbital_relationship/orbited_by": [{
       "id": null,
       "optional": "forbidden"
     }]
   }]
Personal tools