Reputation: 1567
I'm trying to search Freebase for the name of a chemical element and return its atomic mass, and I'm trying to get that to work with a query and an mql_output.
Here's my code:
service_url = 'https://www.googleapis.com/freebase/v1/search'
params = {
'query': 'Helium',
'key': freebase_key,
'mql_output': '{"name":[],"/chemistry/chemical_element/atomic_mass":[]}',
'limit': '5'
}
url = service_url + '?' + urllib.urlencode(params)
response = json.loads(urllib.urlopen(url).read())
for result in response['result']:
logging.info('Result: {}'.format(result))
This is the output I get in the logs:
Result: {u'relevance:score': 107.16467299999999, u'name': [u'Helium'], u'/chemistry/chemical_element/atomic_mass': [None]}
Result: {u'relevance:score': 39.270966000000001, u'name': [u'Helium-3'], u'/chemistry/chemical_element/atomic_mass': []}
Result: {u'relevance:score': 38.038089999999997, u'name': [u'Liquid helium'], u'/chemistry/chemical_element/atomic_mass': []}
Result: {u'relevance:score': 32.367195000000002, u'name': [u'Isotopes of helium'], u'/chemistry/chemical_element/atomic_mass': []}
Result: {u'relevance:score': 28.453569000000002, u'name': [u'Star'], u'/chemistry/chemical_element/atomic_mass': []}
The one I'm looking for, the only "Helium" that has the .../atomic_mass property associated with it, should give me the atomic mass, right?
Instead, it just says "None", while, if you look at Freebase, it definitely has the atomic mass property associated with it. The other "Helium"s just return empty square brackets, though, so at least it seems like the Helium I'm looking for has something there; I'm just not getting it.
Any idea what's going on here?
Thanks a lot.
Upvotes: 1
Views: 41
Reputation: 10540
You should check the schema to see not only what types and properties to query for, but also what the expected type of the result is.
In this case, the expected type is https://www.freebase.com/chemistry/atomic_mass?schema= which is an object containing two values, but no name (thus the "None" result).
You may be able to just change the [] to [{}], but if that doesn't work, query for whichever of "mass" or "uncertainty" is of interest to you (or both)
Upvotes: 1