User Tools

Site Tools


Loki - Logic in wiki

The main apparent limitation of existing semantic wikis is the lack of expressive knowledge representation mechanism. Building a knowledge base with a semantic wiki becomes complicated because of its collective nature, where number of users collaborate in the knowledge engineering process. A need for knowledge evaluation and analysis facilities become clear.

Loki Proposal

Logic-based Wiki, or Loki for short, uses the logic programming paradigm to represent knowledge in the wiki, including semantic annotations and rules. The main design principles are as follows:

  • provide an expressive underlying logical representation for semantic annotations and rules,
  • allow for strong reasoning support in the wiki,
  • preserve backward compatibility with existing wikis, namely SMW.

The design has been based on the use of the Prolog *) programming language.

*) Prolog is an expressive logic programming language. The Prolog system uses a knowledge base to answer queries. From a logical point of view, the knowledge base is composed of Horn clauses and a goal. In Prolog two basic forms of statements are possible: facts and rules. While the default inference strategy is backward-chaining it is trivial to built custom meta-interpreters implementing any inference strategy. Although Prolog has been traditionally related to Artificial Intelligence, it is a mature and universal programming language. Number of powerful implementations are currently available, e.g. SWI-Prolog - a mature implementation widely used in research and education as well as for commercial applications. SWI-Prolog provides a rich set of libraries, including the semweb library for dealing with standards from the W3C standard for the Semantic Web (RDF, RDFS and OWL).

SMW Support in Loki

There are three main methods of semantic annotations used in Semantic MediaWiki that are supported in Loki:

  • categories - a simple form of annotation that allows users to classify pages. To state that article (Wiki page) belongs to the Category book one has to write [[category:book]] within the article.
  • relations - there is a possibility to describe relationships between two Wiki pages by assigning annotations to existing links. For example there is a relation author between the “Call of Cthulhu” and H.P.Lovecraft. To express this one has edit the page the_call_of_cthulhu and add [[author::h_p_lovecraft]] within the page content.
  • attributes - allow to specify relationships of Wiki pages to things that are not Wiki pages. For example, one can state that a book has been published in year 2009 by writing [[date:=2009]] at the wiki page of this book.

Thanks to semantic annotations, users can search for articles using a simple query language that was developed based on the known syntax of the Wiki. For example to display all books written by a given author one can formulate the query:

{{#ask: [[category:book]] [[author::h_p_lovecraft]]}}
The query functionality can be used to embed dynamic content into pages, which is a major advantage over traditional wikis.

Loki allows to describe categories, relations and attributes the same way as in SMW. They are represented by appropriate Prolog terms. Technically, SMW markup is converted to Prolog code and then saved in Loki file related to Wiki page. Examples are as follows, with the SMW syntax gives first, and the corresponding Prolog representation below.

**Author**: [[author::h_p_lovecraft]]
**Date**:  [[date:=2009]]

Semantic Web standards support

RDF/S, OWL and SPARQL support

RDF annotations can be embedded directly in the XML serialization. They are parsed by the SWI-Prolog semweb/rdf_db library, and turned to the internal representation. The library represents RDF triples simply as:

rdf(?Subject, ?Predicate, ?Object).

RDFS is also supported by the semweb/rdfs library.

Within the wikitext a SPARQL query (SELECT, ASK or DESCRIBE) may be posed. The query scope is the whole wiki system. SPARQL queries are handled by the semweb/sparql_client. Analogously to the SMW-like queries, SPARQL ones are also translated to Prolog goals and then executed by the wiki engine.

RDF/XML export

Semantic information gathered on the Loki pages may be exported to the RDF/XML format. Metadate from “regular” pages are written in RDF, whereas the metadata of the special pages (categories, properties, attributes) are written in OWL.

On each wiki page there is a button “Export to RDF” which run an action generating an RDF file assosiated with this page. The exported file consists of 4 parts: a header with used namespaces, metadata of the exported page, additional information, and finally: ontological information about categories, relations and attributes. The first and the second part is always there, the third and the fourth are optional and depends on the configuration.

Categories are exported as owl:Class, relations between two pages as owl:ObjectProperty and attributes as owl:DatatypeProperty elements. Information about subcategories and subproperties are exported with use of rdfs:subClassOf and rdfs:subProperty respectively.

Prolog Knowledge Representation and Reasoning

Loki can directly interpret the SMW syntax. Moreover, it allows for embedding any Prolog code, providing more expressive and flexible knowledge. To do so, a special markup is used, as shown below:


This simple statement adds two facts to the knowledge base. The plugin invocation is performed using the predefined syntax. To specify the goal (query) for the interpreter the following syntax is used:

<pl goal="coutry(X),write(X),nl,fail"></pl>

It is possible to combine these two, as follows:

<pl goal="country(X),write(X),nl,fail">

It is possible to specify a given scope of the query (in terms of wiki namespaces):

<pl goal="country(X),write(X),nl,fail" 

Thanks to the Prolog engine available in the wiki, the knowledge representation is flexible and the inference options are very rich. Prolog uses backwards chaining with program clauses. However, it is very easy to implement meta-interpreters for forward chaining.

A simple clause finding recently created pages might be as follows:

recent_pages(Today,Page) :-
    I is Today - D,
    I < 7.

Compound queries can also be created easily and executed as Prolog predicates.

Rule-based Reasoning

An optional decision rule layer is also considered with the use of the HeaRT runtime for the XTT2 framework. XTT2 (eXtended Tabular Trees v2) knowledge representation incorporates attributive table format. Similar rules are grouped within separated tables, and the system is split into a network of such tables representing the inference flow. XTT2 rules can be serialized into a HMR format which is supported in Loki.

HeKatE RunTime (HeaRT) is a dedicated inference engine for the XTT2 rule bases. The engine is highly modularized. It supports four types of inference process, Data and Goal Driven, Fixed Order, and Token Driven. The engine is implemented in Prolog, using the SWI-Prolog stack.

Embedding HeaRT in Loki is currently in an experimental phase and is not provided with the current release.


The wikitext from the regular wiki contains basic semantic annotations as in SMW. Additionally it contains Prolog code and HMR rules. These are combined into a Loki knowledge base.

The knowledge base may be queried using both generic Prolog queries, as well as SPARQL. Reasoning is done either by a regular Prolog engine or by the dedicated HeaRT engine.


An implementation of the Loki architecture has been developed. The main goal of the system design is to deliver a generic and flexible solution.

There are tens of wiki engines available. Most of them are similar w.r.t to main concepts and features. However, there are number of differences when it comes to the wikitext syntax, implementation and runtime environment, as well as extra features. This is why, instead of building yet another wiki engine, or modify an existing one, the idea is to use a ready, flexible and extensible wiki engine, that could be optionally extended with knowledge representation and processing capabilities. Instead of modifying an existing wiki engine or implementing a new one, a development of an extension of the DokuWiki system was chosen.

DokuWiki is designed to be portable, easy to use and set up. Like number of other solutions DokuWiki is based on PHP. However, it does not require any relational database back-end. It allows for image embedding, and file upload and download. Pages can be arranged into namespaces which act as a tree-like hierarchy similar to directory structure. The templates mechanism provides an easy way to change the presentation layer of the wiki. Modularized architecture of DokuWiki allows the user to extend it with plugins which provide additional syntax and functionality. A large number of plugins for DokuWiki is available.

DokuWiki provides a flexible plugin system, providing several kinds of plugins. These include:

  • Syntax Plugins, extending the wikitext syntax,
  • Action Plugins, redefining selected core wiki operations, (e.g. saving wikipages), and
  • Renderer Plugins, allowing to create new export modes (possibly replacing the standard XHTML renderer)

The current version of Loki implements both the Syntax and Renderer functionality. Text-based wikipages are fed to a lexical analyzer (Lexer) which identifies the special wiki markup. The standard DokuWiki markup is extended by a special markup that contains Prolog clauses. The stream of tokens is then passed to the Helper that transforms it to special renderer instructions that are parsed by the Parser. The final stage is the Renderer, responsible for creating a client-visible output (e.g. XHTML).

The detailed functionality of the Loki Syntax Plugin includes parsing the Prolog code embedded in the wikitext, and generating the knowledge base composed of files containing the Prolog code, where each wikipage has a corresponding file in the knowledge base. The PlWiki Renderer plugin is responsible for executing the Prolog interpreter with a given goal, and rendering the results via the standard DokuWiki mechanism.

What's next?

If you are interested in Loki, you can download our plugin, install it and follow our tutorial to make a quickstart with Loki!

If you do not want to install it, you can see use cases in this demo wiki.

docs/loki-about.txt · Last modified: 2015/12/06 21:48 by kkutt