freearhey/knowledge-graph
Composer 安装命令:
composer require freearhey/knowledge-graph
包简介
A simple PHP client for working with Google Knowledge Graph API
README 文档
README
A simple PHP client for working with Google Knowledge Graph API.
Installation
composer require freearhey/knowledge-graph
Usage
require_once('vendor/autoload.php'); 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);
Available Methods
search()
The search method give you a way to search in Knowledge Graph by entity name.
$results = $graph->search($query, $type, $lang, $limit);
Arguments:
$query: term to search (required)$type: specify the type of results (e.g. "Book") (List of available types: https://developers.google.com/knowledge-graph/)$lang: specify the results language$limit: set a custom limit (default: 20)
Example:
$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/" } ... ] } */
The search method always returns Illuminate\Support\Collection class with results. This means you can use all the methods available in Laravel's Collections.
find()
The find method give you a way to search by entity ID.
$results = $graph->find($id, $lang);
Arguments:
$id: ID to search (e.g. "/m/0dl567")$lang: specify the results language
Example:
$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/" } */
Testing
API_KEY=YOUR_API_KEY vendor/bin/phpunit
Contribution
If you find a bug or want to contribute to the code or documentation, you can help by submitting an issue or a pull request.
License
Knowledge Graph is licensed under the MIT license.
freearhey/knowledge-graph 适用场景与选型建议
freearhey/knowledge-graph 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 40.52k 次下载、GitHub Stars 达 5, 最近一次更新时间为 2017 年 10 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「api」 「client」 「google」 「graph」 「knowledge」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 freearhey/knowledge-graph 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 freearhey/knowledge-graph 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 freearhey/knowledge-graph 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A PSR-7 compatible library for making CRUD API endpoints
Mock PSR-18 HTTP client
Asynchronous MQTT client built on React
Client for Google Directions API to add interpolated points to a route consisting of given coordinates.
Alfabank REST API integration
A Flickr wrapper to allow you to call the Flickr api with Guzzle as the backend.Goal is to have 100% Flickr api coverage rather than just upload/display photos (currently at 23%).
统计信息
- 总下载量: 40.52k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-10-19