Help:Displaying information 1.4.3 - 1.5.0

From semantic-mediawiki.org


This page contains outdated information and is thus OBSOLETE!
This documentation page applies to all SMW versions from 1.4.3 to 1.5.0.

Displaying information en 1.4.3 1.5.0


SMW user manual
Introduction
Editing
Properties and types
Special properties
Inverse properties
Custom units

Semantic templates

Service links

Browsing interfaces
Special page "Ask"
Special:Browse
Semantic search
Selecting pages
Strict comparators
Displaying information
Result formats
Inline queries
Querying for queries
Concepts
Inferencing
Using the API
Semantic Web
RDF export

Importing vocabulary

SMW admin manual
Table of Contents

Queries in Semantic MediaWiki return a list of pages, and the default result of a query therefore simply displays the selected pages' titles. Additional information such as a page's property values or categories, can be included into a query result by using additional printout statements that are introduced here. In Special:Ask, printout statements can simply be entered into the input box on the right, with one statement per line.

There are different kinds of printout statments, but all of them can be recognised by the question mark ? that they start with. The important difference between printout statements and query descriptions is that the former do not restrict the result set in any way: even if some printout has no values for a given page, an empty field will be printed, but the page is still part of the result.


Printing property values[edit]

The most common form of printout statements are property printouts, that make SMW display all values assigned to a certain property. These are written simply as a question mark followed by the property name, e.g.

?population

prints the values for «population» of all query results. On Special:Ask, the result of each printout is shown in a table column that is labelled by the name of the property. It is possible to change that label for a printout, and this will be very useful when using queries on wiki pages (it is not really relevant on Special:Ask of course). The equality symbol is used to change the label:

?population = Number of inhabitants

The above still prints population, but with the modified label in the table header. As mentioned above, property printouts may have an empty result for some pages, e.g. if something does not have any population. Property conditions with wildcards (see above) can be used to ensure that all elements in a query result have some value for the printed property, if this is desired.

Printing categories[edit]

There are two ways to print category information: either SMW prints all categories assigned to some page, or SMW checks for one particular category. The first case is achieved by the printout

?Category

where «Category» is the name of the Category namespace in the local language. This printout will show all catgories that are directly used on a result page. The other option is to ask for one particular category, such as

?Category:Actor

The result then will contain a column «Actor» that contains X for all pages that directly belong to that category, and is empty otherwise. Again, one can change the label using equality:

?Category:Actor = A

will merely display an «A» as the header of the result column which might be more sensible given that the entries in that column are very short. It is also possible to change the way in which this kind of category queries are formatted, as described below.

The main result column[edit]

All queries by default display the main list of result pages in the first column. In some cases, it can be useful to move that to another position. This is not relevant for Special:Ask, but can be quite useful in inline queries. A special printout statment is available for this purpose:

?

This single question mark addresses the «unlabelled result column» that shows the main result list. As before, different labels can be assigned with the equality symbol, e.g.

? = Results

If you like to omit the main result column, you may use the parameter mainlabel=- (see also Help:Inline_queries#Changing_the_first_result_column).

Display format[edit]

Many printout statements can be further customised by giving a printout format which can be given after a property name, separated by the symbol #. The available formats depend on the type of the printout and involved property.

Plain (unformatted) printouts[edit]

A general format that is supported by most types of printouts is the plain format (or empty format), available since SMW 1.4.3. Printouts with this format will avoid all forms of beautification or linking in their presentation, and return a plain value instead. This is particularly useful when results are further processed in templates or parser functions. To select the plain output format, a hyphen ("-") or simply nothing is used as a printout string, as in the following examples:

?population# -
?capital #

Both printouts select the plain format. Spaces do not matter and can be inserted to increase readability. For numerical properties like the population number, the plain format is a simple number string without commas to separate digits. For properties of type page, the plain output is simply the name of the page without any link.

Formats for specific printout types[edit]

For properties that support units, queries can thus determine which unit should be used for the output. To print the height in cm, e.g., one would use the following:

?height#cm

this assumes that the property height is aware of the unit «cm». For properties of type date, the output format "ISO" is available to obtain results in a technical format that conforms to the ISO 8601 standard. Other datatypes may have different printout formats. See the types documentation for details.

For printouts of the form ?Category:Actor, the display format can be used to modify what SMW will display for cases where a page is (or is not) in the category. The following is an example:

?Category:Actor#an actor, not an actor

This will show the text «an actor» for all pages that are actors, and the text «not an actor» otherwise. This can, for example, also be used in combination with small images to display icons for certain categories.