Ask API

From semantic-mediawiki.org
Jump to: navigation, search

The Ask API allows you to do ask queries against SMW using the MediaWiki API and get results back serialized in one of the formats it supports. There are 2 API modules that differ in how you specify the query, but have identical output of the query results.

Ask

The "ask" module supports one parameter, query, which takes the same string you'd feed into an #ask tag, but urlencoded.

Example
api.php?action=ask&query=[[Modification date::%2B]]|%3FModification date|sort%3DModification date|order%3Ddesc&format=jsonfm
https://www.semantic-mediawiki.org/w/api.php

Askargs

The "askargs" module aims to take arguments in unserialized form, so with as little ask-specific syntax as possible. It supports 3 arguments:

  • "conditions": The query conditions, ie the requirements for a subject to be included
  • "printouts": The query printouts, ie the properties to show per subject
  • "parameters": The query parameters, ie all non-condition and non-printout arguments
Example
api.php?action=askargs&conditions=Modification%20date::%2B&printouts=Modification%20date&parameters=sort%3DModification%20date|order%3Ddesc&format=jsonfm
run example

Limit and offset

As in regular ask queries, both "limit" and "offset" are specified in the parameter list.

To get the first 10 results: &parameters=limit%3D10

The API result contains a "query-continue-offset" key, which can be used to fetch additional results: &parameters=offset%3D10|limit%3D10

If there is no "query-continue-offset" key in the result, the end of the result set was reached.

BrowseBySubject

The "browsebysubject" module allows to browse a subject, i.e. a page or subobject.

  • "subject": The title of the subject to be queried
  • "subobject": The title of the subobject with the named identifier to be queried (available since SMW 2.1)
Example (subject)
api.php?action=browsebysubject&subject=Main_Page
run example
Example (subject and subobject with named identifier)
api.php?action=browsebysubject&subject=Help:SMW_-_Number_of_downloads&subobject=SFS-2012-10
run example

NoteNote:  Browsing of a subobject subject with an anonymous identifier is limited to its "parent" subject, meaning that a request for a "Foo#_ed5a9979db6609b32733eda3fb747d21" subject will produce information for "Foo" as a whole including its subobjects because MW's WebRequest (responsible for handling request data sent by a browser) will eliminate any fragments (indicated by "#") to an API consumer.

SMWInfo

The "smwinfo" module enables to access statistical data information about the installed SMW basis.

Example
api.php?action=smwinfo&format=json&info=proppagecount|propcount|errorcount|querycount|usedpropcount|declaredpropcount|conceptcount|querysize|subobjectcount|formatcount
run example

The parameter "formatcount" will output an array of used formats together with its count information available.

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

Semantic MediaWiki 2.2.0 introduced the "errorcount" parameter to this module allowing to retrieve the number of improperly added values.[1]

NoteNote:  If used in conjunction with the External Data extension do not forget to replace all pipe characters | in API URL with {{!}} templates (≤ MW 1.23) or magic word (≥ MW 1.24) inside the {{#get_web_data:...}} parser function.

Serialization

External links

See also

Github readme

Octocat.pngdocs/technical/api.md

This file contains details about Semantic MediaWiki's API for external use with a description of available interfaces. For more details on MediaWiki's WbeAPI, it is recommended to read this [website][guideline].

api.php?action=ask

The Ask API allows you to do ask queries against SMW using the MediaWiki API and get results back serialized in one of the formats it supports.

The ask module supports one parameter, query, which takes the same string you'd feed into an #ask tag, but urlencoded.

api.php?action=ask&query=[[Modification date::%2B]]|%3FModification date|sort%3DModification date|order%3Ddesc&format=jsonfm

api.php?action=askargs

The Askargs API module aims to take arguments in un-serialized form, so with as little ask-specific syntax as possible. It supports 3 arguments:

  • "conditions": The query conditions, ie the requirements for a subject to be included
  • "printouts": The query printeouts, ie the properties to show per subject
  • "parameters": The query parameters, ie all non-condition and non-printeout arguments

api.php?action=askargs&conditions=Modification date::%2B&printouts=Modification date&parameters=|sort%3DModification date|order%3Ddesc&format=jsonfm

Output serialization

php { "query-continue-offset": 50, "query": { "printrequests": [ { "label": "", "typeid": "_wpg", "mode": 2, "format": false }, { "label": "Modification date", "typeid": "_dat", "mode": 1, "format": "" } ], "results": { "Main Page": { "printouts": { "Modification date": [ "1381456128" ] }, "fulltext": "Main Page", "fullurl": "http:\/\/localhost:8080\/mw\/index.php\/Main_Page", "namespace": 0, "exists": true }, ... }, "meta": { "hash": "a9abdb34024fa8735f6b044305a48619", "count": 50, "offset": 0 } } }

api.php?action=smwinfo

An interface to access statistical information about the properties, values etc..

api.php?action=smwinfo&format=json&info=proppagecount|propcount

The following parameters are available and can be concatenate using the "|" character.

  • proppagecount
  • propcount
  • querycount
  • usedpropcount
  • declaredpropcount
  • conceptcount
  • querysize
  • subobjectcount
  • formatcount
  • errorcount

Output serialization

php { "info": { "proppagecount": 40, "formatcount": { "table": 14, "list": 3, "broadtable": 1 } } } The parameter "formatcount" will output an array of used formats together with its count information.

api.php?action=browsebysubject

An interface to browse facts (the equivalent of Special:Browse) of a subject (wikipage) including special properties and subobjects.

api.php?action=browsebysubject&subject=Main%20Page api.php?action=browsebysubject&subject=Main%20Page&subobject=_QUERYa0856d9fbd9e495af0963ecc75fcef14

Output serialization

php { "query": { "subject": "Main_Page#0#", "data": [ { "property": "Foo", "dataitem": [ { "type": 2, "item": "Bar" } ] } ... ], "sobj": [ { "subject": "Main_Page#0##_QUERYa0856d9fbd9e495af0963ecc75fcef14", "data": [ { "property": "_ASKDE", "dataitem": [ { "type": 1, "item": "1" } ] }, ... ] ... } ], "serializer": "SMW\Serializers\SemanticDataSerializer", "version": 0.1 } }

api.php?action=browsebyproperty

An interface to browse properties (the equivalent of Special:Properties).

api.php?action=browsebyproperty api.php?action=browsebyproperty&limit=100&format=json&property=name

Output serialization

php { "xmlns:Foaf": "http://xmlns.com/foaf/0.1/", "query": { "Foaf:name": { "label": "Foaf:name", "isUserDefined": true, "usageCount": 2 }, "Has_common_name": { "label": "Has common name", "isUserDefined": true, "usageCount": 1 } }, "version": 0.1, "meta": { "limit": 100, "count": 2, "isCached": true } }


References

  1. See issue 893 for further information on this.


This documentation page applies to all SMW versions from 1.7.0 to the most current version.
      Other languages: de

Ask API en 1.7.0