Querying the CSDMS model repository: Difference between revisions
(Add query syntax section) |
(Add properties and categories sections) |
||
Line 1: | Line 1: | ||
=Querying the CSDMS Model Repository= | = Querying the CSDMS Model Repository = | ||
[https://www.semantic-mediawiki.org/wiki/Semantic_MediaWiki Semantic MediaWiki] (SMW) | [https://www.semantic-mediawiki.org/wiki/Semantic_MediaWiki Semantic MediaWiki] (SMW) | ||
Line 12: | Line 12: | ||
http://csdms.colorado.edu/mediawiki/api.php. | http://csdms.colorado.edu/mediawiki/api.php. | ||
==Query syntax== | == Query syntax == | ||
The <code>ask</code> action supports one parameter, <code>query</code>, | The <code>ask</code> action supports one parameter, <code>query</code>, | ||
Line 41: | Line 41: | ||
A query result can also be viewed in pretty print form | 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>. | by changing the value of the <code>format</code> parameter to <code>jsonfm</code>. | ||
== Properties == | |||
[https://www.semantic-mediawiki.org/wiki/Help:Properties_and_types Properties] | |||
are the basic data type of SMW. | |||
They consist of a name and a value, | |||
both of which are case-sensitive. | |||
A defined set of properties are added to each model | |||
by the CSDMS WikiSysop. | |||
For example, | |||
<code>Programming language</code> is a property of models | |||
in the CSDMS model metadata repository. | |||
'''Note:''' | |||
I desire a query that returns all the properties of a model, | |||
but I haven't figured out how to make it. | |||
It's on my list of unanswered questions below. | |||
In lieu of a programmatic query, | |||
I've been looking at the model's wiki source; | |||
for example, the | |||
[http://csdms.colorado.edu/mediawiki/index.php?title=Model:HydroTrend&action=edit Wikitext for HydroTrend]. | |||
== Categories == | |||
[https://www.semantic-mediawiki.org/wiki/Help:Editing Categories] | |||
are tags added to a page | |||
by the CSDMS WikiSysop | |||
to aid in classification. | |||
Like properties, | |||
categories can be queried. | |||
For example, | |||
the condition | |||
<nowiki>[[Category:Terrestrial]]</nowiki> | |||
will list all terrestrial models the CSDMS model metadata repository. | |||
Unlike properties, | |||
only one colon <code>:</code> separates the category name and value. | |||
<code>Model</code> is itself a category in the CSDMS wiki. | |||
Search for a particular model by name: | |||
<nowiki>[[Model:HydroTrend]]</nowiki> | |||
The category value is case-sensitive; | |||
e.g., <code>hydrotrend</code> wouldn't match a model. | |||
Here's this condition in a query: | |||
[http://csdms.colorado.edu/mediawiki/api.php?action=ask&query=%5B%5BModel:HydroTrend%5D%5D&format=json <nowiki>http://csdms.colorado.edu/mediawiki/api.php?action=ask&query=[[Model:HydroTrend]]&format=json</nowiki>] |
Revision as of 20:34, 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
.
Properties
Properties are the basic data type of SMW. They consist of a name and a value, both of which are case-sensitive.
A defined set of properties are added to each model
by the CSDMS WikiSysop.
For example,
Programming language
is a property of models
in the CSDMS model metadata repository.
Note: I desire a query that returns all the properties of a model, but I haven't figured out how to make it. It's on my list of unanswered questions below. In lieu of a programmatic query, I've been looking at the model's wiki source; for example, the Wikitext for HydroTrend.
Categories
Categories are tags added to a page by the CSDMS WikiSysop to aid in classification. Like properties, categories can be queried. For example, the condition
[[Category:Terrestrial]]
will list all terrestrial models the CSDMS model metadata repository.
Unlike properties,
only one colon :
separates the category name and value.
Model
is itself a category in the CSDMS wiki.
Search for a particular model by name:
[[Model:HydroTrend]]
The category value is case-sensitive;
e.g., hydrotrend
wouldn't match a model.
Here's this condition in a query:
http://csdms.colorado.edu/mediawiki/api.php?action=ask&query=[[Model:HydroTrend]]&format=json