freebase api for sorting by city relevance

北城余情 提交于 2019-12-14 02:10:56

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/9989727/freebase-api-for-sorting-by-city-relevance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!