[Developers] Freebase newbie: simple question

Shawn Simister narphorium at gmail.com
Thu Feb 26 00:32:00 UTC 2009


Vishal Talwar wrote:
> According to Wikipedia:
>
> "The postal abbreviation is same as ISO 3166-2 subdivision code for 
> all fifty states."
>
> We hold the ISO 3166-2 subdivision code on the property 
> /location/administrative_division/iso_3166_2_code. Values should be of 
> the form "US-[state code]" for all US states, so the transformation 
> seems pretty straightforward from there.
>
> Hope that helps,
> Vishal
>
In MQL that would look like this:

{
    "country" : {
        "id" : "/en/united_states"
    },
    "iso_3166_2_code" : null,
    "name" : "Massachusetts",
    "type" : "/location/administrative_division"
}

You can try this query out in the Query Editor Tool 
<http://www.freebase.com/tools/queryeditor?q=%7B%22country%22:%7B%22id%22:%22/en/united_states%22%7D,%22iso_3166_2_code%22:null,%22name%22:%22Massachusetts%22,%22type%22:%22/location/administrative_division%22%7D&read=1>. 
Or you can fetch the data directly from your rails apps with the 
following code:

require 'net/http'

query_string = 
'{"query":{"country":{"id":"/en/united_states"},"iso_3166_2_code":null,"name":"Massachusetts","type":"/location/administrative_division"}}'
query_uri = 
URI.parse('http://www.freebase.com/api/service/mqlread?query=' + 
URI.escape(query_string))
result = Net::HTTP.get(query_uri)

Then it's just a matter of parsing the JSON, getting the value of 
iso_3166_2_code and removing the "US-" from the beginning.

Shawn

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freebase.com/pipermail/developers/attachments/20090225/0c5dfd35/attachment.htm 


More information about the Developers mailing list