├── VERSION ├── .gitignore ├── Gemfile ├── .travis.yml ├── Gemfile.lock ├── CHANGES ├── test ├── tc_icon.rb ├── tc_link.rb ├── tc_live.rb └── tc_zero_click_info.rb ├── lib ├── duck_duck_go │ ├── icon.rb │ ├── link.rb │ └── zero_click_info.rb └── duck_duck_go.rb ├── LICENSE ├── README.rdoc ├── duck-duck-go.gemspec └── Rakefile /VERSION: -------------------------------------------------------------------------------- 1 | 1.1.3 -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | rdoc 2 | *~ 3 | coverage 4 | pkg 5 | .redcar 6 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | gem 'jeweler' 3 | gem 'httpclient' 4 | gem 'json' 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: ruby 2 | rvm: 3 | - 2.0.0 4 | - 1.9.3 5 | - jruby-18mode # JRuby in 1.8 mode 6 | - jruby-19mode # JRuby in 1.9 mode 7 | - rbx-18mode 8 | - rbx-19mode 9 | - 1.8.7 10 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | git (1.2.5) 5 | httpclient (2.3.3) 6 | jeweler (1.8.4) 7 | bundler (~> 1.0) 8 | git (>= 1.2.5) 9 | rake 10 | rdoc 11 | json (1.7.7) 12 | rake (10.0.4) 13 | rdoc (4.0.1) 14 | json (~> 1.4) 15 | 16 | PLATFORMS 17 | ruby 18 | 19 | DEPENDENCIES 20 | httpclient 21 | jeweler 22 | json 23 | -------------------------------------------------------------------------------- /CHANGES: -------------------------------------------------------------------------------- 1 | 1.1.3 02-07-2012 2 | - Fix live tests after DDG results changed 3 | 4 | 1.1.2 03-05-2012 5 | - Fix for URI parsing exceptions InvalidURIError [Chris Nicola - https://github.com/lucisferre] 6 | 7 | 1.1.1 03-12-2011 8 | - Fix live tests after DDG results changed 9 | 10 | 1.1.0 13-04-2011 11 | - Support for skip_disambiguation queries 12 | 13 | 1.0.2 08-04-2011 14 | - Add CHANGES file 15 | 16 | 1.0.1 08-04-2011 17 | - Fix email address typo. No code changes. 18 | 19 | 1.0.0 08-04-2011 20 | - Initial version 21 | -------------------------------------------------------------------------------- /test/tc_icon.rb: -------------------------------------------------------------------------------- 1 | $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) 2 | 3 | require 'test/unit' 4 | require 'duck_duck_go/icon' 5 | require 'uri' 6 | 7 | class TestIcon < Test::Unit::TestCase 8 | 9 | def test_icon 10 | data = { 11 | "URL" => "https://i.duckduckgo.com/i/foo.com.ico", 12 | "Height" => 16, 13 | "Width" => 16 14 | } 15 | 16 | icon = DuckDuckGo::Icon.by(data) 17 | assert_instance_of(DuckDuckGo::Icon, icon) 18 | assert_instance_of(URI::HTTPS, icon.url) 19 | assert_equal("i.duckduckgo.com", icon.url.host) 20 | assert_equal(16, icon.width) 21 | assert_equal(16, icon.height) 22 | end 23 | end -------------------------------------------------------------------------------- /lib/duck_duck_go/icon.rb: -------------------------------------------------------------------------------- 1 | module DuckDuckGo 2 | 3 | require 'uri' 4 | 5 | class DuckDuckGo::Icon 6 | 7 | attr_reader :url, :width, :height 8 | 9 | # Representes a DDG icon 10 | def initialize(url = nil, width = nil, height = nil) 11 | @url = url 12 | @width = width 13 | @height = height 14 | end 15 | 16 | # Populate an DuckDuckGo::Icon from a result 17 | def self.by(icon_result) 18 | url = URI.parse(icon_result['URL']) unless icon_result['URL'].empty? 19 | width = icon_result['Width'] if icon_result['Width'] 20 | height = icon_result['Height'] if icon_result['Height'] 21 | 22 | self.new(url, width, height) 23 | end 24 | end 25 | 26 | end -------------------------------------------------------------------------------- /lib/duck_duck_go/link.rb: -------------------------------------------------------------------------------- 1 | module DuckDuckGo 2 | 3 | require 'uri' 4 | require 'duck_duck_go/icon' 5 | 6 | class DuckDuckGo::Link 7 | 8 | attr_reader :result, :first_url, :icon, :text 9 | 10 | # Representes a DDG link 11 | def initialize(result = nil, first_url = nil, icon = nil, text = nil) 12 | @result = result 13 | @first_url = first_url 14 | @icon = icon 15 | @text = text 16 | end 17 | 18 | # Populate a DuckDuckGo::Link from a result 19 | def self.by(link_result) 20 | result = link_result['Result'] unless link_result['Result'].empty? 21 | first_url = URI.parse(link_result['FirstURL']) unless link_result['FirstURL'].empty? 22 | icon = DuckDuckGo::Icon.by(link_result['Icon']) unless link_result['Icon'].empty? 23 | text = link_result['Text'] unless link_result['Text'].empty? 24 | 25 | self.new(result, first_url, icon, text) 26 | end 27 | end 28 | 29 | end -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011 Andrew Jones, http://andrew-jones.com 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /test/tc_link.rb: -------------------------------------------------------------------------------- 1 | $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) 2 | 3 | require 'test/unit' 4 | require 'duck_duck_go/link' 5 | require 'duck_duck_go/icon' 6 | require 'uri' 7 | 8 | class TestLink < Test::Unit::TestCase 9 | 10 | def test_link 11 | data = { 12 | "Result" => "Official site", 13 | "Icon" => { 14 | "URL" => "https://i.duckduckgo.com/i/foo.com.ico", 15 | "Height" => 16, 16 | "Width" => 16 17 | }, 18 | "FirstURL" => "http://www.foo.com", 19 | "Text" => "Official site" 20 | } 21 | 22 | link = DuckDuckGo::Link.by(data) 23 | assert_instance_of(DuckDuckGo::Link, link) 24 | assert_instance_of(DuckDuckGo::Icon, link.icon) 25 | assert_instance_of(URI::HTTP, link.first_url) 26 | assert_equal('www.foo.com', link.first_url.host) 27 | assert_equal('Official site', link.text) 28 | end 29 | 30 | def test_link_missing_icon 31 | data = { 32 | "Result" => "Official site", 33 | "Icon" => { 34 | }, 35 | "FirstURL" => "http://www.foo.com", 36 | "Text" => "Official site" 37 | } 38 | 39 | link = DuckDuckGo::Link.by(data) 40 | assert_instance_of(DuckDuckGo::Link, link) 41 | assert_nil(link.icon) 42 | assert_instance_of(URI::HTTP, link.first_url) 43 | assert_equal('www.foo.com', link.first_url.host) 44 | assert_equal('Official site', link.text) 45 | end 46 | end -------------------------------------------------------------------------------- /lib/duck_duck_go.rb: -------------------------------------------------------------------------------- 1 | # Author: Andrew Jones 2 | # The license of this source is MIT Licence 3 | 4 | module DuckDuckGo 5 | 6 | require 'rubygems' 7 | require 'uri' 8 | require 'httpclient' 9 | require 'json' 10 | require 'duck_duck_go/zero_click_info' 11 | 12 | # see DuckDuckGo::Main.new 13 | def self.new(*params) 14 | DuckDuckGo::Main.new(*params) 15 | end 16 | 17 | class Main 18 | 19 | API_URL = 'http://api.duckduckgo.com/' 20 | API_URL_SECURE = 'https://api.duckduckgo.com/' 21 | 22 | # Create a new instance. 23 | # It is recommended to pass in a meaningful user agent. 24 | # Defaults to using the secure api (https) 25 | def initialize(http_agent_name = 'DuckDuckGo.rb', secure = true) 26 | if secure 27 | @url = API_URL_SECURE 28 | else 29 | @url = API_URL 30 | end 31 | @http = HTTPClient.new(:agent_name => http_agent_name) 32 | end 33 | 34 | # Run a query against Duck Duck Go 35 | # Returns an instance of DuckDuckGo::ZeroClickInfo 36 | def zeroclickinfo(query, skip_disambiguation = false) 37 | args = { 38 | 'q' => query, 39 | 'o' => 'json' 40 | } 41 | if(skip_disambiguation) 42 | args['d'] = 1 43 | end 44 | 45 | data = @http.get_content(@url, args) 46 | 47 | # parse the JSON and return an instance 48 | # of the ZeroClickInfo class 49 | DuckDuckGo::ZeroClickInfo.by(JSON.parse(data)) 50 | end 51 | 52 | # Alias for DuckDuckGo::Main.zeroclickinfo 53 | def zci(*params) 54 | self.zeroclickinfo(*params) 55 | end 56 | end 57 | 58 | end -------------------------------------------------------------------------------- /README.rdoc: -------------------------------------------------------------------------------- 1 | This is a Ruby library to access the DuckDuckGo Zero Click Info API. 2 | 3 | = How to install 4 | 5 | gem install duck-duck-go 6 | 7 | = Synopsis 8 | 9 | require "duck_duck_go" 10 | 11 | ddg = DuckDuckGo.new 12 | zci = ddg.zeroclickinfo("Stephen Fry") # ZeroClickInfo object 13 | 14 | zci.heading # Stephen Fry 15 | zci.abstract_text # Stephen John Fry is an English actor, screenwriter, author, playwright, ... 16 | zci.related_topics["_"][0].text # Stephen Fry (cricketer) ... 17 | 18 | = Description 19 | 20 | This library accesses the DuckDuckGo Zero Click Info API[http://duckduckgo.com/api.html], and returns an DuckDuckGo::ZeroClickInfo object containing the result. 21 | 22 | Depending on the result type, the +related_topics+ hash will contain slightly different results. 23 | 24 | For most queries, related_topics["_"] contains an array of the related topics. 25 | 26 | For a disambiguation query, related_topics["_"] contains the related topics, where as related_topics["Topic"] contains the disambiguation results. For example, searching for _apple_, you will find a related_topics["Compaines"] entry containing Apple Inc and Apple Corp, amongst others. 27 | 28 | = Issues 29 | 30 | http://github.com/andrewrjones/ruby-duck-duck-go/issues 31 | 32 | = Source code 33 | 34 | http://github.com/andrewrjones/ruby-duck-duck-go 35 | 36 | = Credits 37 | 38 | API and design heavily influenced by WWW::DuckDuckGo[http://search.cpan.org/~getty/WWW-DuckDuckGo-0.006/lib/WWW/DuckDuckGo/ZeroClickInfo.pm], the equivalent Perl module. 39 | 40 | = Copyright and License 41 | 42 | Copyright (c) 2012 Andrew Jones (http://andrew-jones.com) 43 | 44 | This code is available under the MIT License. See the LICENSE file for more details. 45 | -------------------------------------------------------------------------------- /test/tc_live.rb: -------------------------------------------------------------------------------- 1 | $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) 2 | 3 | require 'test/unit' 4 | require 'duck_duck_go' 5 | require 'duck_duck_go/zero_click_info' 6 | 7 | class TestLive < Test::Unit::TestCase 8 | 9 | # test a live search for 'jack wilshere' 10 | def test_live 11 | 12 | ddg = DuckDuckGo.new(nil, false) 13 | zci = ddg.zci('jack wilshere') 14 | 15 | assert_instance_of(DuckDuckGo::ZeroClickInfo, zci) 16 | assert_equal("Jack Wilshere", zci.heading) 17 | assert_equal("Wikipedia", zci.abstract_source) 18 | assert_equal("A", zci.type) 19 | end 20 | 21 | # test using http 22 | def test_live_http 23 | 24 | ddg = DuckDuckGo.new(nil, true) 25 | zci = ddg.zci('jack wilshere') 26 | 27 | assert_instance_of(DuckDuckGo::ZeroClickInfo, zci) 28 | assert_equal("Jack Wilshere", zci.heading) 29 | assert_equal("Wikipedia", zci.abstract_source) 30 | assert_equal("A", zci.type) 31 | end 32 | 33 | def test_skip_disambiguation 34 | ddg = DuckDuckGo.new(nil, true) 35 | zci = ddg.zci('Bill Gates') 36 | 37 | assert_instance_of(DuckDuckGo::ZeroClickInfo, zci) 38 | assert_equal("D", zci.type) 39 | 40 | sleep(5) 41 | 42 | zci = ddg.zci('Bill Gates', true) 43 | 44 | assert_instance_of(DuckDuckGo::ZeroClickInfo, zci) 45 | assert_equal("Bill Gates", zci.heading) 46 | assert_equal("Wikipedia", zci.abstract_source) 47 | assert_equal("A", zci.type) 48 | end 49 | 50 | # questions do not currently get a response on the api 51 | def test_answer 52 | ddg = DuckDuckGo.new 53 | zci = ddg.zci('age of obama') 54 | 55 | assert_nil(zci.abstract) 56 | assert_nil(zci.answer) 57 | assert_nil(zci.definition) 58 | assert_nil(zci.heading) 59 | assert_equal(0, zci.related_topics.size) 60 | assert_equal(0, zci.results.size) 61 | end 62 | end 63 | -------------------------------------------------------------------------------- /duck-duck-go.gemspec: -------------------------------------------------------------------------------- 1 | # Generated by jeweler 2 | # DO NOT EDIT THIS FILE DIRECTLY 3 | # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec' 4 | # -*- encoding: utf-8 -*- 5 | 6 | Gem::Specification.new do |s| 7 | s.name = %q{duck-duck-go} 8 | s.version = "1.1.3" 9 | 10 | s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= 11 | s.authors = ["andrewrjones"] 12 | s.date = %q{2012-07-02} 13 | s.description = %q{A Ruby library to access the DuckDuckGo Zero Click Info API.} 14 | s.email = %q{andrew@arjones.co.uk} 15 | s.extra_rdoc_files = [ 16 | "LICENSE", 17 | "README.rdoc" 18 | ] 19 | s.files = [ 20 | "CHANGES", 21 | "LICENSE", 22 | "README.rdoc", 23 | "Rakefile", 24 | "VERSION", 25 | "duck-duck-go.gemspec", 26 | "lib/duck_duck_go.rb", 27 | "lib/duck_duck_go/icon.rb", 28 | "lib/duck_duck_go/link.rb", 29 | "lib/duck_duck_go/zero_click_info.rb", 30 | "test/tc_icon.rb", 31 | "test/tc_link.rb", 32 | "test/tc_live.rb", 33 | "test/tc_zero_click_info.rb" 34 | ] 35 | s.homepage = %q{https://github.com/andrewrjones/ruby-duck-duck-go} 36 | s.require_paths = ["lib"] 37 | s.rubygems_version = %q{1.6.1} 38 | s.summary = %q{Access the DuckDuckGo Zero Click Info API} 39 | s.test_files = [ 40 | "test/tc_icon.rb", 41 | "test/tc_link.rb", 42 | "test/tc_live.rb", 43 | "test/tc_zero_click_info.rb" 44 | ] 45 | 46 | if s.respond_to? :specification_version then 47 | s.specification_version = 3 48 | 49 | if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then 50 | s.add_runtime_dependency(%q, [">= 0"]) 51 | s.add_runtime_dependency(%q, [">= 0"]) 52 | else 53 | s.add_dependency(%q, [">= 0"]) 54 | s.add_dependency(%q, [">= 0"]) 55 | end 56 | else 57 | s.add_dependency(%q, [">= 0"]) 58 | s.add_dependency(%q, [">= 0"]) 59 | end 60 | end 61 | 62 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'rake' 2 | 3 | task :default => [:test] 4 | 5 | require 'rake/testtask' 6 | desc "Run unit tests" 7 | Rake::TestTask.new("test") { |t| 8 | t.pattern = 'test/tc_*.rb' 9 | t.verbose = true 10 | } 11 | 12 | begin 13 | require 'jeweler' 14 | Jeweler::Tasks.new do |gem| 15 | gem.name = "duck-duck-go" 16 | gem.summary = %Q{Access the DuckDuckGo Zero Click Info API} 17 | gem.description = %Q{A Ruby library to access the DuckDuckGo Zero Click Info API.} 18 | gem.email = "andrew@arjones.co.uk" 19 | gem.homepage = "https://github.com/andrewrjones/ruby-duck-duck-go" 20 | gem.authors = ["andrewrjones"] 21 | gem.add_dependency('httpclient') 22 | gem.add_dependency('json') 23 | # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings 24 | end 25 | Jeweler::GemcutterTasks.new 26 | rescue LoadError 27 | puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler" 28 | end 29 | 30 | begin 31 | require 'rcov/rcovtask' 32 | Rcov::RcovTask.new do |rcov| 33 | rcov.libs << 'test' 34 | rcov.pattern = 'test/tc_*.rb' 35 | rcov.verbose = true 36 | rcov.rcov_opts << '--exclude gems' 37 | end 38 | rescue LoadError 39 | task :rcov do 40 | abort "RCov is not available. In order to run rcov, you must: sudo gem install rcov" 41 | end 42 | end 43 | 44 | #require 'rake/rdoctask' 45 | #Rake::RDocTask.new do |rdoc| 46 | # version = File.exist?('VERSION') ? File.read('VERSION') : "" 47 | # 48 | # rdoc.rdoc_dir = 'rdoc' 49 | # rdoc.title = "duck-duck-go #{version}" 50 | # rdoc.rdoc_files.include('README*') 51 | # rdoc.rdoc_files.include('LICENSE') 52 | # rdoc.rdoc_files.include('lib/**/*.rb') 53 | #end 54 | 55 | desc "Run cane to check quality metrics" 56 | task :quality do 57 | puts `cane --abc-max 10 --gte coverage/covered_percent,99` 58 | exit $?.exitstatus unless $?.exitstatus == 0 59 | end 60 | 61 | # dumps out the result of the query, in JSON and Ruby 62 | # used during development 63 | task :search_dump do 64 | require 'rubygems' 65 | require 'httpclient' 66 | require 'json' 67 | require 'pp' 68 | 69 | unless ENV.include?("query") 70 | raise "usage: rake search_dump query=___" 71 | end 72 | 73 | args = { 74 | 'q' => ENV['query'], 75 | 'o' => 'json' 76 | } 77 | if ENV.include?("skip_disambiguation") 78 | args['d'] = 1 79 | end 80 | 81 | 82 | http = HTTPClient.new 83 | json = http.get_content('http://api.duckduckgo.com/', args) 84 | ruby = JSON.parse(json) 85 | 86 | puts 'JSON' 87 | puts '----' 88 | puts json 89 | puts 90 | puts 'Ruby' 91 | puts '----' 92 | pp ruby 93 | end 94 | -------------------------------------------------------------------------------- /lib/duck_duck_go/zero_click_info.rb: -------------------------------------------------------------------------------- 1 | module DuckDuckGo 2 | 3 | require 'uri' 4 | require 'duck_duck_go/link' 5 | require 'duck_duck_go/icon' 6 | 7 | class DuckDuckGo::ZeroClickInfo 8 | 9 | # Definitions for the result type 10 | TYPE_DEFINITIONS = { 11 | 'A' => 'article', 12 | 'D' => 'disambiguation', 13 | 'C' => 'category', 14 | 'N' => 'name', 15 | 'E' => 'exclusive', 16 | } 17 | 18 | attr_reader :abstract, :abstract_text, :abstract_source, :abstract_url, :image, :heading, :answer, :answer_type, :definition, :definition_source, :definition_url, :type, :type_long, :results, :related_topics 19 | 20 | # Representes a DDG Zero Click Info result 21 | def initialize(abstract = nil, abstract_text = nil, abstract_source = nil, abstract_url = nil, image = nil, heading = nil, answer = nil, answer_type = nil, definition = nil, definition_source = nil, definition_url = nil, type = nil, results = nil, related_topics = nil) 22 | @abstract = abstract 23 | @abstract_text = abstract_text 24 | @abstract_source = abstract_source 25 | @abstract_url = abstract_url 26 | @image = image 27 | @heading = heading 28 | @answer = answer 29 | @answer_type = answer_type 30 | @definition = definition 31 | @definition_source = definition_source 32 | @definition_url = definition_url 33 | @type = type unless type.nil? 34 | @type_long = TYPE_DEFINITIONS[type] 35 | @results = results 36 | @related_topics = related_topics 37 | end 38 | 39 | # Populate the DuckDuckGo::ZeroClickInfo from a result 40 | def self.by(result) 41 | 42 | abstract = result['Abstract'] unless result['Abstract'].empty? 43 | abstract_text = result['AbstractText'] unless result['AbstractText'].empty? 44 | abstract_source = result['AbstractSource'] unless result['AbstractSource'].empty? 45 | abstract_url = URI.parse(URI.escape(result['AbstractURL'])) unless result['AbstractURL'].empty? 46 | image = URI.parse(URI.escape(result['Image'])) unless result['Image'].empty? 47 | heading = result['Heading'] unless result['Heading'].empty? 48 | answer = result['Answer'] unless result['Answer'].empty? 49 | answer_type = result['AnswerType'] unless result['AnswerType'].empty? 50 | definition = result['Definition'] unless result['Definition'].empty? 51 | definition_source = result['DefinitionSource'] unless result['DefinitionSource'].empty? 52 | definition_url = URI.parse(URI.escape(result['DefinitionURL'])) unless result['DefinitionURL'].empty? 53 | type = result['Type'] unless result['Type'].empty? 54 | 55 | if result['Results'] 56 | results = Array.new 57 | result['Results'].each do |link_result| 58 | results << DuckDuckGo::Link.by(link_result) 59 | end 60 | end 61 | 62 | if result['RelatedTopics'] 63 | related_topics = Hash.new 64 | result['RelatedTopics'].each do |t| 65 | if t['Topics'] 66 | topics = Array.new 67 | t['Topics'].each do |link_result| 68 | topics << DuckDuckGo::Link.by(link_result) 69 | end 70 | related_topics[t['Name']] = topics 71 | else 72 | related_topics['_'] = Array.new if related_topics['_'].nil? 73 | related_topics['_'] << DuckDuckGo::Link.by(t) 74 | end 75 | end 76 | end 77 | 78 | self.new(abstract, abstract_text, abstract_source, abstract_url, image, heading, answer, answer_type, definition, definition_source, definition_url, type, results, related_topics) 79 | end 80 | end 81 | 82 | end 83 | -------------------------------------------------------------------------------- /test/tc_zero_click_info.rb: -------------------------------------------------------------------------------- 1 | $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) 2 | 3 | require 'test/unit' 4 | require 'duck_duck_go/zero_click_info' 5 | require 'uri' 6 | 7 | class TestZCI < Test::Unit::TestCase 8 | 9 | def test_zci_article 10 | 11 | # example data - a search for Stephen Fry 12 | data = {"AbstractSource"=>"Wikipedia", 13 | "Answer"=>"", 14 | "Definition"=>"", 15 | "Results"=> 16 | [{"Text"=>"Official site", 17 | "Icon"=> 18 | {"URL"=>"http://i.duck.co/i/stephenfry.com.ico", 19 | "Width"=>16, 20 | "Height"=>16}, 21 | "Result"=> 22 | "Official site", 23 | "FirstURL"=>"http://www.stephenfry.com"}, 24 | {"Text"=> 25 | "Five Minutes With: Stephen Fry, interview with Matthew Stadlen for the BBC", 26 | "Icon"=> 27 | {"URL"=>"http://i.duck.co/i/news.bbc.co.uk.ico", 28 | "Width"=>16, 29 | "Height"=>16}, 30 | "Result"=> 31 | "Five Minutes With: Stephen Fry, interview with Matthew Stadlen for the BBC", 32 | "FirstURL"=>"http://news.bbc.co.uk/1/hi/entertainment/7895351.stm"}], 33 | "AnswerType"=>"", 34 | "Abstract"=> 35 | "Stephen John Fry is an English actor, screenwriter, author, playwright, journalist, poet, comedian, television presenter and film director, and a director of Norwich City Football Club.", 36 | "Heading"=>"Stephen Fry", 37 | "RelatedTopics"=> 38 | [{"Text"=>"Stephen Fry (cricketer) - Stephen Fry was an English cricketer.", 39 | "Icon"=>{}, 40 | "Result"=> 41 | "Stephen Fry (cricketer) - Stephen Fry was an English cricketer.", 42 | "FirstURL"=>"http://duckduckgo.com/Stephen_Fry_(cricketer)"}, 43 | {"Text"=>"English podcasters", 44 | "Icon"=>{}, 45 | "Result"=> 46 | "English podcasters", 47 | "FirstURL"=>"http://duckduckgo.com/c/English_podcasters"}, 48 | {"Text"=>"Rectors of the University of Dundee", 49 | "Icon"=>{}, 50 | "Result"=> 51 | "Rectors of the University of Dundee", 52 | "FirstURL"=>"http://duckduckgo.com/c/Rectors_of_the_University_of_Dundee"}, 53 | {"Text"=>"Real people associated with the Harry Potter books", 54 | "Icon"=>{}, 55 | "Result"=> 56 | "Real people associated with the Harry Potter books", 57 | "FirstURL"=> 58 | "http://duckduckgo.com/c/Real_people_associated_with_the_Harry_Potter_books"}, 59 | {"Text"=>"Sidewise Award winning authors", 60 | "Icon"=>{}, 61 | "Result"=> 62 | "Sidewise Award winning authors", 63 | "FirstURL"=>"http://duckduckgo.com/c/Sidewise_Award_winning_authors"}, 64 | {"Text"=>"British actors of Hungarian descent", 65 | "Icon"=>{}, 66 | "Result"=> 67 | "British actors of Hungarian descent", 68 | "FirstURL"=>"http://duckduckgo.com/c/British_actors_of_Hungarian_descent"}, 69 | {"Text"=>"University Challenge contestants", 70 | "Icon"=>{}, 71 | "Result"=> 72 | "University Challenge contestants", 73 | "FirstURL"=>"http://duckduckgo.com/c/University_Challenge_contestants"}, 74 | {"Text"=>"English radio writers", 75 | "Icon"=>{}, 76 | "Result"=> 77 | "English radio writers", 78 | "FirstURL"=>"http://duckduckgo.com/c/English_radio_writers"}, 79 | {"Text"=>"English humanists", 80 | "Icon"=>{}, 81 | "Result"=> 82 | "English humanists", 83 | "FirstURL"=>"http://duckduckgo.com/c/English_humanists"}, 84 | {"Text"=>"English game show hosts", 85 | "Icon"=>{}, 86 | "Result"=> 87 | "English game show hosts", 88 | "FirstURL"=>"http://duckduckgo.com/c/English_game_show_hosts"}, 89 | {"Text"=>"Alternate history writers", 90 | "Icon"=>{}, 91 | "Result"=> 92 | "Alternate history writers", 93 | "FirstURL"=>"http://duckduckgo.com/c/Alternate_history_writers"}, 94 | {"Text"=>"People associated with the University of Dundee", 95 | "Icon"=>{}, 96 | "Result"=> 97 | "People associated with the University of Dundee", 98 | "FirstURL"=> 99 | "http://duckduckgo.com/c/People_associated_with_the_University_of_Dundee"}, 100 | {"Text"=>"English comedy writers", 101 | "Icon"=>{}, 102 | "Result"=> 103 | "English comedy writers", 104 | "FirstURL"=>"http://duckduckgo.com/c/English_comedy_writers"}, 105 | {"Text"=>"Old Uppinghamians", 106 | "Icon"=>{}, 107 | "Result"=> 108 | "Old Uppinghamians", 109 | "FirstURL"=>"http://duckduckgo.com/c/Old_Uppinghamians"}, 110 | {"Text"=>"Audio book narrators", 111 | "Icon"=>{}, 112 | "Result"=> 113 | "Audio book narrators", 114 | "FirstURL"=>"http://duckduckgo.com/c/Audio_book_narrators"}, 115 | {"Text"=>"People from Hampstead", 116 | "Icon"=>{}, 117 | "Result"=> 118 | "People from Hampstead", 119 | "FirstURL"=>"http://duckduckgo.com/c/People_from_Hampstead"}, 120 | {"Text"=>"Atheism activists", 121 | "Icon"=>{}, 122 | "Result"=> 123 | "Atheism activists", 124 | "FirstURL"=>"http://duckduckgo.com/c/Atheism_activists"}, 125 | {"Text"=>"LGBT television personalities", 126 | "Icon"=>{}, 127 | "Result"=> 128 | "LGBT television personalities", 129 | "FirstURL"=>"http://duckduckgo.com/c/LGBT_television_personalities"}, 130 | {"Text"=> 131 | "Outstanding Performance by a Cast in a Motion Picture Screen Actors Guild Award winners", 132 | "Icon"=>{}, 133 | "Result"=> 134 | "Outstanding Performance by a Cast in a Motion Picture Screen Actors Guild Award winners", 135 | "FirstURL"=> 136 | "http://duckduckgo.com/c/Outstanding_Performance_by_a_Cast_in_a_Motion_Picture_Screen_Actors_Guild_Award_winners"}, 137 | {"Text"=>"Jewish atheists", 138 | "Icon"=>{}, 139 | "Result"=> 140 | "Jewish atheists", 141 | "FirstURL"=>"http://duckduckgo.com/c/Jewish_atheists"}, 142 | {"Text"=>"English atheists", 143 | "Icon"=>{}, 144 | "Result"=> 145 | "English atheists", 146 | "FirstURL"=>"http://duckduckgo.com/c/English_atheists"}, 147 | {"Text"=>"Alumni of Queens' College, Cambridge", 148 | "Icon"=>{}, 149 | "Result"=> 150 | "Alumni of Queens' College, Cambridge", 151 | "FirstURL"=> 152 | "http://duckduckgo.com/c/Alumni_of_Queens'_College%2C_Cambridge"}, 153 | {"Text"=>"English television writers", 154 | "Icon"=>{}, 155 | "Result"=> 156 | "English television writers", 157 | "FirstURL"=>"http://duckduckgo.com/c/English_television_writers"}, 158 | {"Text"=>"People with bipolar disorder", 159 | "Icon"=>{}, 160 | "Result"=> 161 | "People with bipolar disorder", 162 | "FirstURL"=>"http://duckduckgo.com/c/People_with_bipolar_disorder"}, 163 | {"Text"=>"English film directors", 164 | "Icon"=>{}, 165 | "Result"=> 166 | "English film directors", 167 | "FirstURL"=>"http://duckduckgo.com/c/English_film_directors"}, 168 | {"Text"=>"English comedians", 169 | "Icon"=>{}, 170 | "Result"=> 171 | "English comedians", 172 | "FirstURL"=>"http://duckduckgo.com/c/English_comedians"}], 173 | "AbstractURL"=>"http://en.wikipedia.org/wiki/Stephen_Fry", 174 | "Image"=>"http://i.duck.co/i/72880df1.jpg", 175 | "DefinitionURL"=>"", 176 | "DefinitionSource"=>"", 177 | "AbstractText"=> 178 | "Stephen John Fry is an English actor, screenwriter, author, playwright, journalist, poet, comedian, television presenter and film director, and a director of Norwich City Football Club.", 179 | "Type"=>"A"} 180 | 181 | 182 | zci = DuckDuckGo::ZeroClickInfo.by(data) 183 | 184 | assert_equal("Stephen Fry", zci.heading) 185 | assert_equal("Wikipedia", zci.abstract_source) 186 | assert_instance_of(URI::HTTP, zci.image) 187 | assert_equal('i.duck.co', zci.image.host) 188 | assert_equal("Stephen John Fry is an English actor, screenwriter, author, playwright, journalist, poet, comedian, television presenter and film director, and a director of Norwich City Football Club.", zci.abstract_text) 189 | assert_equal("Stephen John Fry is an English actor, screenwriter, author, playwright, journalist, poet, comedian, television presenter and film director, and a director of Norwich City Football Club.", zci.abstract) 190 | assert_nil(zci.answer_type) 191 | assert_equal("A", zci.type) 192 | assert_equal("article", zci.type_long) 193 | assert_nil(zci.definition_url) 194 | assert_nil(zci.answer) 195 | assert_instance_of(URI::HTTP, zci.abstract_url) 196 | assert_equal('en.wikipedia.org', zci.abstract_url.host) 197 | assert_equal(2, zci.results.size) 198 | assert_equal("Official site", zci.results[0].text) 199 | assert_equal(1, zci.related_topics.size) 200 | assert_equal(26, zci.related_topics["_"].size) 201 | assert_equal("Stephen Fry (cricketer) - Stephen Fry was an English cricketer.", zci.related_topics["_"][0].text) 202 | end 203 | 204 | def test_zci_disambiguation 205 | 206 | data = {"AbstractSource"=>"Wikipedia", 207 | "Answer"=>"", 208 | "Definition"=> 209 | "A deciduous Eurasian tree having alternate simple leaves and white or pink flowers.", 210 | "Results"=>[], 211 | "AnswerType"=>"", 212 | "Abstract"=>"", 213 | "Heading"=>"Apple", 214 | "RelatedTopics"=> 215 | [{"Text"=>"The apple is a tree and its pomaceous fruit.", 216 | "Icon"=>{"URL"=>"http://i.duck.co/i/b5c79bb9.jpg"}, 217 | "Result"=> 218 | "The apple is a tree and its pomaceous fruit.", 219 | "FirstURL"=>"http://duckduckgo.com/apple"}, 220 | {"Name"=>"Companies", 221 | "Topics"=> 222 | [{"Text"=>"Apple Inc., a consumer electronics and software company", 223 | "Icon"=>{"URL"=>"http://i.duck.co/i/794fb31f.png"}, 224 | "Result"=> 225 | "Apple Inc., a consumer electronics and software company", 226 | "FirstURL"=>"http://duckduckgo.com/Apple_Inc."}, 227 | {"Text"=>"Apple Corps, a multimedia corporation founded by The Beatles", 228 | "Icon"=>{"URL"=>"http://i.duck.co/i/9e15faeb.jpg"}, 229 | "Result"=> 230 | "Apple Corps, a multimedia corporation founded by The Beatles", 231 | "FirstURL"=>"http://duckduckgo.com/Apple_Corps"}]}, 232 | {"Name"=>"Films", 233 | "Topics"=> 234 | [{"Text"=>"The Apple (1980 film), a 1980 musical science fiction film", 235 | "Icon"=>{"URL"=>"http://i.duck.co/i/ca3778cb.jpg"}, 236 | "Result"=> 237 | "The Apple (1980 film), a 1980 musical science fiction film", 238 | "FirstURL"=>"http://duckduckgo.com/The_Apple_(1980_film)"}, 239 | {"Text"=>"The Apple (1998 film), by Samira Makhmalbaf", 240 | "Icon"=>{"URL"=>"http://i.duck.co/i/51c5a500.jpg"}, 241 | "Result"=> 242 | "The Apple (1998 film), by Samira Makhmalbaf", 243 | "FirstURL"=>"http://duckduckgo.com/The_Apple_(1998_film)"}]}, 244 | {"Name"=>"Television", 245 | "Topics"=> 246 | [{"Text"=> 247 | "\"The Apple\" (Star Trek: The Original Series), a second season episode", 248 | "Icon"=>{"URL"=>"http://i.duck.co/i/7fc88794.jpg"}, 249 | "Result"=> 250 | "\"The Apple\" (Star Trek: The Original Series), a second season episode", 251 | "FirstURL"=> 252 | "http://duckduckgo.com/The_Apple_(Star_Trek%3A_The_Original_Series)"}]}, 253 | {"Name"=>"Music", 254 | "Topics"=> 255 | [{"Text"=>"Apple (album), an album by Mother Love Bone", 256 | "Icon"=>{"URL"=>"http://i.duck.co/i/9ca01bdb.jpg"}, 257 | "Result"=> 258 | "Apple (album), an album by Mother Love Bone", 259 | "FirstURL"=>"http://duckduckgo.com/Apple_(album)"}, 260 | {"Text"=>"Apple (band), a British psychedelic rock band", 261 | "Icon"=>{}, 262 | "Result"=> 263 | "Apple (band), a British psychedelic rock band", 264 | "FirstURL"=>"http://duckduckgo.com/Apple_(band)"}, 265 | {"Text"=>"The Apples, an early 90s Scottish indie-dance band", 266 | "Icon"=>{}, 267 | "Result"=> 268 | "The Apples, an early 90s Scottish indie-dance band", 269 | "FirstURL"=>"http://duckduckgo.com/The_Apples"}, 270 | {"Text"=>"The Apples (Israeli), a mid 2000s Israeli funk band", 271 | "Icon"=>{}, 272 | "Result"=> 273 | "The Apples (Israeli), a mid 2000s Israeli funk band", 274 | "FirstURL"=>"http://duckduckgo.com/The_Apples_(Israeli)"}, 275 | {"Text"=>"Apple Records, record label founded by The Beatles", 276 | "Icon"=>{"URL"=>"http://i.duck.co/i/9e15faeb.jpg"}, 277 | "Result"=> 278 | "Apple Records, record label founded by The Beatles", 279 | "FirstURL"=>"http://duckduckgo.com/Apple_Records"}]}, 280 | {"Name"=>"People", 281 | "Topics"=> 282 | [{"Text"=> 283 | "Apple Martin, the daughter of Gwyneth Paltrow and Chris Martin", 284 | "Icon"=>{"URL"=>"http://i.duck.co/i/f762256a.jpg"}, 285 | "Result"=> 286 | "Apple Martin, the daughter of Gwyneth Paltrow and Chris Martin", 287 | "FirstURL"=>"http://duckduckgo.com/Gwyneth_Paltrow"}, 288 | {"Text"=>"Billy Apple, artist", 289 | "Icon"=>{}, 290 | "Result"=> 291 | "Billy Apple, artist", 292 | "FirstURL"=>"http://duckduckgo.com/Billy_Apple"}, 293 | {"Text"=> 294 | "Fiona Apple, a Grammy award winning American singer-songwriter", 295 | "Icon"=>{"URL"=>"http://i.duck.co/i/f5f38669.jpg"}, 296 | "Result"=> 297 | "Fiona Apple, a Grammy award winning American singer-songwriter", 298 | "FirstURL"=>"http://duckduckgo.com/Fiona_Apple"}, 299 | {"Text"=>"Raymond Apple (rabbi), from Australia", 300 | "Icon"=>{}, 301 | "Result"=> 302 | "Raymond Apple (rabbi), from Australia", 303 | "FirstURL"=>"http://duckduckgo.com/Raymond_Apple_(rabbi)"}, 304 | {"Text"=> 305 | "Constance M. K. Applebee (1873\342\200\2231981), athlete, known as \"The Apple\"", 306 | "Icon"=>{}, 307 | "Result"=> 308 | "Constance M. K. Applebee (1873\342\200\2231981), athlete, known as \"The Apple\"", 309 | "FirstURL"=>"http://duckduckgo.com/Constance_M._K._Applebee"}]}, 310 | {"Name"=>"Places", 311 | "Topics"=> 312 | [{"Text"=>"Apple River Meanings", 313 | "Icon"=>{}, 314 | "Result"=> 315 | "Apple River Meanings", 316 | "FirstURL"=>"http://duckduckgo.com/d/Apple_River"}, 317 | {"Text"=>"Apple Valley Meanings", 318 | "Icon"=>{}, 319 | "Result"=> 320 | "Apple Valley Meanings", 321 | "FirstURL"=>"http://duckduckgo.com/d/Apple_Valley"}, 322 | {"Text"=>"Big Apple, nickname for New York City", 323 | "Icon"=>{"URL"=>"http://i.duck.co/i/a8cb4202.jpg"}, 324 | "Result"=> 325 | "Big Apple, nickname for New York City", 326 | "FirstURL"=>"http://duckduckgo.com/Big_Apple"}]}, 327 | {"Name"=>"Technology", 328 | "Topics"=> 329 | [{"Text"=> 330 | "Apple I - The Apple I, also known as the Apple-1, was an early personal computer.", 331 | "Icon"=>{"URL"=>"http://i.duck.co/i/020104f2.jpg"}, 332 | "Result"=> 333 | "Apple I - The Apple I, also known as the Apple-1, was an early personal computer.", 334 | "FirstURL"=>"http://duckduckgo.com/Apple_I"}, 335 | {"Text"=> 336 | "Apple II - The Apple II is an 8-bit home computer, one of the first highly successful mass-produced microcomputer products, designed primarily by Steve Wozniak, manufactured by Apple Computer and introduce...", 337 | "Icon"=>{"URL"=>"http://i.duck.co/i/e96a6b64.jpg"}, 338 | "Result"=> 339 | "Apple II - The Apple II is an 8-bit home computer, one of the first highly successful mass-produced microcomputer products, designed primarily by Steve Wozniak, manufactured by Apple Computer and introduce...", 340 | "FirstURL"=>"http://duckduckgo.com/Apple_II_series"}, 341 | {"Text"=> 342 | "Apple III - The Apple III is a business-oriented personal computer produced and released by Apple Computer and was intended as the successor to the Apple II series, but largely considered a failure in the m...", 343 | "Icon"=>{"URL"=>"http://i.duck.co/i/3702da39.jpg"}, 344 | "Result"=> 345 | "Apple III - The Apple III is a business-oriented personal computer produced and released by Apple Computer and was intended as the successor to the Apple II series, but largely considered a failure in the m...", 346 | "FirstURL"=>"http://duckduckgo.com/Apple_III"}, 347 | {"Text"=> 348 | "APPLE (Ariane Passenger Payload Experiment), an Indian experimental communication satellite launched in 1981", 349 | "Icon"=>{}, 350 | "Result"=> 351 | "APPLE (Ariane Passenger Payload Experiment), an Indian experimental communication satellite launched in 1981", 352 | "FirstURL"=> 353 | "http://duckduckgo.com/Ariane_Passenger_Payload_Experiment"}, 354 | {"Text"=> 355 | "Apple (automobile), an American automobile manufactured by Apple Automobile Company from 1917 to 1918", 356 | "Icon"=>{}, 357 | "Result"=> 358 | "Apple (automobile), an American automobile manufactured by Apple Automobile Company from 1917 to 1918", 359 | "FirstURL"=>"http://duckduckgo.com/Apple_(automobile)"}]}, 360 | {"Name"=>"Other uses", 361 | "Topics"=> 362 | [{"Text"=> 363 | "APPLE (Accumulation Program for Part-time and Limited-service Employees), a deferred compensation program in California", 364 | "Icon"=>{}, 365 | "Result"=> 366 | "APPLE (Accumulation Program for Part-time and Limited-service Employees), a deferred compensation program in California", 367 | "FirstURL"=>"http://duckduckgo.com/deferred_compensation"}, 368 | {"Text"=> 369 | "Apples (card game) - Apples is a 4-player trick-based game similar in play to hearts, spades, and bridge.", 370 | "Icon"=>{}, 371 | "Result"=> 372 | "Apples (card game) - Apples is a 4-player trick-based game similar in play to hearts, spades, and bridge.", 373 | "FirstURL"=>"http://duckduckgo.com/Apples_(card_game)"}, 374 | {"Text"=> 375 | "Apple Cup, the annual college football game between state rivals the University of Washington and Washington State University", 376 | "Icon"=>{}, 377 | "Result"=> 378 | "Apple Cup, the annual college football game between state rivals the University of Washington and Washington State University", 379 | "FirstURL"=>"http://duckduckgo.com/Apple_Cup"}, 380 | {"Text"=>"Apple Daily, a Hong-Kong-based newspaper", 381 | "Icon"=>{"URL"=>"http://i.duck.co/i/a220d44b.jpg"}, 382 | "Result"=> 383 | "Apple Daily, a Hong-Kong-based newspaper", 384 | "FirstURL"=>"http://duckduckgo.com/Apple_Daily"}, 385 | {"Text"=> 386 | "Apple (symbolism) - Apples appear in many religious traditions, often as a mystical or forbidden fruit.", 387 | "Icon"=>{"URL"=>"http://i.duck.co/i/b58eb2b4.jpg"}, 388 | "Result"=> 389 | "Apple (symbolism) - Apples appear in many religious traditions, often as a mystical or forbidden fruit.", 390 | "FirstURL"=>"http://duckduckgo.com/Apple_(symbolism)"}, 391 | {"Text"=>"Apples, Vaud, a municipality in Switzerland", 392 | "Icon"=>{"URL"=>"http://i.duck.co/i/88722dce.png"}, 393 | "Result"=> 394 | "Apples, Vaud, a municipality in Switzerland", 395 | "FirstURL"=>"http://duckduckgo.com/Apples%2C_Vaud"}]}, 396 | {"Name"=>"See also", 397 | "Topics"=> 398 | [{"Text"=>"Apple shape, one of the four basic female body shapes", 399 | "Icon"=>{"URL"=>"http://i.duck.co/i/458fcf42.jpg"}, 400 | "Result"=> 401 | "Apple shape, one of the four basic female body shapes", 402 | "FirstURL"=>"http://duckduckgo.com/female_body_shape"}, 403 | {"Text"=> 404 | "Apple Store (online) - The Apple Store is the online store of Apple Inc.. All of Apple's product lines are carried as well as select brands of accessories for its products.", 405 | "Icon"=>{}, 406 | "Result"=> 407 | "Apple Store (online) - The Apple Store is the online store of Apple Inc.. All of Apple's product lines are carried as well as select brands of accessories for its products.", 408 | "FirstURL"=>"http://duckduckgo.com/Apple_Store_(online)"}, 409 | {"Text"=>"Big Apple Meanings", 410 | "Icon"=>{}, 411 | "Result"=> 412 | "Big Apple Meanings", 413 | "FirstURL"=>"http://duckduckgo.com/d/Big_Apple"}, 414 | {"Text"=>"Golden apple Meanings", 415 | "Icon"=>{}, 416 | "Result"=> 417 | "Golden apple Meanings", 418 | "FirstURL"=>"http://duckduckgo.com/d/Golden_apple"}, 419 | {"Text"=>"The Apple Meanings", 420 | "Icon"=>{}, 421 | "Result"=> 422 | "The Apple Meanings", 423 | "FirstURL"=>"http://duckduckgo.com/d/The_Apple"}, 424 | {"Text"=>"The Little Apple Meanings", 425 | "Icon"=>{}, 426 | "Result"=> 427 | "The Little Apple Meanings", 428 | "FirstURL"=>"http://duckduckgo.com/d/The_Little_Apple"}, 429 | {"Text"=>"Apel - Apel is a German surname.", 430 | "Icon"=>{}, 431 | "Result"=> 432 | "Apel - Apel is a German surname.", 433 | "FirstURL"=>"http://duckduckgo.com/Apel"}, 434 | {"Text"=>"Appel Meanings", 435 | "Icon"=>{}, 436 | "Result"=> 437 | "Appel Meanings", 438 | "FirstURL"=>"http://duckduckgo.com/d/Appel"}, 439 | {"Text"=>"APPEL Meanings", 440 | "Icon"=>{}, 441 | "Result"=> 442 | "APPEL Meanings", 443 | "FirstURL"=>"http://duckduckgo.com/d/APPEL"}, 444 | {"Text"=>"Apple Trees, a 1992 German film", 445 | "Icon"=>{}, 446 | "Result"=> 447 | "Apple Trees, a 1992 German film", 448 | "FirstURL"=>"http://duckduckgo.com/Apple_Trees"}, 449 | {"Text"=>"The Apple Tree, a series of three musical playlets", 450 | "Icon"=>{"URL"=>"http://i.duck.co/i/a53248fd.png"}, 451 | "Result"=> 452 | "The Apple Tree, a series of three musical playlets", 453 | "FirstURL"=>"http://duckduckgo.com/The_Apple_Tree"}]}], 454 | "AbstractURL"=>"http://en.wikipedia.org/wiki/Apple_(disambiguation)", 455 | "Image"=>"", 456 | "DefinitionURL"=> 457 | "http://www.thefreedictionary.com/_/search.aspx?pid=aff18&word=apple", 458 | "DefinitionSource"=>"TheFreeDictionary", 459 | "AbstractText"=>"", 460 | "Type"=>"D"} 461 | 462 | 463 | zci = DuckDuckGo::ZeroClickInfo.by(data) 464 | 465 | assert_equal("Apple", zci.heading) 466 | assert_equal("Wikipedia", zci.abstract_source) 467 | assert_nil(zci.image) 468 | assert_nil(zci.abstract_text) 469 | assert_equal("TheFreeDictionary", zci.definition_source) 470 | assert_equal("A deciduous Eurasian tree having alternate simple leaves and white or pink flowers.", zci.definition) 471 | assert_instance_of(URI::HTTP, zci.definition_url) 472 | assert_nil(zci.answer_type) 473 | assert_equal("D", zci.type) 474 | assert_equal("disambiguation", zci.type_long) 475 | assert_nil(zci.answer) 476 | assert_instance_of(URI::HTTP, zci.abstract_url) 477 | assert_equal('en.wikipedia.org', zci.abstract_url.host) 478 | assert_equal(0, zci.results.size) 479 | assert_equal(10, zci.related_topics.size) 480 | assert_equal(1, zci.related_topics["_"].size) 481 | assert_equal("The apple is a tree and its pomaceous fruit.", zci.related_topics["_"][0].text) 482 | assert_not_nil(zci.related_topics["Companies"]) 483 | assert_equal(2, zci.related_topics["Companies"].size) 484 | assert_equal("Apple Inc., a consumer electronics and software company", zci.related_topics["Companies"][0].text) 485 | end 486 | 487 | def test_zci_category 488 | 489 | data = {"AbstractSource"=>"Wikipedia", 490 | "Answer"=>"", 491 | "Definition"=>"", 492 | "Results"=>[], 493 | "AnswerType"=>"", 494 | "Abstract"=>"", 495 | "Heading"=>"The Simpsons characters", 496 | "RelatedTopics"=> 497 | [{"Text"=> 498 | "Abraham Simpson - Abraham Jay \"Abe\" Simpson (voiced by Dan Castellaneta), known near universally simply as Grampa, is a fictional character in the animated television series The Simpsons.", 499 | "Icon"=>{"URL"=>"http://i.duck.co/i/7b1c968b.png"}, 500 | "Result"=> 501 | "Abraham Simpson
Abraham Jay \"Abe\" Simpson (voiced by Dan Castellaneta), known near universally simply as Grampa, is a fictional character in the animated television series The Simpsons.", 502 | "FirstURL"=>"http://duckduckgo.com/Abraham_Simpson"}, 503 | {"Text"=> 504 | "Apu Nahasapeemapetilon - Apu Nahasapeemapetilon, Ph.D. is a character in the animated television series The Simpsons.", 505 | "Icon"=>{"URL"=>"http://i.duck.co/i/3dfa3dc3.png"}, 506 | "Result"=> 507 | "Apu Nahasapeemapetilon
Apu Nahasapeemapetilon, Ph.D. is a character in the animated television series The Simpsons.", 508 | "FirstURL"=>"http://duckduckgo.com/Apu_Nahasapeemapetilon"}, 509 | {"Text"=> 510 | "Barney Gumble - Barnard \"Barney\" Gumble is a fictional character on the American animated sitcom The Simpsons.", 511 | "Icon"=>{"URL"=>"http://i.duck.co/i/39ce98c0.png"}, 512 | "Result"=> 513 | "Barney Gumble
Barnard \"Barney\" Gumble is a fictional character on the American animated sitcom The Simpsons.", 514 | "FirstURL"=>"http://duckduckgo.com/Barney_Gumble"}, 515 | {"Text"=> 516 | "Bart Simpson - Bartholomew JoJo \"Bart\" Simpson is a fictional character in the animated television series The Simpsons and part of the eponymous family.", 517 | "Icon"=>{"URL"=>"http://i.duck.co/i/62a07d9e.png"}, 518 | "Result"=> 519 | "Bart Simpson
Bartholomew JoJo \"Bart\" Simpson is a fictional character in the animated television series The Simpsons and part of the eponymous family.", 520 | "FirstURL"=>"http://duckduckgo.com/Bart_Simpson"}, 521 | {"Text"=> 522 | "Carl Carlson - Carl Carlson, usually known simply as Carl, is a supporting character in the animated television series The Simpsons voiced by Hank Azaria.", 523 | "Icon"=>{"URL"=>"http://i.duck.co/i/f572e9ae.png"}, 524 | "Result"=> 525 | "Carl Carlson
Carl Carlson, usually known simply as Carl, is a supporting character in the animated television series The Simpsons voiced by Hank Azaria.", 526 | "FirstURL"=>"http://duckduckgo.com/Carl_Carlson"}, 527 | {"Text"=> 528 | "Clancy Wiggum - Chief Clancy Wiggum is a fictional character from the animated television series The Simpsons, voiced by Hank Azaria.", 529 | "Icon"=>{"URL"=>"http://i.duck.co/i/f0eb79ee.png"}, 530 | "Result"=> 531 | "Clancy Wiggum
Chief Clancy Wiggum is a fictional character from the animated television series The Simpsons, voiced by Hank Azaria.", 532 | "FirstURL"=>"http://duckduckgo.com/Clancy_Wiggum"}, 533 | {"Text"=> 534 | "Cletus Spuckler - Cletus Delroy Spuckler is a recurring character in the Fox animated series, The Simpsons, and is voiced by Hank Azaria.", 535 | "Icon"=>{"URL"=>"http://i.duck.co/i/4d663a85.gif"}, 536 | "Result"=> 537 | "Cletus Spuckler
Cletus Delroy Spuckler is a recurring character in the Fox animated series, The Simpsons, and is voiced by Hank Azaria.", 538 | "FirstURL"=>"http://duckduckgo.com/Cletus_Spuckler"}, 539 | {"Text"=> 540 | "Comic Book Guy - Jeff Albertson, best known as the Comic Book Guy, is a recurring fictional character in the animated television series The Simpsons.", 541 | "Icon"=>{"URL"=>"http://i.duck.co/i/911ab519.png"}, 542 | "Result"=> 543 | "Comic Book Guy
Jeff Albertson, best known as the Comic Book Guy, is a recurring fictional character in the animated television series The Simpsons.", 544 | "FirstURL"=>"http://duckduckgo.com/Comic_Book_Guy"}, 545 | {"Text"=> 546 | "Edna Krabappel - Edna Krabappel is a fictional character from the animated TV series The Simpsons, voiced by Marcia Wallace.", 547 | "Icon"=>{"URL"=>"http://i.duck.co/i/1bdfff5e.png"}, 548 | "Result"=> 549 | "Edna Krabappel
Edna Krabappel is a fictional character from the animated TV series The Simpsons, voiced by Marcia Wallace.", 550 | "FirstURL"=>"http://duckduckgo.com/Edna_Krabappel"}, 551 | {"Text"=> 552 | "Fat Tony - Fat Tony is a recurring character in the animated sitcom The Simpsons.", 553 | "Icon"=>{"URL"=>"http://i.duck.co/i/a4583d66.png"}, 554 | "Result"=> 555 | "Fat Tony
Fat Tony is a recurring character in the animated sitcom The Simpsons.", 556 | "FirstURL"=>"http://duckduckgo.com/Fat_Tony"}, 557 | {"Text"=> 558 | "Groundskeeper Willie - Groundskeeper Willie born William Mcdougal is a recurring character on The Simpsons, voiced by Dan Castellaneta.", 559 | "Icon"=>{"URL"=>"http://i.duck.co/i/f845601f.png"}, 560 | "Result"=> 561 | "Groundskeeper Willie
Groundskeeper Willie born William Mcdougal is a recurring character on The Simpsons, voiced by Dan Castellaneta.", 562 | "FirstURL"=>"http://duckduckgo.com/Groundskeeper_Willie"}, 563 | {"Text"=> 564 | "Hans Moleman - Hans Moleman is a recurring character in the animated television series The Simpsons.", 565 | "Icon"=>{"URL"=>"http://i.duck.co/i/9f651728.png"}, 566 | "Result"=> 567 | "Hans Moleman
Hans Moleman is a recurring character in the animated television series The Simpsons.", 568 | "FirstURL"=>"http://duckduckgo.com/Hans_Moleman"}, 569 | {"Text"=> 570 | "Homer Simpson - Homer Jay Simpson is a fictional main character in the animated television series The Simpsons and the father of the eponymous family.", 571 | "Icon"=>{"URL"=>"http://i.duck.co/i/bf0eb228.png"}, 572 | "Result"=> 573 | "Homer Simpson
Homer Jay Simpson is a fictional main character in the animated television series The Simpsons and the father of the eponymous family.", 574 | "FirstURL"=>"http://duckduckgo.com/Homer_Simpson"}, 575 | {"Text"=> 576 | "Joe Quimby - Mayor Joseph \"Joe\" Quimby, nicknamed \"Diamond Joe,\" is a recurring character from the animated television series The Simpsons.", 577 | "Icon"=>{"URL"=>"http://i.duck.co/i/93d80e95.png"}, 578 | "Result"=> 579 | "Joe Quimby
Mayor Joseph \"Joe\" Quimby, nicknamed \"Diamond Joe,\" is a recurring character from the animated television series The Simpsons.", 580 | "FirstURL"=>"http://duckduckgo.com/Joe_Quimby"}, 581 | {"Text"=> 582 | "Julius Hibbert - Dr. Julius M. Hibbert, M.D., is a recurring character on the animated series The Simpsons.", 583 | "Icon"=>{"URL"=>"http://i.duck.co/i/c9497b7e.png"}, 584 | "Result"=> 585 | "Julius Hibbert
Dr. Julius M. Hibbert, M.D., is a recurring character on the animated series The Simpsons.", 586 | "FirstURL"=>"http://duckduckgo.com/Julius_Hibbert"}, 587 | {"Text"=> 588 | "Kang and Kodos - Kang and Kodos are a duo of recurring characters in the animated television series The Simpsons.", 589 | "Icon"=>{"URL"=>"http://i.duck.co/i/be84f45b.png"}, 590 | "Result"=> 591 | "Kang and Kodos
Kang and Kodos are a duo of recurring characters in the animated television series The Simpsons.", 592 | "FirstURL"=>"http://duckduckgo.com/Kang_and_Kodos"}, 593 | {"Text"=> 594 | "Kent Brockman - Kent Brockman is a fictional character in the animated television series The Simpsons.", 595 | "Icon"=>{"URL"=>"http://i.duck.co/i/b6c36d00.jpg"}, 596 | "Result"=> 597 | "Kent Brockman
Kent Brockman is a fictional character in the animated television series The Simpsons.", 598 | "FirstURL"=>"http://duckduckgo.com/Kent_Brockman"}, 599 | {"Text"=> 600 | "Krusty the Clown - Herschel Shmoikel Pinchas Yerucham Krustofski, better known by the stage name Krusty the Clown, is a fictional character who suffers bipolarity in the animated television series The Simp...", 601 | "Icon"=>{"URL"=>"http://i.duck.co/i/caa07f01.png"}, 602 | "Result"=> 603 | "Krusty the Clown
Herschel Shmoikel Pinchas Yerucham Krustofski, better known by the stage name Krusty the Clown, is a fictional character who suffers bipolarity in the animated television series The Simp...", 604 | "FirstURL"=>"http://duckduckgo.com/Krusty_the_Clown"}, 605 | {"Text"=> 606 | "Lenny Leonard - Lenford Leonard, MPhys usually known simply as Lenny, is a supporting character in the Fox animated series The Simpsons, and is voiced by Harry Shearer.", 607 | "Icon"=>{"URL"=>"http://i.duck.co/i/76575c43.png"}, 608 | "Result"=> 609 | "Lenny Leonard
Lenford Leonard, MPhys usually known simply as Lenny, is a supporting character in the Fox animated series The Simpsons, and is voiced by Harry Shearer.", 610 | "FirstURL"=>"http://duckduckgo.com/Lenny_Leonard"}, 611 | {"Text"=> 612 | "Lionel Hutz - Lionel Hutz is a recurring character from the animated television series The Simpsons.", 613 | "Icon"=>{"URL"=>"http://i.duck.co/i/94d72e52.jpg"}, 614 | "Result"=> 615 | "Lionel Hutz
Lionel Hutz is a recurring character from the animated television series The Simpsons.", 616 | "FirstURL"=>"http://duckduckgo.com/Lionel_Hutz"}, 617 | {"Text"=> 618 | "Lisa Simpson - Lisa Marie Simpson is a fictional main character in the animated television series The Simpsons.", 619 | "Icon"=>{"URL"=>"http://i.duck.co/i/0c6d3b53.png"}, 620 | "Result"=> 621 | "Lisa Simpson
Lisa Marie Simpson is a fictional main character in the animated television series The Simpsons.", 622 | "FirstURL"=>"http://duckduckgo.com/Lisa_Simpson"}, 623 | {"Text"=> 624 | "Maggie Simpson - Margaret \"Maggie\" Simpson is a fictional character in the animated television series The Simpsons.", 625 | "Icon"=>{"URL"=>"http://i.duck.co/i/c018dead.png"}, 626 | "Result"=> 627 | "Maggie Simpson
Margaret \"Maggie\" Simpson is a fictional character in the animated television series The Simpsons.", 628 | "FirstURL"=>"http://duckduckgo.com/Maggie_Simpson"}, 629 | {"Text"=> 630 | "Marge Simpson - Marjorie \"Marge\" Simpson is a fictional main character in the animated television series The Simpsons and the matriarch of the eponymous family.", 631 | "Icon"=>{"URL"=>"http://i.duck.co/i/b75bd67d.png"}, 632 | "Result"=> 633 | "Marge Simpson
Marjorie \"Marge\" Simpson is a fictional main character in the animated television series The Simpsons and the matriarch of the eponymous family.", 634 | "FirstURL"=>"http://duckduckgo.com/Marge_Simpson"}, 635 | {"Text"=> 636 | "Martin Prince - Martin Prince, Jr. is a recurring character in the Fox animated series, The Simpsons, and is voiced by Russi Taylor.", 637 | "Icon"=>{"URL"=>"http://i.duck.co/i/eb68975c.png"}, 638 | "Result"=> 639 | "Martin Prince
Martin Prince, Jr. is a recurring character in the Fox animated series, The Simpsons, and is voiced by Russi Taylor.", 640 | "FirstURL"=>"http://duckduckgo.com/Martin_Prince"}, 641 | {"Text"=> 642 | "Milhouse Van Houten - Milhouse Mussolini Van Houten is a fictional character featured in the animated television series The Simpsons, voiced by Pamela Hayden.", 643 | "Icon"=>{"URL"=>"http://i.duck.co/i/c1923cb1.png"}, 644 | "Result"=> 645 | "Milhouse Van Houten
Milhouse Mussolini Van Houten is a fictional character featured in the animated television series The Simpsons, voiced by Pamela Hayden.", 646 | "FirstURL"=>"http://duckduckgo.com/Milhouse_Van_Houten"}, 647 | {"Text"=> 648 | "Moe Szyslak - Momar \"Moe\" Szyslak () is a fictional character in the American animated television series, The Simpsons.", 649 | "Icon"=>{"URL"=>"http://i.duck.co/i/388580ad.png"}, 650 | "Result"=> 651 | "Moe Szyslak
Momar \"Moe\" Szyslak () is a fictional character in the American animated television series, The Simpsons.", 652 | "FirstURL"=>"http://duckduckgo.com/Moe_Szyslak"}, 653 | {"Text"=> 654 | "Mona Simpson (The Simpsons) - Mona J. Simpson is a recurring fictional character in the animated television series The Simpsons.", 655 | "Icon"=>{"URL"=>"http://i.duck.co/i/ba6285fb.png"}, 656 | "Result"=> 657 | "Mona Simpson (The Simpsons)
Mona J. Simpson is a recurring fictional character in the animated television series The Simpsons.", 658 | "FirstURL"=>"http://duckduckgo.com/Mona_Simpson_(The_Simpsons)"}, 659 | {"Text"=> 660 | "Mr. Burns - Charles Montgomery Plantagenet Schicklgruber\"Monty\" Burns, usually referred to as Mr. Burns, is a recurring fictional character in the animated television series The Simpsons,...", 661 | "Icon"=>{"URL"=>"http://i.duck.co/i/cf311517.png"}, 662 | "Result"=> 663 | "Mr. Burns
Charles Montgomery Plantagenet Schicklgruber\"Monty\" Burns, usually referred to as Mr. Burns, is a recurring fictional character in the animated television series The Simpsons,...", 664 | "FirstURL"=>"http://duckduckgo.com/Mr._Burns"}, 665 | {"Text"=> 666 | "Ned Flanders - Nedward \"Ned\" Flanders is a recurring fictional character in the animated television series The Simpsons.", 667 | "Icon"=>{"URL"=>"http://i.duck.co/i/e66f380d.png"}, 668 | "Result"=> 669 | "Ned Flanders
Nedward \"Ned\" Flanders is a recurring fictional character in the animated television series The Simpsons.", 670 | "FirstURL"=>"http://duckduckgo.com/Ned_Flanders"}, 671 | {"Text"=> 672 | "Nelson Muntz - Nelson Mandela Muntz is a fictional character from the animated TV series The Simpsons.", 673 | "Icon"=>{"URL"=>"http://i.duck.co/i/23702790.png"}, 674 | "Result"=> 675 | "Nelson Muntz
Nelson Mandela Muntz is a fictional character from the animated TV series The Simpsons.", 676 | "FirstURL"=>"http://duckduckgo.com/Nelson_Muntz"}, 677 | {"Text"=> 678 | "Nick Riviera - Dr. Nick Riviera, M.D. is a fictional character on the animated television series The Simpsons.", 679 | "Icon"=>{"URL"=>"http://i.duck.co/i/db757c91.png"}, 680 | "Result"=> 681 | "Nick Riviera
Dr. Nick Riviera, M.D. is a fictional character on the animated television series The Simpsons.", 682 | "FirstURL"=>"http://duckduckgo.com/Nick_Riviera"}, 683 | {"Text"=> 684 | "Otto Mann - Otto Mann is a fictional character on the animated TV series The Simpsons, voiced by Harry Shearer.", 685 | "Icon"=>{"URL"=>"http://i.duck.co/i/9ba5c930.png"}, 686 | "Result"=> 687 | "Otto Mann
Otto Mann is a fictional character on the animated TV series The Simpsons, voiced by Harry Shearer.", 688 | "FirstURL"=>"http://duckduckgo.com/Otto_Mann"}, 689 | {"Text"=> 690 | "Patty and Selma Bouvier - Patty and Selma Bouvier () are fictional twins in the Fox Broadcasting animated series, The Simpsons, and are voiced by Julie Kavner.", 691 | "Icon"=>{"URL"=>"http://i.duck.co/i/9f1ecf46.png"}, 692 | "Result"=> 693 | "Patty and Selma Bouvier
Patty and Selma Bouvier () are fictional twins in the Fox Broadcasting animated series, The Simpsons, and are voiced by Julie Kavner.", 694 | "FirstURL"=>"http://duckduckgo.com/Patty_and_Selma_Bouvier"}, 695 | {"Text"=> 696 | "Professor Frink - Professor John Nerdelbaum Frink, Jr. is a recurring character in the American animated television series The Simpsons.", 697 | "Icon"=>{"URL"=>"http://i.duck.co/i/c9dc0e13.png"}, 698 | "Result"=> 699 | "Professor Frink
Professor John Nerdelbaum Frink, Jr. is a recurring character in the American animated television series The Simpsons.", 700 | "FirstURL"=>"http://duckduckgo.com/Professor_Frink"}, 701 | {"Text"=> 702 | "Ralph Wiggum - Ralph Wiggum is a recurring fictional character on the animated series The Simpsons, voiced by Nancy Cartwright.", 703 | "Icon"=>{"URL"=>"http://i.duck.co/i/2f9c97eb.png"}, 704 | "Result"=> 705 | "Ralph Wiggum
Ralph Wiggum is a recurring fictional character on the animated series The Simpsons, voiced by Nancy Cartwright.", 706 | "FirstURL"=>"http://duckduckgo.com/Ralph_Wiggum"}, 707 | {"Text"=> 708 | "Reverend Timothy Lovejoy - The Reverend Timothy Lovejoy is a recurring character in the animated television series The Simpsons.", 709 | "Icon"=>{"URL"=>"http://i.duck.co/i/5359e785.png"}, 710 | "Result"=> 711 | "Reverend Timothy Lovejoy
The Reverend Timothy Lovejoy is a recurring character in the animated television series The Simpsons.", 712 | "FirstURL"=>"http://duckduckgo.com/Reverend_Timothy_Lovejoy"}, 713 | {"Text"=> 714 | "Santa's Little Helper - Santa's Little Helper is a fictional dog.", 715 | "Icon"=>{"URL"=>"http://i.duck.co/i/6825f3f5.png"}, 716 | "Result"=> 717 | "Santa's Little Helper
Santa's Little Helper is a fictional dog.", 718 | "FirstURL"=>"http://duckduckgo.com/Santa's_Little_Helper"}, 719 | {"Text"=> 720 | "Seymour Skinner - W. Seymour Skinner (born Armin Tamzarian) is a fictional character on the animated sitcom The Simpsons who is voiced by Harry Shearer.", 721 | "Icon"=>{"URL"=>"http://i.duck.co/i/785a66ec.png"}, 722 | "Result"=> 723 | "Seymour Skinner
W. Seymour Skinner (born Armin Tamzarian) is a fictional character on the animated sitcom The Simpsons who is voiced by Harry Shearer.", 724 | "FirstURL"=>"http://duckduckgo.com/Seymour_Skinner"}, 725 | {"Text"=> 726 | "Sideshow Bob - Robert Underdunk-Terwilliger, better known by his stage name Sideshow Bob, is a recurring character in the animated television series The Simpsons.", 727 | "Icon"=>{"URL"=>"http://i.duck.co/i/922b6a1c.png"}, 728 | "Result"=> 729 | "Sideshow Bob
Robert Underdunk-Terwilliger, better known by his stage name Sideshow Bob, is a recurring character in the animated television series The Simpsons.", 730 | "FirstURL"=>"http://duckduckgo.com/Sideshow_Bob"}, 731 | {"Text"=> 732 | "Snowball (The Simpsons) - The name Snowball refers to five fictional cats that have been owned by the Simpson family in the TV show The Simpsons.", 733 | "Icon"=>{"URL"=>"http://i.duck.co/i/6a833a5a.png"}, 734 | "Result"=> 735 | "Snowball (The Simpsons)
The name Snowball refers to five fictional cats that have been owned by the Simpson family in the TV show The Simpsons.", 736 | "FirstURL"=>"http://duckduckgo.com/Snowball_(The_Simpsons)"}, 737 | {"Text"=> 738 | "The Itchy & Scratchy Show - The Itchy & Scratchy Show is a fictional animated television series from The Simpsons.", 739 | "Icon"=>{"URL"=>"http://i.duck.co/i/d8a3a294.png"}, 740 | "Result"=> 741 | "The Itchy & Scratchy Show
The Itchy & Scratchy Show is a fictional animated television series from The Simpsons.", 742 | "FirstURL"=>"http://duckduckgo.com/The_Itchy_%26_Scratchy_Show"}, 743 | {"Text"=> 744 | "Troy McClure - Troy McClure is a fictional character in the American animated sitcom The Simpsons.", 745 | "Icon"=>{"URL"=>"http://i.duck.co/i/20433a15.png"}, 746 | "Result"=> 747 | "Troy McClure
Troy McClure is a fictional character in the American animated sitcom The Simpsons.", 748 | "FirstURL"=>"http://duckduckgo.com/Troy_McClure"}, 749 | {"Text"=> 750 | "Waylon Smithers - Waylon Smithers, Jr. usually referred to as Smithers is a recurring fictional character in the animated series The Simpsons, who is voiced by Harry Shearer.", 751 | "Icon"=>{"URL"=>"http://i.duck.co/i/12f25a94.png"}, 752 | "Result"=> 753 | "Waylon Smithers
Waylon Smithers, Jr. usually referred to as Smithers is a recurring fictional character in the animated series The Simpsons, who is voiced by Harry Shearer.", 754 | "FirstURL"=>"http://duckduckgo.com/Waylon_Smithers"}], 755 | "AbstractURL"=>"http://en.wikipedia.org/wiki/The_Simpsons_characters", 756 | "Image"=>"", 757 | "DefinitionURL"=>"", 758 | "DefinitionSource"=>"", 759 | "AbstractText"=>"", 760 | "Type"=>"C"} 761 | 762 | zci = DuckDuckGo::ZeroClickInfo.by(data) 763 | 764 | assert_equal("The Simpsons characters", zci.heading) 765 | assert_equal("Wikipedia", zci.abstract_source) 766 | assert_nil(zci.image) 767 | assert_nil(zci.abstract_text) 768 | assert_nil(zci.definition_source) 769 | assert_nil(zci.definition_url) 770 | assert_nil(zci.answer_type) 771 | assert_equal("C", zci.type) 772 | assert_equal("category", zci.type_long) 773 | assert_nil(zci.answer) 774 | assert_instance_of(URI::HTTP, zci.abstract_url) 775 | assert_equal('en.wikipedia.org', zci.abstract_url.host) 776 | assert_equal(0, zci.results.size) 777 | assert_equal(1, zci.related_topics.size) 778 | assert_equal(43, zci.related_topics["_"].size) 779 | assert_equal("Abraham Simpson - Abraham Jay \"Abe\" Simpson (voiced by Dan Castellaneta), known near universally simply as Grampa, is a fictional character in the animated television series The Simpsons.", zci.related_topics["_"][0].text) 780 | end 781 | 782 | def test_zci_exclusive 783 | 784 | data = {"AbstractSource"=>"Wikipedia", 785 | "Answer"=>"", 786 | "Definition"=> 787 | "Lorem ipsum - A common piece of text used as mock- content when testing a given page layout or font.", 788 | "Results"=> 789 | [{"Text"=> 790 | "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante hendrerit. Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean ut gravida lorem. Ut turpis felis, pulvinar a semper sed, adipiscing id dolor. Pellentesque auctor nisi id magna consequat sagittis. Curabitur dapibus enim sit amet elit pharetra tincidunt feugiat nisl imperdiet. Ut convallis libero in urna ultrices accumsan. Donec sed odio eros. Donec viverra mi quis quam pulvinar at malesuada arcu rhoncus. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. In rutrum accumsan ultricies. Mauris vitae nisi at sem facilisis semper ac in est.

- Vivamus fermentum semper porta. Nunc diam velit, adipiscing ut tristique vitae, sagittis vel odio. Maecenas convallis ullamcorper ultricies. Curabitur ornare, ligula semper consectetur sagittis, nisi diam iaculis velit, id fringilla sem nunc vel mi. Nam dictum, odio nec pretium volutpat, arcu ante placerat erat, non tristique elit urna et turpis. Quisque mi metus, ornare sit amet fermentum et, tincidunt et orci. Fusce eget orci a orci congue vestibulum. Ut dolor diam, elementum et vestibulum eu, porttitor vel elit. Curabitur venenatis pulvinar tellus gravida ornare. Sed et erat faucibus nunc euismod ultricies ut id justo. Nullam cursus suscipit nisi, et ultrices justo sodales nec. Fusce venenatis facilisis lectus ac semper. Aliquam at massa ipsum. Quisque bibendum purus convallis nulla ultrices ultricies. Nullam aliquam, mi eu aliquam tincidunt, purus velit laoreet tortor, viverra pretium nisi quam vitae mi. Fusce vel volutpat elit. Nam sagittis nisi dui.

- Suspendisse lectus leo, consectetur in tempor sit amet, placerat quis neque. Etiam luctus porttitor lorem, sed suscipit est rutrum non. Curabitur lobortis nisl a enim congue semper. Aenean commodo ultrices imperdiet. Vestibulum ut justo vel sapien venenatis tincidunt. Phasellus eget dolor sit amet ipsum dapibus condimentum vitae quis lectus. Aliquam ut massa in turpis dapibus convallis. Praesent elit lacus, vestibulum at malesuada et, ornare et est. Ut augue nunc, sodales ut euismod non, adipiscing vitae orci. Mauris ut placerat justo. Mauris in ultricies enim. Quisque nec est eleifend nulla ultrices egestas quis ut quam. Donec sollicitudin lectus a mauris pulvinar id aliquam urna cursus. Cras quis ligula sem, vel elementum mi. Phasellus non ullamcorper urna.

- Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. In euismod ultrices facilisis. Vestibulum porta sapien adipiscing augue congue id pretium lectus molestie. Proin quis dictum nisl. Morbi id quam sapien, sed vestibulum sem. Duis elementum rutrum mauris sed convallis. Proin vestibulum magna mi. Aenean tristique hendrerit magna, ac facilisis nulla hendrerit ut. Sed non tortor sodales quam auctor elementum. Donec hendrerit nunc eget elit pharetra pulvinar. Suspendisse id tempus tortor. Aenean luctus, elit commodo laoreet commodo, justo nisi consequat massa, sed vulputate quam urna quis eros. Donec vel.  ", 791 | "Icon"=>{"URL"=>"", "Width"=>16, "Height"=>16}, 792 | "Result"=> 793 | "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante hendrerit. Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean ut gravida lorem. Ut turpis felis, pulvinar a semper sed, adipiscing id dolor. Pellentesque auctor nisi id magna consequat sagittis. Curabitur dapibus enim sit amet elit pharetra tincidunt feugiat nisl imperdiet. Ut convallis libero in urna ultrices accumsan. Donec sed odio eros. Donec viverra mi quis quam pulvinar at malesuada arcu rhoncus. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. In rutrum accumsan ultricies. Mauris vitae nisi at sem facilisis semper ac in est.


Vivamus fermentum semper porta. Nunc diam velit, adipiscing ut tristique vitae, sagittis vel odio. Maecenas convallis ullamcorper ultricies. Curabitur ornare, ligula semper consectetur sagittis, nisi diam iaculis velit, id fringilla sem nunc vel mi. Nam dictum, odio nec pretium volutpat, arcu ante placerat erat, non tristique elit urna et turpis. Quisque mi metus, ornare sit amet fermentum et, tincidunt et orci. Fusce eget orci a orci congue vestibulum. Ut dolor diam, elementum et vestibulum eu, porttitor vel elit. Curabitur venenatis pulvinar tellus gravida ornare. Sed et erat faucibus nunc euismod ultricies ut id justo. Nullam cursus suscipit nisi, et ultrices justo sodales nec. Fusce venenatis facilisis lectus ac semper. Aliquam at massa ipsum. Quisque bibendum purus convallis nulla ultrices ultricies. Nullam aliquam, mi eu aliquam tincidunt, purus velit laoreet tortor, viverra pretium nisi quam vitae mi. Fusce vel volutpat elit. Nam sagittis nisi dui.


Suspendisse lectus leo, consectetur in tempor sit amet, placerat quis neque. Etiam luctus porttitor lorem, sed suscipit est rutrum non. Curabitur lobortis nisl a enim congue semper. Aenean commodo ultrices imperdiet. Vestibulum ut justo vel sapien venenatis tincidunt. Phasellus eget dolor sit amet ipsum dapibus condimentum vitae quis lectus. Aliquam ut massa in turpis dapibus convallis. Praesent elit lacus, vestibulum at malesuada et, ornare et est. Ut augue nunc, sodales ut euismod non, adipiscing vitae orci. Mauris ut placerat justo. Mauris in ultricies enim. Quisque nec est eleifend nulla ultrices egestas quis ut quam. Donec sollicitudin lectus a mauris pulvinar id aliquam urna cursus. Cras quis ligula sem, vel elementum mi. Phasellus non ullamcorper urna.


Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. In euismod ultrices facilisis. Vestibulum porta sapien adipiscing augue congue id pretium lectus molestie. Proin quis dictum nisl. Morbi id quam sapien, sed vestibulum sem. Duis elementum rutrum mauris sed convallis. Proin vestibulum magna mi. Aenean tristique hendrerit magna, ac facilisis nulla hendrerit ut. Sed non tortor sodales quam auctor elementum. Donec hendrerit nunc eget elit pharetra pulvinar. Suspendisse id tempus tortor. Aenean luctus, elit commodo laoreet commodo, justo nisi consequat massa, sed vulputate quam urna quis eros. Donec vel.  ", 794 | "FirstURL"=>"http://lipsum.com"}], 795 | "AnswerType"=>"", 796 | "Abstract"=>"", 797 | "Heading"=>"Lorem Ipsum", 798 | "RelatedTopics"=>[], 799 | "AbstractURL"=>"http://en.wikipedia.org/wiki/Lorem_Ipsum", 800 | "Image"=>"", 801 | "DefinitionURL"=> 802 | "http://www.merriam-webster.com/dictionary/lorem ipsum", 803 | "DefinitionSource"=>"TheFreeDictionary", 804 | "AbstractText"=>"", 805 | "Type"=>"E"} 806 | 807 | zci = DuckDuckGo::ZeroClickInfo.by(data) 808 | 809 | assert_equal("Lorem Ipsum", zci.heading) 810 | assert_equal("Wikipedia", zci.abstract_source) 811 | assert_nil(zci.image) 812 | assert_nil(zci.abstract_text) 813 | assert_equal("TheFreeDictionary", zci.definition_source) 814 | assert_equal("Lorem ipsum - A common piece of text used as mock- content when testing a given page layout or font.", zci.definition) 815 | assert_instance_of(URI::HTTP, zci.definition_url) 816 | assert_nil(zci.answer_type) 817 | assert_equal("E", zci.type) 818 | assert_equal("exclusive", zci.type_long) 819 | assert_nil(zci.answer) 820 | assert_instance_of(URI::HTTP, zci.abstract_url) 821 | assert_equal('en.wikipedia.org', zci.abstract_url.host) 822 | assert_equal(1, zci.results.size) 823 | assert_equal(0, zci.related_topics.size) 824 | end 825 | end 826 | --------------------------------------------------------------------------------