Skip to content

A simple way to get PHP objects of Wikidata items, from Sparql queries or for single items.

Notifications You must be signed in to change notification settings

samwilson/simple-wikidata

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple Wikidata

This is a simple (and limited, by design) package for interacting with Wikidata from PHP.

Packagist License GitHub issues Scrutinizer Code Quality Code Coverage Build Status

Example

// The Sparql must return an ?item column.
$sparql = "SELECT ?item WHERE { ?item wdt:P31 wd:Q54050 } LIMIT 5";
$cache = new \Stash\Pool(new \Stash\Driver\FileSystem());
$people = new \Samwilson\SimpleWikidata\Query($sparql, 'en', $cache);
foreach ($people->getItems() as $person) {
    // Each $person is an Item object.
    $person->getLabel();
    $person->getPropertyOfTypeItem();
    $person->getPropertyOfTypeQuantity();
    $person->getPropertyOfTypeIdentifier(); // External identifier
    $person->getPropertyOfTypeUrl();
    $person->getPropertyOfTypeTime();
    $person->getPropertyOfTypeString(); // No language
    $person->getPropertyOfTypeText(); // Has language
    $person->getPropertyOfTypeCoord();
    $person->getPropertyOfTypeFile(); // Commons media
}

Licence

GPL3.0+

About

A simple way to get PHP objects of Wikidata items, from Sparql queries or for single items.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages