【问题标题】:Seemingly empty result from Freebase mql_output searchFreebase mql_output 搜索的看似空的结果
【发布时间】:2014-10-19 03:24:17
【问题描述】:

我正在尝试在 Freebase 中搜索化学元素的名称并返回其原子质量,并且我正在尝试使其与查询和 mql_output 一起使用。

这是我的代码:

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))

这是我在日志中得到的输出:

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': []}

我正在寻找的那个,唯一具有.../atomic_mass 属性的“氦”应该给我原子质量,对吧?

相反,它只是说“无”,而如果您查看Freebase,它肯定具有与之相关的原子质量属性。不过,其他“Helium”只是返回空方括号,所以至少看起来我正在寻找的 Helium 有 something ;我就是不明白。

知道这里发生了什么吗?

非常感谢。

【问题讨论】:

    标签: python freebase


    【解决方案1】:

    您应该检查架构,不仅要查看要查询的类型和属性,还要查看结果的预期类型。

    在这种情况下,预期的类型是 https://www.freebase.com/chemistry/atomic_mass?schema=,它是一个包含两个值但没有名称的对象(因此是“无”结果)。

    您可以只将 [] 更改为 [{}],但如果这不起作用,请查询您(或两者)感兴趣的“质量”或“不确定性”中的哪一个

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-06
      • 1970-01-01
      • 1970-01-01
      • 2014-11-28
      • 1970-01-01
      • 2015-05-06
      相关资源
      最近更新 更多