Help:Datatype "Boolean"

From semantic-mediawiki.org
Jump to: navigation, search
Boolean
Holds boolean (true/false) values
Further Information
Provided by: Semantic MediaWiki
Added in version: 1.0
Removed in version: still in use
Datatype ID:
_boo
In this wiki: Boolean
Table of Contents

The datatype Boolean is for attributes that can only have two possible values, called truth value. You can enter "true" or "false", also 1/0, yes/no, t/f, and y/n. Other languages may provide language-specific options.

To allow two arbitrary strings, or more than two possible values (such as no - maybe - probably - yes) use Help:Datatype "String" with Property:Allows value to restrict the possible values. In many circumstances it may also be more appropriate to use a category instead of a Boolean.

Displaying Boolean values in inline queries

By default, Boolean values will display true and false in queries. This can be changed by specifying a format string to control what is displayed for the true and false values of a property. Consider, e.g., a Boolean property successful in a wiki about projects, that describes whether or not a certain project was a success. Displaying all projects with their success status could then be achieved as follows:

{{#ask:
 [[Category:Project]]
 |?successful#success,failure
}}

where success and failure are displayed in a result column labeled "successful". Note that this column may have empty fields, for projects where the success or failure was not determined yet. This is a difference to categories, which can either be true or unset, but not explicitly set to false. So if we would have used a category Category:Successful project then we could have created only the following query:

{{#ask:
 [[Category:Project]]
 |?Category:Successful project#success,failure
}}

In this case, an extra column labeled "Successful" appears again, but now showing success for all results that belong to the category Successful, and showing failure for all other cases (including those where the status may be unknown).

In both of the above cases, it is possible to use "=" to change the label of the result column, as usual, e.g.:

{{#ask:
 [[Category:Project]]
 |?successful#success,failure=Success status
}}

A special formatting symbol for Booleans is the lower-case letter x. When given as a text for displaying results, SMW will use an X that resembles a cross for true.

{{#ask:
 [[Category:Project]]
 |?successful#x
}}

This would show a cross for all cases where the property is set to true, and nothing if it is false or unset. Finally, the labels given for true and false (or category membership and non-membership) can also be special symbols or images, and may also be empty to show nothing. However, at least the comma should always be set. So to display a tick (actually a square root symbol) for true one could use:

{{#ask:
 [[Category:Project]]
 |?successful#√,
}}

Booleans in other languages

As mentioned above you may enter "true" or "false", also 1/0, yes/no, t/f, and y/n as possible values for booleans. To find out about (and possibly change) the booleans used in your language, see the messages MediaWiki:Smw_true_words and MediaWiki:Smw_false_words.

See the effect for this wiki at: Help:Examples for Boolean Options

Localization based on user language is provided with the #LOCL output formatting option. Furthermore, if a page has set a specific page content language 1 then the DV tries to match local values against that language 2 instead of the global content language.

Examples


Related query syntax elements

General

Help pageSyntax elementDescription
#ask: annotation query marker
@annotation
Marks an inline query as part of an annotation3
#ask: control query marker
@control=slider
Allows to dynamically alter a result display without the need to reload a page4
#ask: deferred query marker
@deferred
Marks an inline query as deferred from regular parsing4
#ask: hierarchy depth restriction
+depth=
Restricts the hierarchy depth of a query5
#ask: printout column alignment
+align=
Defines an alignment for the content of a printout column
#ask: printout column width
+width=
Defines a width for a printout column6
#ask: printout sorting order
+order=
Defines the sorting order for printout statements (dot chain syntax)7

References

  1. ^  Semantic MediaWiki: GitHub issue #1580 example - Localization of boolean values
  2. ^  Semantic MediaWiki: GitHub pull request gh:smw:1580
  3. ^  Semantic MediaWiki: GitHub pull request gh:smw:2572
  4. a b  Semantic MediaWiki: GitHub pull request gh:smw:2398 (Add support for @deferred mode)
  5. ^  Semantic MediaWiki: GitHub issue gh:smw:2662
  6. ^  Semantic MediaWiki: GitHub pull request gh:smw:2677
  7. ^  Semantic MediaWiki: GitHub pull request gh:smw:2073