jamesfrost / wikidata
A PHP client for working with Wikidata API.
1.0.2
2017-02-27 11:58 UTC
Requires
- php: >=5.4.0
This package is not auto-updated.
Last update: 2025-03-29 22:48:48 UTC
README
Wikidata provides a API for searching and retrieving data from wikidata.org.
Installation
composer require freearhey/wikidata
Usage
$wikidata = new Wikidata;
Search
Search by entity title:
$result = $wikidata->search('steve jobs');
Check if no search results
if($result->isEmpty()) { echo 'no results'; die(); }
Retrieve first entity in result list
$singleResult = $result->first();
Retrieve all results
$allResults = $result->get();
Get entity id
$entityId = $singleResult->getEntityId(); // Q26
Entities
Get single entity by id:
$entities = $wikidata->entities('Q26');
Get single entity with preset language (default: en)
$entities = $wikidata->entities('Q26', 'fr');
Get few entities by id and more languages
$entities = $wikidata->entities('Q26|Q106', 'en|fr|ch');
Retrieve first entity
$entity = $entities->first();
Get all entities
$entity = $entities->get();
Get single entity by id
$entity = $entities->get('Q26');
Get entity label and description (default language: en)
$label = $entity->getLabel(); // Steve Jobs $description = $entity->getDescription('de'); // US-amerikanischer Unternehmer, Mitbegründer von Apple Computer
Get entity property values by property id (e.g. P21) if it exists. All list properties you can find here
$gender = $entity->getPropertyValues('P21'); // array(1) { [0]=> string(4) "male" }
And with language property (default: en)
$childs = $entity->getPropertyValues('P40', 'ru'); // array(1) { [0]=> string(35) "Бреннан-Джобс, Лиза" }
That's all.
License
Wikidata is licensed under the MIT license