PHPackages                             ask/ask - 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. ask/ask

AbandonedArchivedLibrary

ask/ask
=======

Library containing a PHP implementation of the Ask query language

1.0.2(11y ago)139.6k2[2 issues](https://github.com/wmde/Ask/issues)4GPL-2.0+PHPPHP &gt;=5.3.0

Since Nov 17Pushed 5y ago22 watchersCompare

[ Source](https://github.com/wmde/Ask)[ Packagist](https://packagist.org/packages/ask/ask)[ Docs](https://github.com/wmde/Ask)[ RSS](/packages/ask-ask/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (4)Used By (4)

This library is no longer under development and is no longer maintained.

Ask
===

[](#ask)

Library containing a PHP implementation of the Ask query language.

The implementation consists out of domain objects that represent various parts of Ask queries.

[![Build Status](https://camo.githubusercontent.com/e358918bf45460fc991d19828ae1f08e079468fdd321d20c1b95ceb6ceb66f13/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f776d64652f41736b2e706e673f6272616e63683d6d6173746572)](http://travis-ci.org/wmde/Ask)[![Coverage Status](https://camo.githubusercontent.com/ed3f3501d8b176b34a9093374a5a337809e4f45e8b160ba6d896743e272d9698/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f776d64652f41736b2f62616467652e706e673f6272616e63683d6d6173746572)](https://coveralls.io/r/wmde/Ask?branch=master)[![Scrutinizer Quality Score](https://camo.githubusercontent.com/a7e19d8c5002e131981a2dc54c6051c20fcee357e1ec306bd0a1373f78214292/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f776d64652f41736b2f6261646765732f7175616c6974792d73636f72652e706e673f733d65613464363537663332323265613030333035643537626561303333396134383938383265653935)](https://scrutinizer-ci.com/g/wmde/Ask/)

On Packagist: [![Latest Stable Version](https://camo.githubusercontent.com/8daff720f14b9e2e5184edfb7d10bed80e92e00bc8184a43824298ecf5ff63ee/68747470733a2f2f706f7365722e707567782e6f72672f61736b2f61736b2f76657273696f6e2e706e67)](https://packagist.org/packages/ask/ask)[![Download count](https://camo.githubusercontent.com/2b108af1474cebc1fc62649286d6ac34429a3a207a1f626d8bcd944ec7798c79/68747470733a2f2f706f7365722e707567782e6f72672f61736b2f61736b2f642f746f74616c2e706e67)](https://packagist.org/packages/ask/ask)

Requirements
------------

[](#requirements)

- PHP 5.3 or later
- [DataValues](https://github.com/DataValues/DataValues) 0.1 or later

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

[](#installation)

You can use [Composer](http://getcomposer.org/) to download and install this package as well as its dependencies. Alternatively you can simply clone the git repository and take care of loading yourself.

### Composer

[](#composer)

To add this package as a local, per-project dependency to your project, simply add a dependency on `ask/ask` to your project's `composer.json` file. Here is a minimal example of a `composer.json` file that just defines a dependency on Ask 1.0:

```
{
    "require": {
        "ask/ask": "1.0.*"
    }
}

```

### Manual

[](#manual)

Get the Ask code, either via git, or some other means. Also get all dependencies. You can find a list of the dependencies in the "require" section of the composer.json file. Load all dependencies and the load the Ask library by including its entry point: Ask.php.

Structure
---------

[](#structure)

The Ask library defines the Ask query language. Its important components are:

- Ask\\Language - everything part of the ask language itself

    - Ask\\Language\\Description - descriptions (aka concepts)
    - Ask\\Language\\Option - QueryOptions object and its parts
    - Ask\\Language\\Selection - selection requests
    - Ask\\Language\\Query.php - the object defining what a query is

### Description

[](#description)

Each query has a single description which specifies which entities match. This is similar to the WHERE part of an SQL string. There different types of descriptions are listed below. Since several types of descriptions can be composed out of one or more sub descriptions, tree like structures can be created.

- Description - abstract base class

    - AnyValue - A description that matches any object
    - Conjunction - Description of a collection of many descriptions, all of which must be satisfied (AND)
    - Disjunction - Description of a collection of many descriptions, at least one of which must be satisfied (OR)
    - SomeProperty - Description of a set of instances that have an attribute with some value that fits another (sub)description
    - ValueDescription - Description of one data value, or of a range of data values

All descriptions reside in the Ask\\Language\\Description namespace.

### Option

[](#option)

The options a query consist out of are defined by the `QueryOptions` class. This class contains limit, offset and sorting options.

Sorting options are defined by the `SortOptions` class, which contains a list of `SortExpression` objects.

All options related classes reside in the Ask\\Language\\Option namespace.

### Selection

[](#selection)

Specifying what information a query should select from matching entities is done via the selection requests in the query object. Selection requests are thus akin to the SELECT part of an SQL string. They thus have no effect on which entities match the query and are returned. All types of selection request implement abstract base class SelectionRequest and can be found in the Ask\\Language\\Selection namespace.

Usage
-----

[](#usage)

#### A query for the first hundred entities that are compared

[](#a-query-for-the-first-hundred-entities-that-are-compared)

```
use Ask\Language\Query;
use Ask\Language\Description\AnyValue;
use Ask\Language\Option\QueryOptions;

$myAwesomeQuery = new Query(
    new AnyValue(),
    array(),
    new QueryOptions( 100, 0 )
);
```

#### A query with an offset of 50

[](#a-query-with-an-offset-of-50)

```
$myAwesomeQuery = new Query(
    new AnyValue(),
    array(),
    new QueryOptions( 100, 50 )
);
```

#### A query to get the ''cost'' of the first hundred entities that have a ''cost'' property

[](#a-query-to-get-the-cost-of-the-first-hundred-entities-that-have-a-cost-property)

This is assuming 'p42' is an identifier for a ''cost'' property.

```
$awesomePropertyId = new PropertyValue( 'p42' );

$myAwesomeQuery = new Query(
    new SomeProperty( $awesomePropertyId, new AnyValue() ),
    array(
        new PropertySelection( $awesomePropertyId )
    ),
    new QueryOptions( 100, 0 )
);
```

#### A query to get the first hundred entities that have 9000.1 as value for their ''cost'' property.

[](#a-query-to-get-the-first-hundred-entities-that-have-90001-as-value-for-their-cost-property)

This is assuming 'p42' is an identifier for a ''cost'' property.

```
$awesomePropertyId = new PropertyValue( 'p42' );
$someCost = new NumericValue( 9000.1 );

$myAwesomeQuery = new Query(
    new SomeProperty( $awesomePropertyId, new ValueDescription( $someCost ) ),
    array(),
    new QueryOptions( 100, 0 )
);
```

#### A query getting the hundred entities with highest ''cost'', highest ''cost'' first

[](#a-query-getting-the-hundred-entities-with-highest-cost-highest-cost-first)

This is assuming 'p42' is an identifier for a ''cost'' property.

```
$awesomePropertyId = new PropertyValue( 'p42' );

$myAwesomeQuery = new Query(
    new AnyValue(),
    array(),
    new QueryOptions(
        100,
        0,
        new SortOptions( array(
            new PropertyValueSortExpression( $awesomePropertyId, SortExpression::DESCENDING )
        ) )
    )
);
```

#### A query to get the hundred first entities that have a ''cost'' either equal to 42 or bigger than 9000

[](#a-query-to-get-the-hundred-first-entities-that-have-a-cost-either-equal-to-42-or-bigger-than-9000)

This is assuming 'p42' is an identifier for a ''cost'' property.

```
$awesomePropertyId = new PropertyValue( 'p42' );
$costOf42 = new NumericValue( 42 );
$costOf9000 = new NumericValue( 9000 );

$myAwesomeQuery = new Query(
    new SomeProperty(
        $awesomePropertyId,
        new Disjunction( array(
            new ValueDescription( $costOf42 ),
            new ValueDescription( $costOf9000, ValueDescription::COMP_GRTR ),
        ) )
    ),
    array(),
    new QueryOptions( 100, 0 )
);
```

Tests
-----

[](#tests)

This library comes with a set up PHPUnit tests that cover all non-trivial code. You can run these tests using the PHPUnit configuration file found in the root directory. The tests can also be run via TravisCI, as a TravisCI configuration file is also provided in the root directory.

Authors
-------

[](#authors)

Ask has been written by [Jeroen De Dauw](https://www.mediawiki.org/wiki/User:Jeroen_De_Dauw)as [Wikimedia Germany](https://wikimedia.de) employee for the [Wikidata project](https://wikidata.org/).

This library is a reimplementation of the Ask language domain objects in [Semantic MediaWiki](https://semantic-mediawiki.org/), which have been written by [Markus Krötzsch](http://korrekt.org/). This reimplementation is conceptually almost entirely based on the original code and contains small portions of it.

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

[](#release-notes)

### 1.0.3 (alpha)

[](#103-alpha)

- Installation together with DataValues 2.x is now supported.

### 1.0.2 (2014-10-16)

[](#102-2014-10-16)

- Installation together with DataValues 1.x is now supported.

### 1.0.1 (2014-01-21)

[](#101-2014-01-21)

- Removed custom autoloader. The Composer support for PSR-4 is now used.
- The PHPUnit bootstrap file now automatically runs "composer update".

### 1.0 (2013-11-17)

[](#10-2013-11-17)

Initial release with these features:

- PHP implementation of the Ask language core
- Implementation of descriptions, selection requests and sort options initially needed for Wikidata

Links
-----

[](#links)

- [Ask on Packagist](https://packagist.org/packages/ask/ask)
- [Ask on Ohloh](https://www.ohloh.net/p/ask)
- [Ask on coveralls.io](https://coveralls.io/r/wmde/Ask?branch=master)
- [Ask on ScrutinizerCI](https://scrutinizer-ci.com/g/wmde/Ask/)
- [Ask on TravisCI](https://travis-ci.org/wmde/Ask)
- [NodeJS implementation of Ask](https://github.com/JeroenDeDauw/AskJS)

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community29

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 82.1% 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 ~166 days

Total

3

Last Release

4233d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/451bd4039d530fed8f9c3da91bfa519233a397d2182cdfdcad700f6cfea19b7f?d=identicon)[Jeroen De Dauw](/maintainers/Jeroen%20De%20Dauw)

![](https://www.gravatar.com/avatar/5406ed1d40d50ffc61d67e9f5149914dbfe0b8a52bdf297299f5ccfab0a73d91?d=identicon)[thiemowmde](/maintainers/thiemowmde)

![](https://avatars.githubusercontent.com/u/22235?v=4)[Stefan Wasilewski](/maintainers/SMW)[@smw](https://github.com/smw)

---

Top Contributors

[![JeroenDeDauw](https://avatars.githubusercontent.com/u/146040?v=4)](https://github.com/JeroenDeDauw "JeroenDeDauw (202 commits)")[![translatewiki](https://avatars.githubusercontent.com/u/24829418?v=4)](https://github.com/translatewiki "translatewiki (21 commits)")[![addshore](https://avatars.githubusercontent.com/u/3308769?v=4)](https://github.com/addshore "addshore (9 commits)")[![tobijat](https://avatars.githubusercontent.com/u/2997252?v=4)](https://github.com/tobijat "tobijat (4 commits)")[![thiemowmde](https://avatars.githubusercontent.com/u/6576639?v=4)](https://github.com/thiemowmde "thiemowmde (3 commits)")[![siebrand](https://avatars.githubusercontent.com/u/210297?v=4)](https://github.com/siebrand "siebrand (2 commits)")[![DanweDE](https://avatars.githubusercontent.com/u/101926?v=4)](https://github.com/DanweDE "DanweDE (2 commits)")[![mariushoch](https://avatars.githubusercontent.com/u/2446964?v=4)](https://github.com/mariushoch "mariushoch (1 commits)")[![manicki](https://avatars.githubusercontent.com/u/3524114?v=4)](https://github.com/manicki "manicki (1 commits)")[![filbertkm](https://avatars.githubusercontent.com/u/135401?v=4)](https://github.com/filbertkm "filbertkm (1 commits)")

---

Tags

wikidataSMWSemantic MediaWikiask

### Embed Badge

![Health badge](/badges/ask-ask/health.svg)

```
[![Health](https://phpackages.com/badges/ask-ask/health.svg)](https://phpackages.com/packages/ask-ask)
```

###  Alternatives

[mediawiki/semantic-media-wiki

An extension to MediaWiki that lets you store and query structured data within wiki pages

586361.8k33](/packages/mediawiki-semantic-media-wiki)[param-processor/param-processor

Parameter processing library

22640.0k8](/packages/param-processor-param-processor)[mediawiki/semantic-result-formats

Provides additional result formats for queries using Semantic MediaWiki

51180.7k1](/packages/mediawiki-semantic-result-formats)[mediawiki/semantic-extra-special-properties

Provides extra special properties for Semantic MediaWiki

3074.6k1](/packages/mediawiki-semantic-extra-special-properties)[mediawiki/semantic-scribunto

A Semantic Mediawiki extension to natively support the Scribunto extension

2967.5k](/packages/mediawiki-semantic-scribunto)[data-values/common

Contains common implementations of the interfaces defined by DataValuesInterfaces

11934.5k13](/packages/data-values-common)

PHPackages © 2026

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