[Developers] Freebase newbie: simple question

Tom Morris tfmorris at gmail.com
Thu Feb 26 03:11:32 UTC 2009


Wow, popular question!  A few tidbits that haven't been mentioned already:

- There's a type /location/us_state which is more specific than
/location/administrative_division for your needs
- To anchor a text search to the beginning of the name, use "^"  e.g. "^mass*"
- If you want search both the primary name and the aliases, you'll
need to get a little fancier than the query that Shawn gave.  I think
there's an example in the MQL cookbook which shows querying either/or

But more important than all of the above, Freebase is waaayy overkill
for this.  A simple three column table/text file with 55 or so
lines/rows would be much more efficient.

Tom

On Wed, Feb 25, 2009 at 9:11 PM, Shawn Simister <narphorium at gmail.com> wrote:
> 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". 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 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
>
>
> _______________________________________________
> Developers mailing list
> Developers at freebase.com
> http://lists.freebase.com/mailman/listinfo/developers
>
>


More information about the Developers mailing list