2012-08-27 40 views

回答

2

如果我必須這樣做,我會嘗試根據使用谷歌圖像或其他人的單詞搜索圖像,並識別前n個結果的最常見的顏色。

0

這聽起來像一個非常合理的自然語言處理問題,並且通過map-reduce很容易處理。

確定您稱爲顏色的單詞和短語列表['blue','green','red',...]。 查看句子的大部分語料庫以及提及特定顏色的句子,對於該句子中的其他每個詞,請在文件中記下(word, color_name)。 (地圖步驟)

那麼你已經在你的陰莖看到每一個字,聚集你已經看到了它要達到這樣的{'cucumber': {'green': 300, 'yellow': 34, 'blue': 2}, 'tomato': {'red': 900, 'green': 430'}...}的所有顏色(reduce步驟)

只要你使用一個足夠大的語料庫(東西像維基百科),你會弄清楚如何修剪真正的小數字,稀有詞彙,你應該能夠製作相當全面和強大的詞典,將數百萬種物品映射到它們的顏色上。

0

另一種方法是在谷歌中進行文本搜索以獲得有關顏色和單詞的組合並採用最高數量的結果組合。下面是一個快速的Python腳本:

import urllib 
import json 
import itertools 

def google_count(q): 
     query = urllib.urlencode({'q': q}) 
     url = 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&%s' % query 
     search_response = urllib.urlopen(url) 
     search_results = search_response.read() 
     results = json.loads(search_results) 
     data = results['responseData'] 
     return int(data['cursor']['estimatedResultCount']) 

colors = ['yellow', 'orange', 'red', 'purple', 'blue', 'green'] 

# get a list of google search counts 
res = [google_count('"%s grass"' % c) for c in colors] 
# pair the results with their corresponding colors 
res2 = list(itertools.izip(res, colors)) 
# get the color with the highest score 
print "%s is %s" % ('grass', sorted(res2)[-1][1]) 

這將打印:

grass is green 
+0

或者您可以在ImageNet(http://www.image-net.org/)中進行搜索,該搜索向Wordnet條目提供圖像,因此您可能會獲得更準確的圖像。使用谷歌搜索,例如「蘋果」可能會顯示技術公司,而不是水果。 –

0

丹尼爾和Xi.lin的答案是非常好的想法。在同一軸上,我們可以將這兩種方法結合起來,採用類似於西林的方法,但更簡單:查詢谷歌圖片,查找與想要查找顏色相關聯的單詞+「顏色」過濾器(請參見左下方欄)。並看看哪種顏色會產生更多的結果。