From a275a8cc89918e680ecf2523460b1e54ed70f902 Mon Sep 17 00:00:00 2001 From: chrox Date: Wed, 20 Aug 2014 18:04:19 +0800 Subject: [PATCH] strip punctuations in word before wikipedia lookup --- frontend/apps/reader/modules/readerhighlight.lua | 1 - frontend/apps/reader/modules/readerwikipedia.lua | 6 ++++++ frontend/ui/widget/dictquicklookup.lua | 1 - 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/frontend/apps/reader/modules/readerhighlight.lua b/frontend/apps/reader/modules/readerhighlight.lua index c6d869e9f..890b42e5f 100644 --- a/frontend/apps/reader/modules/readerhighlight.lua +++ b/frontend/apps/reader/modules/readerhighlight.lua @@ -312,7 +312,6 @@ function ReaderHighlight:onHoldRelease() callback = function() UIManager:scheduleIn(0.1, function() self:lookupWikipedia() - self:onClose() end) end, }, diff --git a/frontend/apps/reader/modules/readerwikipedia.lua b/frontend/apps/reader/modules/readerwikipedia.lua index 34537ad33..984fc2028 100644 --- a/frontend/apps/reader/modules/readerwikipedia.lua +++ b/frontend/apps/reader/modules/readerwikipedia.lua @@ -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 diff --git a/frontend/ui/widget/dictquicklookup.lua b/frontend/ui/widget/dictquicklookup.lua index fd232affc..cb4b62ccb 100644 --- a/frontend/ui/widget/dictquicklookup.lua +++ b/frontend/ui/widget/dictquicklookup.lua @@ -175,7 +175,6 @@ function DictQuickLookup:update() callback = function() UIManager:scheduleIn(0.1, function() self:lookupWikipedia() - self:onClose() end) end, },