Knowledge graph api

From LemonWiki共筆
Jump to navigation Jump to search

List of Knowledge graph API

List of Knowledge graph API[edit]

Understanding the DuckDuckGo Instant Answers API[edit]

API Endpoint Structure https://api.duckduckgo.com/?format=<FORMAT>&q=<QUERY>

Where:

  • <FORMAT> specifies the response format (e.g., json)
  • <QUERY> is your URL-encoded search term (e.g., Keira Christina Knightley)

Example: https://api.duckduckgo.com/?format=json&q=who%20is%20girl%20friend%20of%20Simba

Demonstration search term: "Keira Christina Knightley"

  • Web Search Experience: When visiting the DuckDuckGo search page, users see an information card with text like: "Keira Christina Knightley OBE is an English actress. Known for her work in independent films and blockbusters, particularly period dramas..."
  • API Integration: This same biographical information can be programmatically accessed via the Instant Answers API in the "AbstractText" or "Abstract" field of the JSON response.
Example output of DuckDuckGo Instant Answers API (click to show)

{
   "Abstract" : "Keira Christina Knightley OBE is an English actress. Known for her work in independent films and blockbusters, particularly period dramas, she has received numerous accolades, including nominations for two Academy Awards, two British Academy Film Awards, four Golden Globes, and a Laurence Olivier Award. In 2018, she was appointed an OBE at Buckingham Palace for services to drama and charity. Born in London to actors Will Knightley and Sharman Macdonald, Knightley obtained an agent at age six and initially worked in commercials and television films. Following a minor role as Sab\u00e9 in Star Wars: Episode I \u2013 The Phantom Menace, her breakthrough came when she played a tomboy footballer in Bend It Like Beckham and co-starred in Love Actually. She achieved global recognition for playing Elizabeth Swann in the Pirates of the Caribbean film series. For her portrayal of Elizabeth Bennet in Pride & Prejudice, Knightley was nominated for the Academy Award for Best Actress.",
   "AbstractSource" : "Wikipedia",
   "AbstractText" : "Keira Christina Knightley OBE is an English actress. Known for her work in independent films and blockbusters, particularly period dramas, she has received numerous accolades, including nominations for two Academy Awards, two British Academy Film Awards, four Golden Globes, and a Laurence Olivier Award. In 2018, she was appointed an OBE at Buckingham Palace for services to drama and charity. Born in London to actors Will Knightley and Sharman Macdonald, Knightley obtained an agent at age six and initially worked in commercials and television films. Following a minor role as Sab\u00e9 in Star Wars: Episode I \u2013 The Phantom Menace, her breakthrough came when she played a tomboy footballer in Bend It Like Beckham and co-starred in Love Actually. She achieved global recognition for playing Elizabeth Swann in the Pirates of the Caribbean film series. For her portrayal of Elizabeth Bennet in Pride & Prejudice, Knightley was nominated for the Academy Award for Best Actress.",
   "AbstractURL" : "https://en.wikipedia.org/wiki/Keira_Knightley",
   "Answer" : "",
   "AnswerType" : "",
   "Definition" : "",
   "DefinitionSource" : "",
   "DefinitionURL" : "",
   "Entity" : "actor",
   "Heading" : "Keira Knightley",
   "Image" : "/i/4a6ac0950a7fdca2.jpg",
   "ImageHeight" : 270,
   "ImageIsLogo" : 0,
   "ImageWidth" : 203,
   "Infobox" : {
      "content" : [
         {
            "data_type" : "string",
            "label" : "Born",
            "value" : "Keira Christina Knightley, March 26, 1985, London, England",
            "wiki_order" : 0
         },
         {
            "data_type" : "string",
            "label" : "Age",
            "value" : "40 years",
            "wiki_order" : 0
         },
         {
            "data_type" : "string",
            "label" : "Occupation",
            "value" : "Actress",
            "wiki_order" : 1
         },
         {
            "data_type" : "string",
            "label" : "Years active",
            "value" : "1991\u2013present",
            "wiki_order" : 2
         },
         {
            "data_type" : "string",
            "label" : "Children",
            "value" : "2",
            "wiki_order" : 4
         },
         {
            "data_type" : "string",
            "label" : "Parent(s)",
            "value" : "Will Knightley, Sharman Macdonald",
            "wiki_order" : 5
         },
         {
            "data_type" : "instagram_profile",
            "label" : "Instagram profile",
            "value" : "keiraknightley",
            "wiki_order" : "103"
         },
         {
            "data_type" : "imdb_id",
            "label" : "IMDb ID",
            "value" : "nm0461136",
            "wiki_order" : "106"
         },
         {
            "data_type" : "rotten_tomatoes",
            "label" : "Rotten Tomatoes ID",
            "value" : "celebrity/kiira_naiteulri",
            "wiki_order" : "107"
         },
         {
            "data_type" : "spotify_artist_id",
            "label" : "Spotify Artist ID",
            "value" : "2MG46ekjBSFwPgzoIZvHFU",
            "wiki_order" : "108"
         },
         {
            "data_type" : "instance",
            "label" : "Instance of",
            "value" : {
               "entity-type" : "item",
               "id" : "Q5",
               "numeric-id" : 5
            },
            "wiki_order" : "207"
         },
         {
            "data_type" : "date_of_birth",
            "label" : "Born",
            "value" : {
               "after" : 0,
               "before" : 0,
               "calendarmodel" : "http://www.wikidata.org/entity/Q1985727",
               "precision" : 11,
               "time" : "+1985-03-26T00:00:00Z",
               "timezone" : 0
            },
            "wiki_order" : "209"
         },
         {
            "data_type" : "wd_description",
            "label" : "Wikidata description",
            "value" : "British actress",
            "wiki_order" : "210"
         },
         {
            "data_type" : "wikidata_id",
            "label" : "Wikidata id",
            "value" : "Q42581",
            "wiki_order" : "211"
         },
         {
            "data_type" : "wikidata_label",
            "label" : "Wikidata label",
            "value" : "Keira Knightley",
            "wiki_order" : "212"
         },
         {
            "data_type" : "wikidata_aliases",
            "label" : "Wikidata aliases",
            "value" : [
               "Keira Knightley",
               "Keira Christina Knightley",
               "Keira Christina Righton"
            ],
            "wiki_order" : "213"
         }
      ],
      "meta" : [
         {
            "data_type" : "string",
            "label" : "article_title",
            "value" : "Keira Knightley"
         },
         {
            "data_type" : "string",
            "label" : "template_name",
            "value" : "infobox person"
         },
         {
            "data_type" : "string",
            "label" : "above",
            "value" : "Keira Knightley"
         },
         {
            "data_type" : "string",
            "label" : "caption",
            "value" : "Knightley in 2011"
         }
      ]
   },
   "Redirect" : "",
   "RelatedTopics" : [
      {
         "FirstURL" : "https://duckduckgo.com/c/English_video_game_actresses",
         "Icon" : {
            "Height" : "",
            "URL" : "",
            "Width" : ""
         },
         "Result" : "<a href=\"https://duckduckgo.com/c/English_video_game_actresses\">English video game actresses</a>",
         "Text" : "English video game actresses"
      },
      {
         "FirstURL" : "https://duckduckgo.com/c/English_radio_actresses",
         "Icon" : {
            "Height" : "",
            "URL" : "",
            "Width" : ""
         },
         "Result" : "<a href=\"https://duckduckgo.com/c/English_radio_actresses\">English radio actresses</a>",
         "Text" : "English radio actresses"
      },
      {
         "FirstURL" : "https://duckduckgo.com/c/English_child_actresses",
         "Icon" : {
            "Height" : "",
            "URL" : "",
            "Width" : ""
         },
         "Result" : "<a href=\"https://duckduckgo.com/c/English_child_actresses\">English child actresses</a>",
         "Text" : "English child actresses"
      },
      {
         "FirstURL" : "https://duckduckgo.com/c/English_people_with_disabilities",
         "Icon" : {
            "Height" : "",
            "URL" : "",
            "Width" : ""
         },
         "Result" : "<a href=\"https://duckduckgo.com/c/English_people_with_disabilities\">English people with disabilities</a>",
         "Text" : "English people with disabilities"
      },
      {
         "FirstURL" : "https://duckduckgo.com/c/English_voice_actresses",
         "Icon" : {
            "Height" : "",
            "URL" : "",
            "Width" : ""
         },
         "Result" : "<a href=\"https://duckduckgo.com/c/English_voice_actresses\">English voice actresses</a>",
         "Text" : "English voice actresses"
      },
      {
         "FirstURL" : "https://duckduckgo.com/c/English_atheists",
         "Icon" : {
            "Height" : "",
            "URL" : "",
            "Width" : ""
         },
         "Result" : "<a href=\"https://duckduckgo.com/c/English_atheists\">English atheists</a>",
         "Text" : "English atheists"
      }
   ],
   "Results" : [],
   "Type" : "A",
   "meta" : {
      "attribution" : null,
      "blockgroup" : null,
      "created_date" : null,
      "description" : "Wikipedia",
      "designer" : null,
      "dev_date" : null,
      "dev_milestone" : "live",
      "developer" : [
         {
            "name" : "DDG Team",
            "type" : "ddg",
            "url" : "http://www.duckduckhack.com"
         }
      ],
      "example_query" : "nikola tesla",
      "id" : "wikipedia_fathead",
      "is_stackexchange" : null,
      "js_callback_name" : "wikipedia",
      "live_date" : null,
      "maintainer" : {
         "github" : "duckduckgo"
      },
      "name" : "Wikipedia",
      "perl_module" : "DDG::Fathead::Wikipedia",
      "producer" : null,
      "production_state" : "online",
      "repo" : "fathead",
      "signal_from" : "wikipedia_fathead",
      "src_domain" : "en.wikipedia.org",
      "src_id" : 1,
      "src_name" : "Wikipedia",
      "src_options" : {
         "directory" : "",
         "is_fanon" : 0,
         "is_mediawiki" : 1,
         "is_wikipedia" : 1,
         "language" : "en",
         "min_abstract_length" : "20",
         "skip_abstract" : 0,
         "skip_abstract_paren" : 0,
         "skip_end" : "0",
         "skip_icon" : 0,
         "skip_image_name" : 0,
         "skip_qr" : "",
         "source_skip" : "",
         "src_info" : ""
      },
      "src_url" : null,
      "status" : "live",
      "tab" : "About",
      "topic" : [
         "productivity"
      ],
      "unsafe" : 0
   }
}

To check the API result, open the URL directly.

Known Limitation Icon_exclaim.gif: There's currently a discrepancy between web search results and API responses for certain queries. For instance, searching for "height of eiffel tower" produces different results depending on whether you use the web interface or the API endpoint.

References[edit]