Skip to content

A PHP client for working with Wikidata API.

Notifications You must be signed in to change notification settings

konigbach/wikidata

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Wikidata Build Status

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 label:

$results = $wikidata->search('London');

Search by Wikidata property ID and string value:

$results = $wikidata->searchBy('P238', 'LON');

Search by Wikidata property ID and entity ID:

$results = $wikidata->searchBy('P17', 'Q146');

Check if no search results

if($results->isEmpty()) {
  echo 'no results';
  die();
}

Result

Retrieve first result data

$singleResult = $results->first();

Get result ID

$resultId = $singleResult->id; // Q84

Get result label

$resultLabel = $singleResult->label; // London

Get result aliases

$resultAliases = $singleResult->aliases; // [ 'London, UK', 'London, United Kingdom', 'London, England' ]

Get result description

$resultDescription = $singleResult->description; // capital of England and the United Kingdom

Entity

Get single entity by ID:

$entity = $wikidata->get('Q26');

Get entity ID

$entityId = $entity->id; // Q26

Get entity label

$entityLabel = $entity->label; // Northern Ireland

Get entity aliases

$entityAliases = $entity->aliases; // [ 'NIR', 'UKN', 'North Ireland' ]

Get entity description

$entityDescription = $entity->description; // region in north-west Europe, part of the United Kingdom

Get list of all available properties for specific entity

$properties = $entity->properties; // array(1) { [0]=> string(11) "instance_of", ... }

Get value specific property

$official_language = $entity->get('official_language'); // array(1) { [0]=> string(7) "English" }

That's all.

License

Wikidata is licensed under the MIT license.

About

A PHP client for working with Wikidata API.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%