Python - 使用Google Maps API检查城市名称的拼写

时间:2013-06-06 21:32:55

标签: python google-maps spell-checking

我有大约10万个独特的城市名称,其中许多都有拼写错误(糟糕的扫描,糟糕的ocr,许多带有特殊字符的欧洲名字等等)。我可以在python中编写一个循环来逐个用谷歌地图检查城市,看看拼写是否正确吗?例如。如果我发送“nev york”,我想收到类似“你的意思是:纽约”的内容。我已经做了很多事情,比如匹配列表,然后计算levenshtein距离等。

2 个答案:

答案 0 :(得分:0)

我刚刚发现了difflib非常酷的东西。

它几乎像拼写检查一样

>>> import difflib
>>> x = 'smoke'
>>> y = ['choke','poke','loc','joke','mediocre', 'folk']
>>>
>>> difflib.get_close_matches(x,y)
['poke', 'joke', 'choke']


>>> x = 'nev york'
>>> y = ['New York', 'Compton', ' Phoenix']
>>> difflib.get_close_matches(x,y)
['New York']

唯一的另一部分是将所有城市正确拼写到列表中......或者找一个拥有“拼写正确的城市”单词文件的人

答案 1 :(得分:0)

嗯......好吧。这是一种不同的方法

from selenium import webdriver
from selenium.webdriver.common.keys import Keys


def setup():
    driver = webdriver.Chrome()
    driver.get("http://maps.google.com")
    return driver

def spelledCorrectly(driver, maybeMisspelled):
    searchBox = driver.find_element_by_name('gbqfq')
    searchBox.send_keys(maybeMisspelled)
    ref = driver.find_element_by_id('refsec')

    if ref.text == u'':
        print "Spelled Correctly"
    else:
        print ref.text


if __name__ == "__main__":
     driver = setup() #pass this object into spelledCorrectly
     spelledCorrectly(driver,"schenekctity")

运行setup()一次,然后对任何单词运行spelledCorrectly()

例如......

driver = setup()
for item in giant_misspelled_list_of_cities:
     spelledCorrectly(driver, item)