freebase API根据城市相关性排序 [英] freebase api for sorting by city relevance

查看:147
本文介绍了freebase API根据城市相关性排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个查询,我想要返回给定国家的所有城市。



这很好,除了我想调整一下以便按大小或任何重要性的顺序排序以避免100的限制。我希望前100个城市拥有一个人可能选择的最有可能的城市。 (人口,或?)

  [{
/ location / country / iso3166_1_alpha2:US,
/ location / location / contains:[
id:null,
name:null,
/ location / statistical_region / population:{number :null,date:null}
type:/ location / citytown
]
}]

这种方法很有效,但速度很慢,因为它必须计算所有包含的元素:

 <$ [
/ location / country / iso3166_1_alpha2:US,
/ location / location / contains:[
id:null,
name:null,
type:/ location / citytown,
/ location / location / contains:{return:count}
sort : - / location / location / contains.count
]
}]

我试过包括 / location / statistical_region / population ,但没有太多的运气,有什么想法?

解决方案

你可以在两个阶段做到这一点。首先,您可以像使用MQL一样使用MQL通过ISO代码查看国家/地区:

  {
/ location / country / iso3166_1_alpha2:US,
mid:null,
name:null
}

然后,一旦您了解该国的MID,就可以使用搜索API获取该国100个最相关城市的排名列表像这样

 过滤器:(所有类型:/位置/ citytown部分:/ m / 09c7w0)
code>

这是使用搜索API 过滤器语法和特殊的 Metaschema 谓词寻找美国境内的实体国家(/ m / 09c7w0)。这是特别有用的,因为Search API理解/ location / location / contains是一个传递属性,所以它将查看美国包含的任何实体,即使该包含在Freebase图中的深度超过一个级别。

I have a query where I would like to return all the cities for a given country.

That works fine except I would like to also tweak so to sort it by size or any order of significance to avoid the 100 limit. I would like the first 100 cities to have the most likely cities a person might choose listed first. (population, or?)

[{
  "/location/country/iso3166_1_alpha2": "US",
  "/location/location/contains":[
    "id" : null,
    "name" : null,
    "/location/statistical_region/population" : { "number" : null, "date" : null }
    "type" : "/location/citytown"
  ]
}]​

This works but is very slow as it has to count all the contained elements:

[{
  "/location/country/iso3166_1_alpha2": "US",
  "/location/location/contains":[
    "id" : null,
    "name" : null,
    "type" : "/location/citytown",
    "/location/location/contains":{"return": "count"}
    "sort": "-/location/location/contains.count"
  ]
}]​

I tried including /location/statistical_region/population but without much luck, any ideas?

解决方案

You can do this in two stages. First, you can look up the country by ISO code using MQL like you did above:

{
  "/location/country/iso3166_1_alpha2": "US",
  "mid":           null,
  "name":          null
}​

Then once you know the MID for the country, you can use the Search API to get a ranked list of the 100 most relevant cities in that country like this.

filter: (all type:/location/citytown part_of:/m/09c7w0)

This is using the Search API filter syntax and the special Metaschema predicates to find entities which are contained within the United States (/m/09c7w0). This is especially useful because the Search API understands that /location/location/contains is a transitive property and so it will look at any entity which is contained by the United States even if that containment is more than one level deep in the Freebase graph.

这篇关于freebase API根据城市相关性排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆