[Developers] Freebase newbie: simple question
Shawn Simister
narphorium at gmail.com
Thu Feb 26 02:11:06 UTC 2009
Pito,
I haven't used Httparty before but its looks like a very useful gem
given that it can download a URI and parse the JSON all in one call.
There are two ways to find states that match "mass". The first way would
be to constrain the query that I gave earlier using an MQL filter like this:
[
{
"country" : {
"id" : "/en/united_states"
},
"iso_3166_2_code" : null,
"name" : null,
"filter1:name~=" : "Mass*",
"type" : "/location/administrative_division"
}
]
The other way is to query the /common/topic/alias property like this:
[
{
"/common/topic/alias" : "Mass.",
"country" : {
"id" : "/en/united_states"
},
"iso_3166_2_code" : null,
"name" : null,
"type" : "/location/administrative_division"
}
]
The benefit of using the alias property is that it will also match
non-trivial aliases like "Sunshine State"
<http://www.freebase.com/tools/queryeditor?q=%5B%7B%22/common/topic/alias%22:%22Sunshine%20State%22,%22country%22:%7B%22id%22:%22/en/united_states%22%7D,%22iso_3166_2_code%22:null,%22name%22:null,%22type%22:%22/location/administrative_division%22%7D%5D&read=1>.
The down-side is that a lot of the common aliases haven't been entered
into Freebase yet so you might have to add them in by yourself to get it
to a usable level of accuracy (I had to manually add "Mass." as an alias
to Massachusetts <http://www.freebase.com/view/en/massachusetts> to make
the 2nd query work).
Shawn
Pito Salas wrote:
> Hi Shawn
>
> Do you know the httparty gem. It makes it really easy to do what we need here.
>
> So... What if I wanted any US states that have the letters "mass" in
> their name? Is there magic syntax for thatz?
>
> Thanks again!
>
> Pito
>
>
>> 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
>>
>>
>> _______________________________________________
>> Developers mailing list
>> Developers at freebase.com
>> http://lists.freebase.com/mailman/listinfo/developers
>>
>>
>>
> _______________________________________________
> Developers mailing list
> Developers at freebase.com
> http://lists.freebase.com/mailman/listinfo/developers
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freebase.com/pipermail/developers/attachments/20090225/7e3d6723/attachment.htm
More information about the Developers
mailing list