+++ /dev/null
-# vim: set sw=2 et:\r
-#\r
-# dict plugin: provides a link to the definition of a word in one of the supported\r
-# dictionaries. Currently available are\r
-# * the Oxford dictionary for (British) English\r
-# * the De Mauro/Paravia dictionary for Italian\r
-#\r
-# other plugins can use this one to check if a given word is valid in italian\r
-# or british english by using the is_italian?/is_british? methods\r
-#\r
-# Author: Giuseppe "Oblomov" Bilotta <giuseppe.bilotta@gmail.com>\r
-#\r
-# TODO: cache results and reuse them if get_cached returns a cache copy\r
-\r
-require 'uri'\r
-\r
-DEMAURO_LEMMA = /<anchor>(.*?)(?: - (.*?))<go href="lemma.php\?ID=(\d+)"\/><\/anchor>/\r
-\r
-class DictPlugin < Plugin\r
- def initialize\r
- super\r
- @dmurl = "http://www.demauroparavia.it/"\r
- @dmwapurl = "http://wap.demauroparavia.it/"\r
- @oxurl = "http://www.askoxford.com/concise_oed/"\r
- end\r
-\r
-\r
- def help(plugin, topic="")\r
- return "demauro <word> => provides a link to the definition of the word from the Italian dictionary De Mauro/Paravia"\r
- end\r
-\r
- def demauro(m, params)\r
- justcheck = params[:justcheck]\r
-\r
- word = params[:word].downcase\r
- url = @dmwapurl + "index.php?lemma=#{URI.escape(word)}"\r
- xml = @bot.httputil.get_cached(url)\r
- if xml.nil?\r
- info = @bot.httputil.last_response\r
- info = info ? "(#{info.code} - #{info.message})" : ""\r
- return false if justcheck\r
- m.reply "An error occurred while looking for #{word}#{info}"\r
- return\r
- end\r
- if xml=~ /Non ho trovato occorrenze per/\r
- return false if justcheck\r
- m.reply "Nothing found for #{word}"\r
- return\r
- end\r
- entries = xml.scan(DEMAURO_LEMMA)\r
- text = word\r
- if !entries.assoc(word) and !entries.assoc(word.upcase)\r
- return false if justcheck\r
- text += " not found. Similar words"\r
- end\r
- return true if justcheck\r
- text += ": "\r
- text += entries[0...5].map { |ar|\r
- "#{ar[0]} - #{ar[1].gsub(/<\/?em>/,'')}: #{@dmurl}#{ar[2]}"\r
- }.join(" | ")\r
- m.reply text\r
- end\r
-\r
- def is_italian?(word)\r
- return demauro(nil, :word => word, :justcheck => true)\r
- end\r
-\r
-\r
- def oxford(m, params)\r
- justcheck = params[:justcheck]\r
-\r
- word = params[:word].downcase.gsub(/\s+/,'')\r
- [word, word + "_1"].each { |check|\r
- url = @oxurl + "#{URI.escape(check)}"\r
- h = @bot.httputil.head(url)\r
- if h\r
- m.reply("#{word} found: #{url}") unless justcheck\r
- return true\r
- end\r
- }\r
- return false if justcheck\r
- m.reply "#{word} not found"\r
- end\r
-\r
- def is_british?(word)\r
- return oxford(nil, :word => word, :justcheck => true)\r
- end\r
-\r
-end\r
-\r
-plugin = DictPlugin.new\r
-plugin.map 'demauro :word', :action => 'demauro'\r
-plugin.map 'oxford :word', :action => 'oxford'\r
-\r
--- /dev/null
+# vim: set sw=2 et:\r
+#\r
+# dict plugin: provides a link to the definition of a word in one of the supported\r
+# dictionaries. Currently available are\r
+# * the Oxford dictionary for (British) English\r
+# * the De Mauro/Paravia dictionary for Italian\r
+# * the Chambers dictionary for English (accepts both US and UK)\r
+#\r
+# other plugins can use this one to check if a given word is valid in italian\r
+# or english by using the is_italian?/is_british?/is_english? methods\r
+#\r
+# Author: Giuseppe "Oblomov" Bilotta <giuseppe.bilotta@gmail.com>\r
+#\r
+# TODO: cache results and reuse them if get_cached returns a cache copy\r
+\r
+require 'uri'\r
+\r
+DEMAURO_LEMMA = /<anchor>(.*?)(?: - (.*?))<go href="lemma.php\?ID=(\d+)"\/><\/anchor>/\r
+\r
+class DictPlugin < Plugin\r
+ def initialize\r
+ super\r
+ @dmurl = "http://www.demauroparavia.it/"\r
+ @dmwapurl = "http://wap.demauroparavia.it/index.php?lemma=%s"\r
+ @oxurl = "http://www.askoxford.com/concise_oed/%s"\r
+ @chambersurl = "http://www.chambersharrap.co.uk/chambers/features/chref/chref.py/main?query=%s&title=21st"\r
+ end\r
+\r
+\r
+ def help(plugin, topic="")\r
+ case topic\r
+ when "demauro"\r
+ return "demauro <word> => provides a link to the definition of <word> from the De Mauro/Paravia dictionary"\r
+ when "oxford"\r
+ return "oxford <word> => provides a link to the definition of <word> (it can also be an expression) from the Concise Oxford dictionary"\r
+ when "chambers"\r
+ return "chambers <word> => provides a link to the definition of <word> (it can also be an expression) from the Chambers 21st Century Dictionary"\r
+ end\r
+ return "<dictionary> <word>: check for <word> on <dictionary> where <dictionary> can be one of: demauro, oxford, chambers"\r
+ end\r
+\r
+ def demauro(m, params)\r
+ justcheck = params[:justcheck]\r
+\r
+ word = params[:word].downcase\r
+ url = @dmwapurl % URI.escape(word)\r
+ xml = @bot.httputil.get_cached(url)\r
+ if xml.nil?\r
+ info = @bot.httputil.last_response\r
+ info = info ? " (#{info.code} - #{info.message})" : ""\r
+ return false if justcheck\r
+ m.reply "An error occurred while looking for #{word}#{info}"\r
+ return\r
+ end\r
+ if xml=~ /Non ho trovato occorrenze per/\r
+ return false if justcheck\r
+ m.reply "Nothing found for #{word}"\r
+ return\r
+ end\r
+ entries = xml.scan(DEMAURO_LEMMA)\r
+ text = word\r
+ if !entries.assoc(word) and !entries.assoc(word.upcase)\r
+ return false if justcheck\r
+ text += " not found. Similar words"\r
+ end\r
+ return true if justcheck\r
+ text += ": "\r
+ text += entries[0...5].map { |ar|\r
+ "#{ar[0]} - #{ar[1].gsub(/<\/?em>/,'')}: #{@dmurl}#{ar[2]}"\r
+ }.join(" | ")\r
+ m.reply text\r
+ end\r
+\r
+ def is_italian?(word)\r
+ return demauro(nil, :word => word, :justcheck => true)\r
+ end\r
+\r
+\r
+ def oxford(m, params)\r
+ justcheck = params[:justcheck]\r
+\r
+ word = params[:word].join\r
+ [word, word + "_1"].each { |check|\r
+ url = @oxurl % URI.escape(check)\r
+ h = @bot.httputil.head(url)\r
+ if h\r
+ m.reply("#{word} found: #{url}") unless justcheck\r
+ return true\r
+ end\r
+ }\r
+ return false if justcheck\r
+ m.reply "#{word} not found"\r
+ end\r
+\r
+ def is_british?(word)\r
+ return oxford(nil, :word => word, :justcheck => true)\r
+ end\r
+\r
+\r
+ def chambers(m, params)\r
+ justcheck = params[:justcheck]\r
+\r
+ word = params[:word].to_s.downcase\r
+ url = @chambersurl % URI.escape(word)\r
+ xml = @bot.httputil.get_cached(url)\r
+ case xml\r
+ when nil\r
+ info = @bot.httputil.last_response\r
+ info = info ? " (#{info.code} - #{info.message})" : ""\r
+ return false if justcheck\r
+ m.reply "An error occurred while looking for #{word}#{info}"\r
+ return\r
+ when /Sorry, no entries for <b>.*?<\/b> were found./\r
+ return false if justcheck\r
+ m.reply "Nothing found for #{word}"\r
+ return\r
+ when /No exact matches for <b>.*?<\/b>, but the following may be helpful./\r
+ return false if justcheck\r
+ m.reply "Nothing found for #{word}, but see #{url} for possible suggestions"\r
+ else\r
+ return false if justcheck\r
+ m.reply "#{word}: #{url}"\r
+ end\r
+ end\r
+\r
+ def is_english?(word)\r
+ return chambers(nil, :word => word, :justcheck => true)\r
+ end\r
+\r
+end\r
+\r
+plugin = DictPlugin.new\r
+plugin.map 'demauro :word', :action => 'demauro'\r
+plugin.map 'oxford *word', :action => 'oxford'\r
+plugin.map 'chambers *word', :action => 'chambers'\r
+\r