PHP code example of freearhey / knowledge-graph
1. Go to this page and download the library: Download freearhey/knowledge-graph library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
freearhey / knowledge-graph example snippets
use KnowledgeGraph\Client;
use KnowledgeGraph\KnowledgeGraph;
$client = new Client();
$client->setKey('YOUR_API_KEY'); // More about API Key here: https://developers.google.com/knowledge-graph/how-tos/authorizing
$graph = new KnowledgeGraph($client);
$results = $graph->search($query, $type, $lang, $limit);
$results = $graph->search('taylor swift');
/*
Collection {
#items: array:20 [
0 => SearchResult {
id: "/m/0dl567"
score: 1466.352905
name: "Taylor Swift"
type: array:2 [
0 => "Thing"
1 => "Person"
]
description: "American singer"
image: array:2 [
"contentUrl" => "http://t0.gstatic.com/images?q=tbn:ANd9GcST848UJ0u31E6aoQfb2nnKZFyad7rwNF0ZLOCACGpu4jnboEzV"
"url" => "https://en.wikipedia.org/wiki/Begin_Again_(Taylor_Swift_song)"
]
detailedDescription: array:3 [
"articleBody" => "Taylor Alison Swift is an American singer-songwriter. As one of the world's leading contemporary recording artists, she is known for narrative songs about her p ▶"
"url" => "https://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/"
}
...
]
}
*/
$results = $graph->find($id, $lang);
$results = $graph->find('/m/02j81');
/*
SearchResult {
id: "/m/02j81"
score: 26.98455
name: "Eiffel Tower"
type: array:5 [
0 => "Thing"
1 => "CivicStructure"
2 => "Place"
3 => "TouristAttraction"
4 => "Organization"
]
description: "Tower in Paris, France"
image: array:2 [
"contentUrl" => "http://t1.gstatic.com/images?q=tbn:ANd9GcSao5YmaJqJVcSi60m9ypkaIC6bjKVJdoocuGBzgyTIu4MaMJ-t"
"url" => "https://commons.wikimedia.org/wiki/File:Eiffel_tower.svg"
]
detailedDescription: array:3 [
"articleBody" => "The Eiffel Tower is a wrought-iron lattice tower on the Champ de Mars in Paris, France. It is named after the engineer Gustave Eiffel, whose company designed an ▶"
"url" => "https://en.wikipedia.org/wiki/Eiffel_Tower"
"license" => "https://en.wikipedia.org/wiki/Wikipedia:Text_of_Creative_Commons_Attribution-ShareAlike_3.0_Unported_License"
]
url: "http://www.eiffel-tower.com/"
}
*/