strip punctuations in word before wikipedia lookup

pull/818/head
chrox 10 years ago
parent 50d45a13d1
commit a275a8cc89

@ -312,7 +312,6 @@ function ReaderHighlight:onHoldRelease()
callback = function()
UIManager:scheduleIn(0.1, function()
self:lookupWikipedia()
self:onClose()
end)
end,
},

@ -18,6 +18,7 @@ local ReaderWikipedia = ReaderDictionary:new{
}
function ReaderWikipedia:onLookupWikipedia(word, box)
-- detect language of the text
local ok, lang = pcall(Translator.detect, Translator, word)
-- prompt users to turn on Wifi if network is unreachable
if not ok and lang and lang:find("Network is unreachable") then
@ -26,6 +27,11 @@ function ReaderWikipedia:onLookupWikipedia(word, box)
end
-- convert "zh-CN" and "zh-TW" to "zh"
lang = lang:match("(.*)-") or lang
-- strip punctuation characters around selected word
word = string.gsub(word, "^%p+", '')
word = string.gsub(word, "%p+$", '')
-- seems lower case phrase has higher hit rate
word = string.lower(word)
local results = {}
local ok, pages = pcall(Wikipedia.wikintro, Wikipedia, word, lang)
if ok and pages then

@ -175,7 +175,6 @@ function DictQuickLookup:update()
callback = function()
UIManager:scheduleIn(0.1, function()
self:lookupWikipedia()
self:onClose()
end)
end,
},

Loading…
Cancel
Save