views:

89

answers:

3

I'd like to find a way to take a piece of user supplied text and determine what addresses on the map are mentioned within the text. I'd be happy to use a free web service if it exists or use a script which will not consume too many resources.

One way I can imagine doing this is taking a gigantic database of addressing and searching for each of them individually in the text, but this does not seem efficient. Is there a better algorithm or technique one can suggest?

My basic idea is to take the location information and turn it into markers on a Google Map. If it is too difficult or CPU intensive to determine the locations automatically, I could require users to add information in a location field if necessary but I would prefer not to do this as some of the users are going to be quite young students.

This needs to be done in PHP as that is the scripting language available on my school hosted server.

Note this whole set-up will happen within the context of a Drupal node, and I plan on using a filter to collect the necessary location information from the individual node, so this parsing would only happen once (when the new text enters the database).

+1  A: 

If you did have a gigantic list of locations in a relational database, and you're only concerned about 500 to 1000 words, then you could definitely just pass the SQL command to find matches for the 500-1000 words and it would be quite efficient.

But even if you did have to call a slow API, you could feasibly request for 500 words one by one. If you kept a cache of the matches, then the cache would probably quickly fill up with all the stop words (you know, like "the", "if", "and") and then using the cache, it'd be likely that you would be searching much less than 500 words each time.

I think you might be surprised at how fast the brute force approach would work.

Ray Hidayat
I suppose I could start by ignoring all words less than 3 characters long...that would improve performance slightly.
David Wees
+2  A: 

You could get something like opencalais to tag your text. One of the catigories which it returns is "city" you coud then use another third party module to show the location of the city.

Jeremy French
Although both answers are technically correct, this one seems like a lot less work on my part. Even better, there is apparently a Calais Geo module which does almost exactly what I want.
David Wees
A: 

For future reference I would just like to mention the Yahoo API called Placemaker and the service GeoMaker that is built on top of it.

Those tools can be used to parse out locations from a text as requested here. Unfortunately no Drupal module seems to exists right now- but a custom solution seems easy to code.

VoxPelli