From Biowikifarm Metawiki
Jump to: navigation, search
Help sections
Contents · Semantic MediaWiki · Semantic Forms
Add Ontology · Semantic links and import/export features · Import external vocabulary
Other SemanticMW extensions · Other extensions

This section gives some guidance on, and provides some examples for the use the Semantic MediaWiki extension. For more detailed descriptions see the SemanticMW website.


The Semantic MediaWiki (SemanticMW) extension is useful if you want to summarize and compare information which is located in different wiki pages. The page Countries gives an example of how information on different countries can be combined in a table. This has 2 advantages:

  • In the table you can sort the countries, e.g. by their population size or by the height of their highest mountain.
  • If the information in the source page changes (e.g. the figure for the total population in a given country is adjusted) then the table updates itself automatically.

The Semantic MediaWiki extension is well advanced and provides many different ways of formatting and retrieving the data. We can only give a few examples here.

Defining categories

Categories have been introduced by MediaWiki and represent the former way meant to structure wiki articles. One article might belong to many categories. The present article belongs to:

[[Category: MediaWiki Extensions]]

Defining subcategories

MediaWiki supports a hierarchy of categories that helps to simplify the category statements needed on each page. To indicate that one category is more specific than another, MediaWiki supports a category hierarchy where users can state that one category is a subcategory of another, simply by putting a category on the subcategory's page, e.g. the page Category:Metadata Sources could contain the text:

Category for media using [[Template:Metadata|template metadata]].

So named «semantic drift» occurs if the exact intention of some category is not really specified, e.g. because it lacks a detailed description on its page. Different users then may have slightly different readings of the categories meaning, and this may influence how they use sub-category statements. It is therefore important to always clearly describe on a category page what should go into a category and what shouldn't, and also to point to alternative catgegories that may be suitable.

Defining properties and data types

SemanticMW works with "properties". These define the type of information you want to collect and compare. For example, by creating the page Property:Population SemanticMW knows that "population" is a clearly defined information unit for a country (which could have been also named "number of inhabitants" or something else). In this case it is also important to assign the Type:Number to the "population" property. Otherwise data entered for this property would be regarded as plain text and we might get a sorting order like 179, 2499, 280, 4808, and 560.

Defining sub-properties

Sub-property feature allows inference. For defining sub-properties, its' necessary only to add in the property page the specification for sub-property, i.e., for the Property:Any Keyword:

This is a property of type [[Has type::String]].
[[subproperty of::Property:Text Search]]

These can be organized hierarchically, so one property could be defined as sub-property of a property and the latter could be defined as a sub-property of another property and so on. For example: The properties Property:General Keyword, Property:Scientific Name and others are defined as [[subproperty of::Property:Any Keyword]]. Like already seen before, the last one is [[subproperty of::Property:Text Search]]. Once this has been stated, a query (see Inline queries usage below) for [[Any Keyword::Galium odoratum]] will also return the [[Scientific Name::Galium odoratum]] even if no «Any Keyword» property is given on that page. The same is true for a query [[Text Search::Galium odoratum]]. Similar considerations as in the case of categories apply, and detailed descriptions on property pages are a good method for avoiding semantic drift.

Entering data

Data are assigned to each property by using the format:
 [[Capital::Vienna| ]]
 [[Area::83.9| ]]
 [[Population::8.3| ]]

Note the 2 colons. In the above format the data assignment in the page "Austria" does not produce any text in the page. However, you can also combine the data assignment with the text displayed by using the format [[Capital::Vienna]]

Calling up the data

In Semantic MediaWiki, retrieving the data is possible in two formats and using two different parser functions, as follows:

    1. inline queries which can be used in any wiki page, regardless of categories or namespaces. For expressing inline queries, #ask parser function is used. Into an article page, any number of inline queries might exists.
    2. concepts which represent a so called "dynamic categories" through use of #concept parser function usage. A concept is a page in the Concept: namespace that is always described by a semantic query.

Inline queries usage

For retrieving or querying the data like in the page Countries use the format:
 {{#ask: [[Category:Countries| country]] 
 | ?Capital# = capital
 | ?Area# = land area (1000 km²)
 | ?Population# = population (millions)
 | ?Highest mountain# = highest mountain
 | ?Highest mountain height# = height (m above SL)

Note that:

  • In the 1st line the statement "| country" makes a header for the first column.
  • On the 4th line the statement "| ?Population# = population (millions)" does 3 things:
    1. it retrieves all data assigned to the property "population" in a separate column,
    2. the "# " states that the values in the column are not page links (otherwise the system would display the values in red, as non-existing pages), and
    3. the "= population (millions)" labels the header for this column.
  • There are many different ways of formatting such a table, for example you can display numbers in many different formats, but additional extensions might be needed for some. For more details on inline queries descriptions see SemanticMW Help:Inline_queries.

Concept usage

These pages can be viewed as «dynamic categories», i.e. as collections of pages that are not created manually, but that are computed by SMW from the description given by a query. A concept is a page in the Concept: namespace that is always described by a semantic query, as result of parser function #concept. It is possible to have other content on the concept page as well. Any normal wiki text can go before and after the use of #concept but it will not have any effect on the definition of the concept. The #concept parser function can only be used on pages in the Concept: namespace, and it can only be used once on each such page.

For example, the page Concept:TestConcept has been created as:

 [[Category:Metadata Sources]] [[Type:: Collection || StillImage || Sound || TaxonPage || IdentificationTool || Map]]
 | This is a first test for Concepts.

Concept pages as such can be browsed to view the contents of some concept, similar to category pages. But they can also be used in other semantic queries just like categories. For example, the following query would show all pages in the above concept:

 [[Concept:TestConcept]] [[Type::StillImage]]

Using inverse properties for retrieving data

It is now possible to invert the direction of a page type property in queries and browsing interfaces. Simply write "-" in front of property names anywhere in SMW to refer to the inverse direction of a property, that is to the property that relates the same pages but with annotated page and annotation value exchanged. SMW does not support naming of inverses, but allows them to be used for retrieving data.

The following query return the name of the pages as values of property NamePage, not equals with the current page
 {{#ask: [[NamePage::!{{PAGENAME}}| Pages of interest]] | ?NamePage =  }} 

The result shows all the pages as values of property NamePage.

Simply inverse the property -NamePage in the above query, as in:

{{#ask: [[-NamePage::!{{PAGENAME}}| Pages of interest]] | ?NamePage =  }}

The result shows all the pages refered by the values of property NamePage.


For enabling the SemanticMW on another wiki of the biowikifarm follow the guidelines in the section for extensions: Semantic Mediawiki.

Comparing used vocabularies

From Semantic Web Vocabulary on
there are a number of tools and directions on the Semantic Web. And sometimes they seem to be conceptually equivalent modulo some details. But their vocabulary differs quite a lot. In this table some terms from different communities and / or tools are compared, so that a simple mapping and introduction can be achieved.

RDF OWL DL DL Semantic MediaWiki Freebase LO
model ontology TBox and ABox - domain faction
class class class, concept category type type
resource individual individual, instance article, page topic noun
property object property role relation property role
property datatype property concrete role attribute property verb