Semantic Templates¶
Source: https://www.semantic-mediawiki.org/wiki/Help:Semantic_templates
Warning
Definition: « Semantic Templates »
Semantic templates are a means to incorporate semantic annotations into MediaWiki pages in a standardized way through MediaWiki templates.
Semantic templates are a method of including the markup that Semantic MediaWiki introduces through MediaWiki templates.
This has several advantages:
- users can specify annotations without learning any new syntax
- annotations are used consistently, i.e. users do not have to look for the right properties or categories when editing a page
- infobox-style templates provide data structure, by defining which values belong in which pages
- infobox-style templates also often provide a nice display for the data
For these reasons, semantic templates are a very popular way of handling semantic annotations. In most wikis, semantic data is stored only via templates — in fact, we would estimate that 99% of all SMW data that currently exists is stored via a template.
Infobox-style Semantic Templates¶
Many MediaWiki sites, SMW-based and otherwise, make use of infobox-style templates to present standard information.
For example, Wikipedia articles on cities and villages use a standard template in which editors specify common items of information:
Usually the template (in this case, Infobox Settlement) displays this information in a nicely-formatted table. Such regular templatized items of information are ideal to be mapped into properties in Semantic MediaWiki, with each field being stored using a separate property.
The following example illustrates the use of semantic templates for annotating Infobox-like information to project pages:
Using semantic templates correctly¶
While the above pattern allows you to create all kinds of semantic templates of arbitrary complexity, there are some issues to consider.
-
Automatic annotation requires strict formats
You can annotate template fields automatically, but in this case the supplied values must adhere to the expected format. For example, it makes sense to store the population of a city with a property of datatypeNumber
. Still, the value that users enter might not be a number — it could be a piece of text like “Around 1 million”. Wikipedia notably has many such exceptions: in the main infobox template at France, for instance, the entry supplied for population is not a single number, or even a set of numbers! Instead, there are multiple numbers and textual explanations of their meaning. Such special cases should be kept in mind when designing semantic templates. -
Optional entries and conditionals
In the normal course of operating a wiki, most pages will probably not have their infoboxes completely filled, and you might not want to show empty rows in such cases. To remove rows with blank values, you can add conditionals into the template code, which include a row (and its annotation) only if a non-empty value was provided.This can be achieved with the help of the
#if
parser function, defined by extension ParserFunctions. Wikipedia contains many examples of parser functions in templates, as for instance in template “Taxobox”. Using parser functions typically results in difficult-to-read template code, but the simplification for users can be substantial.