开发者

What are some ways to extract a location from a sentence/query?

I want to recognize and extract a location that's built into a sentence. 开发者_如何学PythonFor example I might have a sentence:

"I love the pizza in Boston, Ma." but this same sentence could also be written as "Pizza in Boston, I love it." OR "I love the pizza in Boston."

So I have to be able to find it anywhere in the sentence and also if the state is not included. To makes things even more complicated people do things like ft. or s. for fort or south so I need a way to recognize these as well.


How about parse each word in the sentence and check against a "location" dictionary? After a hit, secondary tests could include the word before/after to complement the location with a corresponding city (word before) or state (word after).

This will get tricky for things like "The best Buffalo Wings in Kansas City"; When you find multiple locations in a single statement, you could use a seperate "dual-use" dictionary to eliminate words like "Buffalo". You could also search for prepositions like "in", "near", "at", etc. to identify the real location.


I've had pretty good luck using alchemyapi to extract celebrity names from sentences - you might want to see if their entity extraction will do what you need (looking at the example on the bottom of that page, it just might).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜