Querying the CSDMS model repository: Difference between revisions
(First paragraph; remembering wiki markup) |
(Add query syntax section) |
||
Line 9: | Line 9: | ||
to query metadata from the CSDMS model metadata repository. | to query metadata from the CSDMS model metadata repository. | ||
The base URL for any call to the SMW API on the CSDMS | The base URL for any call to the SMW API on the CSDMS website is | ||
http://csdms.colorado.edu/mediawiki/api.php. | http://csdms.colorado.edu/mediawiki/api.php. | ||
==Query syntax== | |||
The <code>ask</code> action supports one parameter, <code>query</code>, | |||
which takes an [https://en.wikipedia.org/wiki/Percent-encoding urlencoded] string. | |||
The query is written in the SMW query language. | |||
A query consists of a series of ''conditions'', | |||
which describe the search. | |||
Conditions are built from ''properties'' and ''values''. | |||
For example, the condition | |||
<nowiki>[[Programming language::C]]</nowiki> | |||
would query for all models with the <code>Programming language</code> property | |||
that have a value of <code>C</code>. | |||
Note that the colons <code>::</code> in the condition | |||
are literal in the query language, | |||
and cannot be urlencoded. | |||
Spaces, however, should be encoded with <code>%20</code> or <code>+</code>, | |||
while brackets <code>[]</code> may optionally be encoded. | |||
Try this condition in a query: | |||
[http://csdms.colorado.edu/mediawiki/api.php?action=ask&query=%5B%5BProgramming+language::C%5D%5D&format=json <nowiki>http://csdms.colorado.edu/mediawiki/api.php?action=ask&query=[[Programming+language::C]]&format=json</nowiki>] | |||
The results of a query are returned as JSON | |||
with a specified | |||
[https://www.semantic-mediawiki.org/wiki/Serialization_%28JSON%29 format]. | |||
A query result can also be viewed in pretty print form | |||
by changing the value of the <code>format</code> parameter to <code>jsonfm</code>. |
Revision as of 12:06, 8 March 2016
Querying the CSDMS Model Repository
Semantic MediaWiki (SMW)
is the knowledge management system used on the CSDMS website.
SMW has an API with several actions,
allowing users to add, edit, and query information.
Here, we'll focus on the ask
action,
and the Ask API,
to query metadata from the CSDMS model metadata repository.
The base URL for any call to the SMW API on the CSDMS website is http://csdms.colorado.edu/mediawiki/api.php.
Query syntax
The ask
action supports one parameter, query
,
which takes an urlencoded string.
The query is written in the SMW query language.
A query consists of a series of conditions,
which describe the search.
Conditions are built from properties and values.
For example, the condition
[[Programming language::C]]
would query for all models with the Programming language
property
that have a value of C
.
Note that the colons ::
in the condition
are literal in the query language,
and cannot be urlencoded.
Spaces, however, should be encoded with %20
or +
,
while brackets []
may optionally be encoded.
Try this condition in a query:
http://csdms.colorado.edu/mediawiki/api.php?action=ask&query=[[Programming+language::C]]&format=json
The results of a query are returned as JSON
with a specified
format.
A query result can also be viewed in pretty print form
by changing the value of the format
parameter to jsonfm
.