0

How can I get list of alias from the query with the name in freebase using a python?

For example, this query

[{
  "name": "citigroup",
  "/common/topic/alias": []
}]

gives

{
  "result": [
    {
      "/common/topic/alias": [
        "Citigroup Inc.",
        "TRAVELERS GROUP INC",
        "CITIGROUP INC",
        "TRAVELERS INC",
        "Citi"
      ],
      "name": "Citigroup"
    },
    {
      "/common/topic/alias": [],
      "name": "Citigroup"
    }
  ]
}

I want a list

["Citigroup Inc.",
"TRAVELERS GROUP INC",
"CITIGROUP INC",
"TRAVELERS INC",
"Citi"]

I tried with

service_url = 'https://www.googleapis.com/freebase/v1/search'
query = {   "name": "citigroup", "/common/topic/alias": []}

params = [{ 'query': json.dumps(query), 'key': key, 'limit':5}]

url = service_url + '?' + urllib.urlencode(params)
response = json.loads(urllib.urlopen(url).read())

But the response does not produce anything... Any help will be greatly appreciated! Thanks

Josh Cho
  • 159
  • 1
  • 13

1 Answers1

0

try this code

import urllib, json

service_url = 'https://www.googleapis.com/freebase/v1/mqlread'
query = [{ "name": "citigroup", "/common/topic/alias": []}]

params = { 'query': json.dumps(query), 'key': key, 'limit':5}

url = service_url + '?' + urllib.urlencode(params)
response = json.loads(urllib.urlopen(url).read())
print response

Basically the query should be asked in the list form as there are more than one result for this query and not into dictionary form.

Gunjan
  • 2,665
  • 23
  • 29