Google Knowledge Graph Search API

文章推薦指數: 80 %
投票人數:10人

The Knowledge Graph has millions of entries that describe real-world entities like people, places, and things. These entities form the nodes of ... Google SearchCentral KnowledgeGraphSearchAPI Language English BahasaIndonesia Deutsch Español Français Português–Brasil Русский 中文–简体 日本語 한국어 Signin Guides Reference Google SearchCentral KnowledgeGraphSearchAPI Guides Reference GetStarted IntroductionPrerequisites HowTo... InstallClientLibrariesAuthorizeRequestsUsetheKnowledgeGraphSearchWidget TermsofService Home SearchCentral KnowledgeGraphSearchAPI GoogleKnowledgeGraphSearchAPI TheKnowledgeGraphSearchAPIletsyoufindentitiesintheGoogleKnowledgeGraph. TheAPIusesstandardschema.orgtypesandiscompliantwiththe JSON-LDspecification. Typicalusecases SomeexamplesofhowyoucanusetheKnowledgeGraphSearchAPIinclude: Gettingarankedlistofthemostnotableentitiesthatmatchcertaincriteria. Predictivelycompletingentitiesinasearchbox. Annotating/organizingcontentusingtheKnowledgeGraphentities. Note:TheKnowledgeGraphSearchAPIisaread-onlyAPI.Warning:ThisAPIisnotsuitableforuseasaproduction-criticalservice.Your productshouldnotformacriticaldependenceonthisAPI. FordetailedinformationabouttheAPImethodsandparameters,seethe APIReference. Samplerequest ThefollowingexampleshowsonekindofrequestyoucansendtotheAPI. (ButcheckthePrerequisitessectionfirst. You'llalsoneedtoinsertyourownAPIkey.) https://kgsearch.googleapis.com/v1/entities:search?query=taylor+swift&key=API_KEY&limit=1&indent=True ThesamplesearchabovereturnsaJSON-LDresultsimilartothefollowing: { "@context":{ "@vocab":"http://schema.org/", "goog":"http://schema.googleapis.com/", "resultScore":"goog:resultScore", "detailedDescription":"goog:detailedDescription", "EntitySearchResult":"goog:EntitySearchResult", "kg":"http://g.co/kg" }, "@type":"ItemList", "itemListElement":[ { "@type":"EntitySearchResult", "result":{ "@id":"kg:/m/0dl567", "name":"TaylorSwift", "@type":[ "Thing", "Person" ], "description":"Singer-songwriter", "image":{ "contentUrl":"https://t1.gstatic.com/images?q=tbn:ANd9GcQmVDAhjhWnN2OWys2ZMO3PGAhupp5tN2LwF_BJmiHgi19hf8Ku", "url":"https://en.wikipedia.org/wiki/Taylor_Swift", "license":"http://creativecommons.org/licenses/by-sa/2.0" }, "detailedDescription":{ "articleBody":"TaylorAlisonSwiftisanAmericansinger-songwriterandactress.RaisedinWyomissing,Pennsylvania,shemovedtoNashville,Tennessee,attheageof14topursueacareerincountrymusic.", "url":"http://en.wikipedia.org/wiki/Taylor_Swift", "license":"https://en.wikipedia.org/wiki/Wikipedia:Text_of_Creative_Commons_Attribution-ShareAlike_3.0_Unported_License" }, "url":"http://taylorswift.com/" }, "resultScore":4850 } ] } Note:TheKnowledgeGraphSearchAPIreturnsonlyindividualmatchingentities, ratherthangraphsofinterconnectedentities.Ifyouneedthelatter,we recommendusingdatadumpsfromWikidatainstead. Thefollowingcodesamplesshowhowtoperformasimilarsearchinvarioussupported languages.ThissearchreturnsentriesmatchingTaylorSwift. Python """ExampleofPythonclientcallingKnowledgeGraphSearchAPI.""" importjson importurllib api_key=open('.api_key').read() query='TaylorSwift' service_url='https://kgsearch.googleapis.com/v1/entities:search' params={ 'query':query, 'limit':10, 'indent':True, 'key':api_key, } url=service_url+'?'+urllib.urlencode(params) response=json.loads(urllib.urlopen(url).read()) forelementinresponse['itemListElement']: print(element['result']['name']+'('+str(element['resultScore'])+')') Java packagecom.google.knowledge.platforms.syndication.entitymatch.codesample; importcom.google.api.client.http.GenericUrl; importcom.google.api.client.http.HttpRequest; importcom.google.api.client.http.HttpRequestFactory; importcom.google.api.client.http.HttpResponse; importcom.google.api.client.http.HttpTransport; importcom.google.api.client.http.javanet.NetHttpTransport; importcom.jayway.jsonpath.JsonPath; importjava.io.FileInputStream; importjava.util.Properties; importorg.json.simple.JSONArray; importorg.json.simple.JSONObject; importorg.json.simple.parser.JSONParser; /**ExampleofJavaclientcallingKnowledgeGraphSearchAPI*/ publicclassSearchExample{ publicstaticPropertiesproperties=newProperties(); publicstaticvoidmain(String[]args){ try{ properties.load(newFileInputStream("kgsearch.properties")); HttpTransporthttpTransport=newNetHttpTransport(); HttpRequestFactoryrequestFactory=httpTransport.createRequestFactory(); JSONParserparser=newJSONParser(); GenericUrlurl=newGenericUrl("https://kgsearch.googleapis.com/v1/entities:search"); url.put("query","TaylorSwift"); url.put("limit","10"); url.put("indent","true"); url.put("key",properties.get("API_KEY")); HttpRequestrequest=requestFactory.buildGetRequest(url); HttpResponsehttpResponse=request.execute(); JSONObjectresponse=(JSONObject)parser.parse(httpResponse.parseAsString()); JSONArrayelements=(JSONArray)response.get("itemListElement"); for(Objectelement:elements){ System.out.println(JsonPath.read(element,"$.result.name").toString()); } }catch(Exceptionex){ ex.printStackTrace(); } } } Javascript

PHP 'TaylorSwift', 'limit'=>10, 'indent'=>TRUE, 'key'=>$api_key); $url=$service_url.'?'.http_build_query($params); $ch=curl_init(); curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); $response=json_decode(curl_exec($ch),true); curl_close($ch); foreach($response['itemListElement']as$element){ echo$element['result']['name'].'
'; } KnowledgeGraphentities TheKnowledgeGraphhasmillionsofentriesthatdescribereal-worldentities likepeople,places,andthings.Theseentitiesformthenodesofthegraph. ThefollowingaresomeofthetypesofentitiesfoundintheKnowledgeGraph: Book BookSeries EducationalOrganization Event GovernmentOrganization LocalBusiness Movie MovieSeries MusicAlbum MusicGroup MusicRecording Organization Periodical Person Place SportsTeam TVEpisode TVSeries VideoGame VideoGameSeries WebSite Exceptasotherwisenoted,thecontentofthispageislicensedundertheCreativeCommonsAttribution4.0License,andcodesamplesarelicensedundertheApache2.0License.Fordetails,seetheGoogleDevelopersSitePolicies.JavaisaregisteredtrademarkofOracleand/oritsaffiliates. Lastupdated2021-12-10UTC. [{ "type":"thumb-down", "id":"missingTheInformationINeed", "label":"MissingtheinformationIneed" },{ "type":"thumb-down", "id":"tooComplicatedTooManySteps", "label":"Toocomplicated/toomanysteps" },{ "type":"thumb-down", "id":"outOfDate", "label":"Outofdate" },{ "type":"thumb-down", "id":"samplesCodeIssue", "label":"Samples/codeissue" },{ "type":"thumb-down", "id":"otherDown", "label":"Other" }] [{ "type":"thumb-up", "id":"easyToUnderstand", "label":"Easytounderstand" },{ "type":"thumb-up", "id":"solvedMyProblem", "label":"Solvedmyproblem" },{ "type":"thumb-up", "id":"otherUp", "label":"Other" }] Connect Blog Facebook Medium Twitter YouTube Programs WomenTechmakers GoogleDeveloperGroups GoogleDevelopersExperts Accelerators GoogleDeveloperStudentClubs Developerconsoles GoogleAPIConsole GoogleCloudPlatformConsole GooglePlayConsole FirebaseConsole ActionsonGoogleConsole CastSDKDeveloperConsole ChromeWebStoreDashboard Android Chrome Firebase GoogleCloudPlatform Allproducts Terms Privacy SignupfortheGoogleDevelopersnewsletter Subscribe Language English BahasaIndonesia Deutsch Español Français Português–Brasil Русский 中文–简体 日本語 한국어


請為這篇文章評分?