Last modified: 2013-07-18 10:21:48 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T48458, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 46458 - Ability to use count via the SMW Ask API
Ability to use count via the SMW Ask API
Status: RESOLVED FIXED
Product: MediaWiki extensions
Classification: Unclassified
Semantic MediaWiki (Other open bugs)
master
All All
: Unprioritized enhancement (vote)
: ---
Assigned To: Nobody - You can work on this!
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2013-03-22 18:03 UTC by Jamie Thingelstad
Modified: 2013-07-18 10:21 UTC (History)
5 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description Jamie Thingelstad 2013-03-22 18:03:16 UTC
I would love to add some deeper semantic statistics to WikiApiary beyond what is reported in the smwinfo API method. This enhancement request could be seen as a request to add more to smwinfo, but I think it would be better (and more generic) as an enhancement to the Ask API.

I would specifically like to execute this query via the API:

{{#ask:[[Query size::+]]|format=count}}

by doing:

http://wikiapiary.com/w/api.php?action=ask&query=%5B%5BQuery%20size%3A%3A%2B%5D%5D%7Cformat%3Dcount&format=json

Right now this will result in a PHP exception:

PHP message: PHP Catchable fatal error:  Argument 1 passed to ApiSMWQuery::addQueryResult() must be an instance of SMWQueryResult, string given, called in **/SemanticMediaWiki/includes/api/ApiAsk.php on line 48 and defined in **/SemanticMediaWiki/includes/api/ApiSMWQuery.php on line 82

The Ask API does allow parameters like sort and order to be passed, but it doesn't seem to handle format at all. For most cases format doesn't make sense (table, ul, array). However, aggregation formats methods like count, max, min, earliest, latest do make a lot of sense.

It would be really great to be able to do these queries via the API. I would then add this as extended semantic information to retrieve and graph in WikiAiary. :-)
Comment 1 Jamie Thingelstad 2013-03-22 18:07:46 UTC
As a thought, maybe this could justify a new API method (e.g., action=smwcalc) that allows you to only specify conditions and request average, count, max, median, min, product and sum (all the current calculations). I would put earliest and latest in there too.
Comment 2 MWJames 2013-03-22 18:39:52 UTC
(In reply to comment #0)
> I would love to add some deeper semantic statistics to WikiApiary beyond what
> is reported in the smwinfo API method. This enhancement request could be seen
> as a request to add more to smwinfo, but I think it would be better (and more
> generic) as an enhancement to the Ask API.
> 

Generally, results from the API are format independent.

> PHP message: PHP Catchable fatal error:  Argument 1 passed to
> ApiSMWQuery::addQueryResult() must be an instance of SMWQueryResult, string
> given, called in **/SemanticMediaWiki/includes/api/ApiAsk.php on line 48 and
> defined in **/SemanticMediaWiki/includes/api/ApiSMWQuery.php on line 82

This certainly needs fixing because of the type hinting, it comes back with a fatal because getResult() doesn't return an SMWQueryResult object but instead outputs a "naked" number.
Comment 3 MWJames 2013-03-22 18:47:10 UTC
(In reply to comment #1)
> As a thought, maybe this could justify a new API method (e.g.,
> action=smwcalc)

If some kind of statistics is needed it should go into ApiSMWInfo class (please, no additional action).

> that allows you to only specify conditions and request average, count, max,
> median, min, product and sum (all the current calculations). I would put
> earliest and latest in there too.

Since we expect the API to be format neutral, any specific formatting rules (e.g. max is an application based formatting acting on a result set) to a result set should be done in a post-process.

Count is somewhat different because it is handled differently in the SQLStore together with the actual database query.
Comment 4 MWJames 2013-04-02 19:40:03 UTC
[1] extends the smwinfo api to be able to access additional statistics such as querycount|querysize|conceptcount

[1] https://gerrit.wikimedia.org/r/#/c/57138
Comment 5 Jamie Thingelstad 2013-04-16 01:27:15 UTC
Thanks for adding these additional values to the SMWInfo API. I've started grabbing them from sites that are reporting it in WikiApiary.

http://wikiapiary.com/wiki/WikiApiary_talk:Operations/2013/April#Even_more_SMWInfo
Comment 6 Gerrit Notification Bot 2013-04-19 09:08:30 UTC
Related URL: https://gerrit.wikimedia.org/r/59990 (Gerrit Change Ifb34d9b17a0b34082ee62245ecf5f49dc0b2eec1)
Comment 7 MWJames 2013-04-19 09:19:40 UTC
The above change will add a "formatcount" parameter to ApiSMWInfo which will ouput
an array of used formats together with the count information.

## JSON example
{
    "info": {
        "formatcount": {
            "datatables": 44,
            "list": 27,
            "jqplotchart": 15,
            "eventcalendar": 15,
            "gallery": 15,
            "jqplotseries": 13,
            "count": 2,
            "sum": 2,
            "rdf": 1
        }
    }
}

It is not yet merged with the master ...
Comment 8 Jamie Thingelstad 2013-04-19 14:06:06 UTC
That is awesome! Will this be variable to include formats that are added via extensions like Semantic Results Formats? I'm guessing yes since some of the items you list above are not built-in to SMW IIRC.

With your previous change and this one you now have everything I was requesting via my special collection page for WikiApiary except queries by size. See

http://wikiapiary.com/wiki/WikiApiary:Collect_Semantic_MediaWiki_usage_setup

The new querysize output that is in the master branch seems to be the sum of all query sizes. It would be great if similar to what you added with formatcount there could be a sizecount listing as well showing querycount at each size.

This is so awesome to add MWJames. I can't wait to incorporate this into WikiApiary so we can start seeing how deep SMW is incorporated into various wikis!
Comment 9 Jamie Thingelstad 2013-04-19 14:09:46 UTC
Just a general comment, any other items you all want to add to SMWInfo I will definitely commit to adding to WikiApiary and graphing over time and showing comparisons across all sites. So, if there are other stats that you all as the core SMW team would like to answer "I wonder how many wikis have queries that take more than x seconds?" for example, add it and I'll start collecting it.

WikiApiary couldn't exist without SMW and I want to create more special capabilities for the SMW community in it. I'd really like to be able to tell someone if their site is using overly burdensome queries.
Comment 10 Gerrit Notification Bot 2013-04-19 15:10:42 UTC
https://gerrit.wikimedia.org/r/59990 (Gerrit Change Ifb34d9b17a0b34082ee62245ecf5f49dc0b2eec1) | change APPROVED and MERGED [by Jeroen De Dauw]

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links