问题描述
我正在开发基于IATA- codeS需要查找国家codeS(ISO-3166的α2)的应用程序(http://en.wikipedia.org/wiki/IATA_airport_$c$ C)。
是否有一个(preferably免费)API是什么?
我在这里提交一个不完整的解决方案,无论是作为的方式来解决手头的国际航空运输协会对Contry- code的问题,并把注意力什么可能是结构化的内容一个未被充分利用的资源:我说的是
这是在这个意义上不完整的,并非所有的IATA codeS包括(但我猜较高的覆盖率),或者不是所有的都分配给他们(唉更经常发生的)一个国家code
我要建议的API是。结果
这项免费服务通过发送与前presses在MQL(查询的Metaweb语言)查询参数HTTPS请求,接收一个JSON对象与理想的效果。
具体的要求看起来像
<$p$p><$c$c>https://www.googleapis.com/freebase/v1/mqlread?indent=2&query=[{\"type\":\"/aviation/airport\",\"id\":null,\"limit\": 25日,名:空,排序:姓名,国际航协:证券及期货条例,/位置/位置/ containedby:[{限制:6,名:空,可选 :真正的排序:姓名,/位置/国家/ iso3166_1_alpha2:[{限制:6,可选:假的,排序:价值,价值:空}]} ],airport_type:[{限制:3,名:空,可选:真实的排序:姓名,类型:/航空/ airport_type}]}]^ - 在这里放置IATA code
为便于阅读,我展示与多行缩进相应的MQL;同样的事情上面只有更好的布局。
[{
类型:/航空/机场
ID:空,
限制:25,
名:空,
排序:名字, 国际航协:证券及期货条例, - &LT;&LT;&LT;这就是你放置所需的IATA code /位置/位置/ containedby:[{
限制:6,
名:空,
可选:真实,
排序:名字,
/位置/国家/ iso3166_1_alpha2:[{
限制:6,
可选:假的,
排序:值
值:空
}]
}],
airport_type:[{
限制:3,
名:空,
可选:真实,
排序:名字,
类型:/航空/ airport_type
}]
}]
和响应如下所示:
{
结果:
{
名:旧金山国际机场
国际航协:证券及期货条例,
/位置/位置/ containedby:[
{
名:美利坚合众国,
/位置/国家/ iso3166_1_alpha2:[
{
值:US
}
]
}
]
airport_type:[
{
类型:/航空/ airport_type
名:公共
}
]
类型:/航空/机场
ID:/ EN / san_francisco_international_airport
}
]
}
结果
此溶液通过钻入游离碱怃,在大约30分钟
/航空/机场
键入和使用各种工具,我简要描述如下。结果
注意这是一个通用的办法,适用于各种疑问:不是机场的IATA codeS匹配ISO国家codeS,我们可以,例如,获取列表桥梁在1950年之前建立一个跨度超过500英尺,查找出生在一个给定的城市等著名的音乐家。此外,据我所知,游离碱API和信息是免费提供的。要注意,然而,也有一些限制(和一些优势!)在游离碱中发现的内容作为与从专门来源获得了比较。结果,
从游离碱获得的信息可能不如权威的,完整的或电流作为与从专门源API和数据提取获得。这种限制说话的协作,类似wiki的,时尚的游离碱云集,由多数志愿者工作队的资料的准通用广度,较集中,常为单发,意,收集通过各种贸易有偿专业人员进行信息组织,如,说IATA或国际海事组织(IMO)。另一方面,游离碱,用数据的语义重新presentation,提供了强有力的方式连接的信息比特的方法。由此,权威来源大部分提供表格的数据,游离碱查询可以匹配的信息明显无关的部分。例如,由此可能IMO产生的海港城市名单及其年度吨位,其数量和终端等,游离碱还可以找到,比如,被枪杀在这些端口或谁在那里出生的著名作家的电影。结果
结果
但足以与信息披露,让我们来看看一个人如何能产生这些查询结果。
- 首先仔细阅读那种在,所需项目以熟悉哪些网站有这方面的报价,并获得一个非正式的感觉可用于此类项目的信息的广度和深度。结果
例如,可以窥视到发现的各种机场的键入的上游离碱 - 一旦需要的是确定项目的类型(S),我们可以看看他们的模式(S)(多种方式到那里,例如链接在页面底部)结果
下面是我们的例子架构。 - 的架构显示收集什么信息字段给定类型。但要小心,虽然模式可以比较完整和复杂的,相应类型的单个实例可能不是所有有这些字段正确填写的:与非正式确认的特设的实例或列表评论作为实例解释如下。
- 返回实例列表中查看并通过添加和删除列来修改这一观点。这样做是,分别与橙色的+按钮上的列表中的左上方,并与小X按钮旁边的每个列标题。结果
请参阅添加新列一节中所示的树是如何允许向下钻取,我们与连接到它的类型或启动类型的模式(pressing的+后会显示)。结果
在机场的情况下,我很快就删除了图像,文章和航空公司相关的领域,以腾出空间,并加入国际航协code和钻在位置找到国家和从那里ISO code。这种连接到国家是一个有点棘手,我不得不寻找到这本身就是另一种位置,由含有,并使用更多提出了国家的类型。 - 一旦你有一个表格列表,以及所需的字段,并可能与使用进行审查的目的了一些额外的字段,您可以通过选择在使用数据MQL链接导出相应的MQL code这个集,在页面的底部。这将弹出一个窗口,您可以复制MQL片段,虽然它可能是更好的进入到。 (您可能还需要复制MQL code和它粘贴到编辑器中,由于与不提起这MQL应用程序中的错误时,pressing在查询编辑器视图按钮)
- 查询编辑器提供了调整初始/默认查询并测试它的便捷方式。您可能需要熟悉,所以一般是相当直观。
- 当查询产生的precisely我们需要的,是时候让它一个班轮,它可以再URL里面使用游离碱MQL(在编辑器屏幕的底部格式化方便的按钮)阅读服务(见这个答案顶部的例子)。
- 更有点测试和调整(例如战斗偶尔错别字引入的JSON语法错误,同时复制/编辑字符串的URL)等......瞧!
- 其实有很多更可与游离碱使用客户端库,以方便与MQL服务集成。
我想用下面的建议来完成:不是这个在线API集成到应用程序中,有时可能下载完整的清单,并用它创建一个本地数据库。以这种方式有可能通过增加行和/或填充空列于补充数据。这种方法特别适用于国际航空运输协会/机场例子-after机场的所有名单及其基本codeS相对较小,不会改变所有frequently-。当然,可能需要本地数据库的这种方法被刷新,并以其他方式保持偶尔,但它消除了在线,实时,连接到游离碱的要求。
I'm developing an app that needs to look up country codes (ISO-3166 alpha2) based on IATA-codes (http://en.wikipedia.org/wiki/IATA_airport_code).
Is there an (preferably free) API for that?
I'm submitting here a incomplete solution, both as way to address the IATA-to-Contry-Code question at hand, and to bring attention to what may be a underused resource for structured content: I'm talking about Freebase !
This is incomplete in the sense that not all IATA codes are included (though I'm guessing a relatively high coverage) or not all have a country code assigned to them (alas a more common occurrence).
The API I wish to suggest is the Freebase MQL Read Service.
This free service works by sending an HTTPS request with a parameter that expresses a query in MQL (Metaweb Query Language), and receiving a JSON object with the desired results.
Specifically the request looks like
https://www.googleapis.com/freebase/v1/mqlread?indent=2&query=[{"type":"/aviation/airport","id":null,"limit": 25,"name":null,"sort":"name","iata": "SFO", "/location/location/containedby": [{"limit":6,"name":null,"optional": true,"sort":"name","/location/country/iso3166_1_alpha2": [{ "limit":6, "optional": false, "sort":"value", "value":null}]}],"airport_type": [{"limit":3,"name":null,"optional": true,"sort":"name","type":"/aviation/airport_type"}]}]
^--- here place the IATA code
for readability I'm showing the corresponding MQL with indentation on multiple lines; same thing as above only better layout.
[{
"type": "/aviation/airport",
"id": null,
"limit": 25,
"name": null,
"sort": "name",
"iata": "SFO", -- <<< that's where you place the desired IATA code
"/location/location/containedby": [{
"limit": 6,
"name": null,
"optional": true,
"sort": "name",
"/location/country/iso3166_1_alpha2": [{
"limit": 6,
"optional": false,
"sort": "value",
"value": null
}]
}],
"airport_type": [{
"limit": 3,
"name": null,
"optional": true,
"sort": "name",
"type": "/aviation/airport_type"
}]
}]
And the response looks like the following:
{
"result": [
{
"name": "San Francisco International Airport",
"iata": "SFO",
"/location/location/containedby": [
{
"name": "United States of America",
"/location/country/iso3166_1_alpha2": [
{
"value": "US"
}
]
}
],
"airport_type": [
{
"type": "/aviation/airport_type",
"name": "Public"
}
],
"type": "/aviation/airport",
"id": "/en/san_francisco_international_airport"
}
]
}
This solution was "whipped-up" in approximately 30 minutes by drilling into the Freebase /aviation/airport
type and using various tools I describe briefly below.
Note that this is a generic approach, applicable to various queries: rather than matching IATA airport codes to ISO country codes, we could, for example, get the list of the bridges build before 1950 with a span exceeding 500 feet, or look up the famous musicians born in a given city etc. Furthermore, AFAIK, the Freebase API and information is freely available. Beware, however, that there are some limitations (and some advantages!) to the content found at Freebase as compared with that obtained from specialized sources.
The information obtained from Freebase may not be as authoritative, complete or current as that obtained with APIs and Data Extracts from specialized sources. This limitation speaks to the quasi universal breadth of the information gathered at Freebase in a collaborative, wiki-like, fashion, by a mostly volunteer task force, compared with the focused, often single-purposed, information gathering performed by paid professionals at various trade organizations such as, say the IATA or the International Maritime Organization (IMO). On the other hand, Freebase, with its semantic representation of the data, provides ways of connecting bits of information in powerful ways. Whereby the authoritative sources provide mostly "tabular" data, Freebase queries can match apparently unrelated pieces of information. For example, whereby the IMO probably produces lists of seaports with their annual tonnage, their number of terminals and such, Freebase can also find, say, the films that were shot in these ports or the famous writers who were born there.
But enough with disclosures, let's see how one can produce these queries
- First peruse the kind of desired items on Freebase, to get familiar with what the site has to offer in this area, and get an informal "feel" for the breadth and depth of the information available for this kind of items.
For example, one may peek into various airport instances found for the Airport Type on Freebase - Once the type(s) of items desired is identified, one can look into their schema(s) (many ways to get there, for example link at bottom of page)
Here's the schema for our Airport Type example. - The schema shows what fields of information are collected for a given type. Beware however that while the schema can be relatively complete and elaborate, the individual instances of the corresponding type may not all have these fields properly filled-in: verify informally with ad hoc reviews of instances or with lists of instances as explained below.
- Return to the list of instances view and modify this view by adding and removing columns. This is done, respectively, with the orange "+" button on the top left of the list and with the small "x" button next to each column header.
See how the tree shown in the "Add new column" section (shown after pressing the "+") allows drilling down the schema of the type that we start with or of types connected to it.
In the case of Airports, I quickly removed the "image", "article" and "airline"-related fields, to make room, and added the IATA code, and drilled in the "Location" to find the Country and from there the ISO code. This connection to "Country" was a bit tricky, I had to look into the "Contained by" which itself is another "Location" and, using the "More" brought up the "Country" type. - Once you have a tabular listing, with the desired fields, and maybe with a few extra fields used for review purposes, you can export the corresponding MQL code by picking the "MQL" link in the "Use Data from this Collection", at the bottom of the page. This pops-up a window where you can copy the MQL snippet, although it is probably better to proceed to the Query Editor. (You may still need to copy the MQL code and paste it back into the editor, due to a bug with the application which doesn't bring that MQL when pressing the "View in Query Editor" button)
- The query editor provides a convenient way of tweaking this initial/default query and testing it. You may need to get familiar with MQL language, it is generally rather intuitive.
- When the query produces precisely what we need, it is time to to make it a "One-liner" (formatting convenience button at bottom of editor screen) which can then be used inside a URL to the Freebase MQL Read service (see example at the top of this answer).
- A bit more testing and tweaking (e.g. fighting the JSON syntax errors occasionally introduced by typos while copying/editing the string to the URL) et... Voila !
- There is actually a lot more that can be done with Freebase, for example using the Google Client Library to facilitate the integration with the MQL service.
I'd like to finish with the following suggestion: Rather than integrating this online API to your application, it is sometimes possible to download the complete list and to create a local database with it. In this fashion it may be possible to complement the data by adding rows and/or filling empty columns. This approach is particularly applicable to the IATA/Airport example -after all the list of airports and their underlying codes is relatively small and does not vary all that frequently-. This approach of course may require the local DB to be refreshed and otherwise maintained occasionally, but it removes the requirement of the online, real-time, connection to Freebase.
这篇关于国际航空运输协会对国家API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!