PHPackages                             ppp/wikibase-entity-store - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. ppp/wikibase-entity-store

ActiveLibrary[Database &amp; ORM](/categories/database)

ppp/wikibase-entity-store
=========================

A small library to store Wikibase entities

0.3.1(9y ago)71.1k4[5 issues](https://github.com/ProjetPP/WikibaseEntityStore/issues)GPL-2.0+PHPPHP &gt;=5.5.0

Since Feb 27Pushed 9y ago12 watchersCompare

[ Source](https://github.com/ProjetPP/WikibaseEntityStore)[ Packagist](https://packagist.org/packages/ppp/wikibase-entity-store)[ Docs](https://github.com/ProjetPP/WikibaseEntityStore)[ RSS](/packages/ppp-wikibase-entity-store/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (20)Versions (7)Used By (0)

WikibaseEntityStore
===================

[](#wikibaseentitystore)

[![Build Status](https://camo.githubusercontent.com/7da74000032897ab17b80580f44332887df5b2001ddadd0dcdcc817ca09ef99f/68747470733a2f2f7472617669732d63692e6f72672f50726f6a657450502f57696b6962617365456e7469747953746f72652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/ProjetPP/WikibaseEntityStore)[![Code Coverage](https://camo.githubusercontent.com/ffc7e2a56d8a41e1e045eac487bf1ff0726a7d8c96944e3f419377e33057c48d/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f50726f6a657450502f57696b6962617365456e7469747953746f72652f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/ProjetPP/WikibaseEntityStore/?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/177f1a813326ccf214055a7823f588a2d0b3fc156342b0dfaa0acf0aab2c20f8/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f50726f6a657450502f57696b6962617365456e7469747953746f72652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/ProjetPP/WikibaseEntityStore/?branch=master)[![Dependency Status](https://camo.githubusercontent.com/782a86182602d8c613637830b2581ef3ffcb4580b96bf46545bc13d06bbdd084/68747470733a2f2f7777772e76657273696f6e6579652e636f6d2f7068702f7070703a77696b69626173652d656e746974792d73746f72652f6465762d6d61737465722f62616467652e737667)](https://www.versioneye.com/php/ppp:wikibase-entity-store/dev-master)

On [Packagist](https://packagist.org/packages/ppp/wikibase-entity-store): [![Latest Stable Version](https://camo.githubusercontent.com/3d11059ea5ddfc8ef53d1fdd4254886cafc1c598778022cfa51c9839b8f8c5eb/68747470733a2f2f706f7365722e707567782e6f72672f7070702f77696b69626173652d656e746974792d73746f72652f76657273696f6e2e706e67)](https://packagist.org/packages/ppp/wikibase-entity-store)[![Download count](https://camo.githubusercontent.com/bf9a995ef7174f550153a9f95de13d59648e11ee5be98bc6ec34f875a6b92467/68747470733a2f2f706f7365722e707567782e6f72672f7070702f77696b69626173652d656e746974792d73746f72652f642f746f74616c2e706e67)](https://packagist.org/packages/ppp/wikibase-entity-store)

WikibaseEntityStore is a small library that provides an unified interface to interact with Wikibase entities.

It currently has two backends:

- An API based backend, slow but very easy to deploy
- A MongoDB based backend, faster but requires to maintain a local copy of Wikibase content

Installation
------------

[](#installation)

Use one of the below methods:

1 - Use composer to install the library and all its dependencies using the master branch:

```
composer require "ppp/wikibase-entity-store":dev-master"

```

2 - Create a composer.json file that just defines a dependency on version 1.0 of this package, and run 'composer install' in the directory:

```
{
    "require": {
        "ppp/wikibase-entity-store": "~1.0"
    }
}
```

Usage
-----

[](#usage)

### Features

[](#features)

The entity storage system is based on the abstract class EntityStore that provides different services to manipulate entities.

These services are:

```
$storeBuilder = new EntityStoreFromConfigurationBuilder();
$store = $storeBuilder->buildEntityStore( 'MY_CONFIG_FILE.json' ); //See backend section for examples of configuration file

//Retrieves the item Q1
try {
    $item = $store->getItemLookup()->getItemForId( new ItemId( 'Q1' ) );
} catch( ItemNotFoundException $e ) {
    //Item not found
}

//Retrieves the property P1
try {
    $item = $store->getPropertyLookup()->getPropertyForId( new PropertyId( 'P1' ) );
} catch( PropertyNotFoundException $e ) {
    //Property not found
}

//Retrieves the item Q1 as EntityDocument
try {
    $item = $store->getEntityLookup()->getEntityDocumentForId( new ItemId( 'Q1' ) );
} catch( EntityNotFoundException $e ) {
    //Property not found
}

//Retrieves the item Q1 and the property P1 as EntityDocuments
$entities = $store->getEntityLookup()->getEntityDocumentsForIds( array( new ItemId( 'Q1' ), new PropertyId( 'P1' ) ) );

//Retrieves the ids of the items that have as label or alias the term "Nyan Cat" in English (with a case insensitive compare)
$itemIds = $store->getItemIdForTermLookup()->getItemIdsForTerm( new Term( 'en', 'Nyan Cat' ) );

//Retrieves the ids of the properties that have as label or alias the term "foo" in French (with a case insensitive compare)
$propertyIds = $store->getPropertyIdForTermLookup()->getPropertyIdsForTerm( new Term( 'fr', 'Foo' ) );

//Do a query on items using the Ask query language: retrieves the first 10 items with P1: Q1
$itemIds = $store->getItemIdForQueryLookup()->getItemIdsForQuery(
    new Query(
        new SomeProperty(
	        new EntityIdValue( new PropertyId( 'P1' ) ),
			new ValueDescription( new EntityIdValue( new ItemId( 'Q1' ) ) )
		),
		array(),
		new QueryOptions( 10, 0 )
	)
);
```

### Backends

[](#backends)

#### API Backend

[](#api-backend)

The API backend is the most easy to use one. It uses the API of a Wikibase instance and WikidataQuery if you use this EntityStore as a backend for Wikidata data and you want query support.

The configuration file looks like:

```
{
    "backend": "api",
    "api": {
        "url": "http://www.wikidata.org/w/api.php",
        "wikidataquery-url": "http://wdq.wmflabs.org/api"
    }
}
```

Replace `http://www.wikidata.org/w/api.php` with the URL of your WediaWiki API if you want to use your store with an other Wikibase instance than Wikidata.

The parameter `wikidataquery-url` is optional and may be unset if you don't want query support using Wikidata content.

Without configuration file:

```
$store = new \Wikibase\EntityStore\Api\ApiEntityStore(
    new \Mediawiki\Api\MediawikiApi( 'http://www.wikidata.org/w/api.php' ),
    new \WikidataQueryApi\WikidataQueryApi( 'http://wdq.wmflabs.org/api' )
);
```

#### MongoDB Backend

[](#mongodb-backend)

The MongoDB backend uses a MongoDB database. Requires [doctrine/mongodb](https://packagist.org/packages/doctrine/mongodb).

The configuration file looks like:

```
{
    "backend": "mongodb",
    "mongodb": {
        "server": SERVER,
        "database": DATABASE
    }
}
```

`server` should be a [MongoDB server connection string](http://docs.mongodb.org/manual/reference/connection-string/) and `database` the name of the database to use.

Without configuration file:

```
//Connect to MongoDB
$connection = new \Doctrine\MongoDB\Connection( MY_CONNECTION_STRING );
if( !$connection->connect() ) {
    throw new RuntimeException( 'Fail to connect to the database' );
}

//Gets the database where entities are stored
$database = $connection
    ->selectDatabase( 'wikibase' );

$store = new \Wikibase\EntityStore\MongoDB\MongDBEntityStore( $database );
```

You can fill the MongoDB database from Wikidata JSON dumps using this script:

```
 php entitystore import-json-dump MY_JSON_DUMP MY_CONFIGURATION_FILE

```

Or from incremental XML dumps using this script:

```
php entitystore import-incremental-xml-dump MY_XML_DUMP MY_CONFIGURATION_FILE

```

#### InMemory backend

[](#inmemory-backend)

Backend based on an array of EntityDocuments. Useful for tests.

```
$store = new \Wikibase\EntityStore\InMemory\InMemoryEntityStore( array(
    new Item( new ItemId( 'Q42' ) )
) );
```

### Options

[](#options)

The different backends support a shared set of options. These options are:

- *string\[\]* `languages`: Allows to filter the set of internationalized values. Default value: `null` (a.k.a. all languages).
- *bool* `languagefallback`: Apply language fallback system to languages defined using languages option. Default value: `false`.

They can be injected in the configuration:

```
{
  "options": {
    "languages": ["en", "fr"],
    "languagefallback": true
  }
}
```

They can be also passed as last parameter of `EntityStore` constructors:

```
$options = new \Wikibase\EntityStore\EntityStoreOptions( array(
	EntityStore::OPTION_LANGUAGES => array( 'en', 'fr' ),
	EntityStore::OPTION_LANGUAGE_FALLBACK => true
) );

$store = new \Wikibase\EntityStore\Api\ApiEntityStore(
    new \Mediawiki\Api\MediawikiApi( 'http://www.wikidata.org/w/api.php' ),
    null,
    $options
);
```

### Cache support

[](#cache-support)

It is possible, in order to get far better performances, to add a cache layer on top of EntityStore:

Adds to the configuration file a `cache` section.

Example with a two layers cache. The first one is a PHP array and the second one a Memcached instance on `localhost:11211`.

```
{
    "cache": {
        "array": true,
        "memcached": {
            "host": "localhost",
            "port": 11211
        }
    }
}
```

Without configuration file:

```
$store = MY_ENTITY_STORE;

$cache = new \Doctrine\Common\Cache\ArrayCache(); //A very simple cache
$cacheLifeTime = 100000; //Life time of cache in seconds

$cachedStore = new \Wikibase\EntityStore\Cache\CachedEntityStore( $store, $cache, $cacheLifeTime );
```

Release notes
-------------

[](#release-notes)

### 0.3.1 (2016-01-11)

[](#031-2016-01-11)

- Adds support of WikibaseDataModel 5.0 and 6.0 and Number 0.7

### 0.3.0 (2016-01-11)

[](#030-2016-01-11)

- Update to WikibaseDataModel 4.0, WikibaseDataModelServices 3.2 and MediaWikiApiBase 2.0
- Change encoding of label indexes in MongoDB

### 0.1.0 (2015-04-21)

[](#010-2015-04-21)

Initial release with these features:

- Retrieve entities from ids or terms
- Import Wikidata JSON full dumps and incremental XML dumps
- Beginning of support of simple queries
- API and MongoDB backends
- Basic cache system

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance6

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 99.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~148 days

Total

4

Last Release

3593d ago

PHP version history (2 changes)0.1PHP &gt;=5.3.0

0.2PHP &gt;=5.5.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/d7990f77322db52f51a2f919eacdef7dd4e94e37b44b96fd71d3f6b0505557c2?d=identicon)[Tpt](/maintainers/Tpt)

---

Top Contributors

[![Tpt](https://avatars.githubusercontent.com/u/458123?v=4)](https://github.com/Tpt "Tpt (129 commits)")[![JeroenDeDauw](https://avatars.githubusercontent.com/u/146040?v=4)](https://github.com/JeroenDeDauw "JeroenDeDauw (1 commits)")

---

Tags

wikidatawikibase

###  Code Quality

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/ppp-wikibase-entity-store/health.svg)

```
[![Health](https://phpackages.com/badges/ppp-wikibase-entity-store/health.svg)](https://phpackages.com/packages/ppp-wikibase-entity-store)
```

###  Alternatives

[guikingone/scheduler-bundle

A Symfony bundle that allows to schedule and create repetitive tasks

114217.4k](/packages/guikingone-scheduler-bundle)[addwiki/wikibase-api

Wikibase API library

264.7k3](/packages/addwiki-wikibase-api)[bartlett/php-compatinfo-db

Reference Database of all functions, constants, classes, interfaces on PHP standard distribution and about 110 extensions

1183.0k1](/packages/bartlett-php-compatinfo-db)[wikibase/data-model-serialization

Serializers and deserializers for the Wikibase DataModel

10196.3k8](/packages/wikibase-data-model-serialization)[perplorm/perpl

Perpl is an improved and still maintained fork of Propel2, an open-source Object-Relational Mapping (ORM) for PHP.

203.7k](/packages/perplorm-perpl)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
