freearhey/wikidata
Composer 安装命令:
composer require freearhey/wikidata
包简介
A PHP client for working with Wikidata API.
README 文档
README
Wikidata 
Wikidata provides a API for searching and retrieving data from wikidata.org.
Installation
composer require freearhey/wikidata
Usage
First we need to create an instance of Wikidata class and save it to some variable, like this:
require_once('vendor/autoload.php'); use Wikidata\Wikidata; $wikidata = new Wikidata();
after that we can use one of the available methods to access the Wikidata database.
Available Methods
search()
The search() method give you a way to find Wikidata entity by it label.
$results = $wikidata->search($query, $lang, $limit);
Arguments:
$query: term to search (required)$lang: specify the results language (default: 'en')$limit: set a custom limit (default: 10)
Example:
$results = $wikidata->search('car', 'fr', 5); /* Collection { #items: array:5 [ 0 => SearchResult { id: "Q1759802" lang: "fr" label: "autocar" wiki_url: "https://fr.wikipedia.org/wiki/autocar" description: "transport routier pouvant accueillir plusieurs voyageurs pour de longues distances" aliases: array:1 [ 0 => "car" ] } 1 => SearchResult { id: "Q224743" lang: "fr" label: "Car" wiki_url: "https://fr.wikipedia.org/wiki/Car" description: "page d'homonymie d'un projet Wikimédia" aliases: [] } ... ] } */
The search() method always returns Illuminate\Support\Collection class with results. This means you can use all the methods available in Laravel's Collections.
searchBy()
The searchBy help you to find Wikidata entities by it properties value.
$results = $wikidata->searchBy($propId, $entityId, $lang, $limit);
Arguments:
$propId: id of the property by which to search (required)$entityId: id of the entity (required)$lang: specify the results language (default: 'en')$limit: set a custom limit (default: 10)
Example:
// List of people who born in city Pomona, US $results = $wikidata->searchBy('P19', 'Q486868'); /* Collection { #items: array:10 [ 0 => SearchResult { id: "Q92638" lang: "en" label: "Robert Tarjan" wiki_url: "https://en.wikipedia.org/wiki/Robert_Tarjan" description: "American computer scientist" aliases: array:2 [ 0 => "Robert E. Tarjan" 1 => "Robert Endre Tarjan" ] } 1 => SearchResult { id: "Q184805" lang: "en" label: "Tom Waits" wiki_url: "https://en.wikipedia.org/wiki/Tom_Waits" description: "American singer-songwriter and actor" aliases: [] } ... ] } */
The searchBy() method always returns Illuminate\Support\Collection class with results. This means you can use all the methods available in Laravel's Collections.
get()
The get() returns Wikidata entity by specified ID.
$entity = $wikidata->get($entityId, $lang);
Arguments:
$entityId: id of the entity (required)$lang: specify the results language (default: 'en')
Example:
// Get all data about Steve Jobs $entity = $wikidata->get('Q19837'); /* Entity { id: "Q19837" lang: "en" label: "Steve Jobs" wiki_url: "https://en.wikipedia.org/wiki/Steve_Jobs" aliases: array:2 [ 0 => "Steven Jobs", 1 => "Steven Paul Jobs" ] description: "American entrepreneur and co-founder of Apple Inc." properties: Collection { ... } } */ // List of all properties as an array $properties = $entity->properties->toArray(); /* [ "P1006" => Property { id: "P1006" label: "NTA ID" values: Collection { #items: array:6 [ 0 => Value { id: "Q5593916" label: "Grammy Trustees Award" qualifiers: Collection { #items: array:1 [ 0 => Qualifier { id: "P585" label: "point in time" value: "2012-01-01T00:00:00Z" } ] } }, ... ] } }, ... ] */
Upgrade Guide
Upgrade to 3.2._ from 3.1._
The main changes in the new version have occurred in the way property values are stored. Now each property can have more than one value. In this regard, the attribute value in the Property object was replaced with the attribute values.
Also, values are now presented not as a string, but as an Value object. This allowed us to save along with each value not only its string representation but also a list of its qualifiers. Detailed information on what qualifiers is can be found here.
Testing
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
Wikidata is licensed under the MIT license.
freearhey/wikidata 适用场景与选型建议
freearhey/wikidata 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 29.57k 次下载、GitHub Stars 达 55, 最近一次更新时间为 2015 年 07 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「client」 「wikidata」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 freearhey/wikidata 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 freearhey/wikidata 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 freearhey/wikidata 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Serializers and deserializers for the Wikibase DataModel
Services around the Wikibase DataModel
Adds the EDTF data type to Wikibase
Provides line-by-line readers and iterators for Wikibase/Wikidata JSON dumps
A PHP client for working with Wikidata API.
Mock PSR-18 HTTP client
统计信息
- 总下载量: 29.57k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 56
- 点击次数: 13
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-07-05
