Search code examples
apierror-handlingreversefreebasemql

How to invert the MQL query (for freebase)?


I am trying to list all the types for a particular id:

{
  "id": "/en/sony",
  "type": [{
    "name": "Topic",
    "id": null
  }]
}

This query giving me the following result: http://tinyurl.com/lubavey

{
  "result": {
    "type": [
      {
        "id": "/common/topic",
        "name": "Topic"
      },
      {
        "id": "/base/audiobase/topic",
        "name": "Topic"
      },
      {
        "id": "/base/fblinux/topic",
        "name": "Topic"
      },
      {
        "id": "/base/digitalcameras/topic",
        "name": "Topic"
      },
      {
        "id": "/base/popstra/topic",
        "name": "Topic"
      },
      {
        "id": "/base/televisions/topic",
        "name": "Topic"
      },
      {
        "id": "/base/ps3games/topic",
        "name": "Topic"
      },
      {
        "id": "/base/filmcameras/topic",
        "name": "Topic"
      },
      {
        "id": "/m/04mny2g",
        "name": "Topic"
      }
    ],
    "id": "/en/sony"
  }
}

I want exactly the opposite result. I want all the types which do not have name as "Topic" with them. How can I achieve this? I tried to use ! operator with property name which is suggested in reference guide of MQL, but it's giving me error:

"Can't use unqualified property names with ! reversing".

What should I do to remove this error with ! and to obtain opposite result of the query?


Solution

  • Try with !=:

    {
      "id": "/en/sony",
      "type": [{
        "name!=": "Topic",
        "id": null
      }]
    }
    

    The != operator says that the constrained property can be anything but the specified value. (It does require that the property be something, however: it does not match object for which the property is null.)

    Read more about != operator here: http://wiki.freebase.com/wiki/MQL_operators#The_.22but_not.22_Operator_.21.3D