Extension:Semantic Internal Objects

Description
Semantic Internal Objects is an extension to MediaWiki, based on top of Semantic MediaWiki, that defines a parser function, '#set_internal', that is used to define "internal objects" within the Semantic MediaWiki system. There are complex types of information sometimes known as 'n-ary relations' that involve more than one data value associated together. A simple example is in a cooking recipe; a recipe may call for 1 cup of flour, and the values "1", "cup" and "flour" must be encoded together; by themselves, the values are not meaningful (the third value has meaning, though not all of the meaning it could have). Such information can be stored already in SMW using many-valued properties, though this approach has problems with flexibility and queriability. Instead, #set_internal can be used to define "internal objects" within a page, which can then be queried as normal SMW pages would; a row of a recipe would be a good example of data that could be defined using #set_internal.

This extension requires version 1.4.2 or greater of Semantic MediaWiki. (Note: if you're a Ubuntu 9.04 user, the default SMW version is 1.4.0 via aptitude/apt-get)

Semantic Internal Objects was funded by STAR Software (Shanghai) Co., Ltd., a member of the STAR Group.

Download
You can download the Semantic Internal Objects code in either one of these two compressed files:


 * semantic_internal_objects_0.1.tar.gz
 * semantic_internal_objects_0.1.zip

You can also download the code directly via SVN from the MediaWiki source code repository, at http://svn.wikimedia.org/svnroot/mediawiki/trunk/extensions/SemanticInternalObjects/. From a command line, you can call the following:

svn checkout http://svn.wikimedia.org/svnroot/mediawiki/trunk/extensions/SemanticInternalObjects/

Installation
To install this extension, create a 'SemanticInternalObjects' directory (either by extracting a compressed file or downloading via SVN), and place this directory within the main MediaWiki 'extensions' directory. Then, in the file 'LocalSettings.php', somewhere below the inclusion of Semantic MediaWiki (both the main 'include_once' line and the 'enableSemantics' line), add the following line:

For most versions of Semantic MediaWiki, you will also need to add one line to the SMW code, in the file /includes/storage/SMW_SQLStore2.php: at the very bottom of the function deleteSemanticData, add this line:

In version 1.4.3 of SMW, this is around line 1925; in version 1.4.2, it's around line 1810.

Of course, if this line is already there, you don't need to add it.

Author
Semantic Internal Objects was written by Yaron Koren, reachable at yaron57 -at- gmail.com.

Version
Semantic Internal Objects is currently at version 0.1.

Usage
The syntax of #set_internal is as follows:

It is very important to note that the first argument is a property pointing from the object, to the main page, and not the other way around! This is a bit counter-intuitive, but it makes meaningful querying possible.

A sample call to #set_internal would be:

This call would be placed in a page for a recipe, and it would define an object that had an automatically-generated name; if it were in a page called "Carrot cake", for instance, the object would be called "Carrot cake#1". If that page had subsequent calls to #set_internal, the objects that those calls generated would be called "Carrot cake#2", "Carrot cake#3", etc.

It should be noted that #set_internal does not display anything to the screen; display of the values has to be handled separately (this can be done easily if the function is called from a template).

One very important note relating to this is that a page, once displayed, must contain some actual text for the call to #set_internal to work. A page containing nothing but a call to #set_internal will not save any internal data, because the MediaWiki parser will be confused into thinking that the page is blank, and won't call the #set_internal function at all.

Querying internal objects
Internal objects, once stored, can be queried as if they were wiki pages. So the following query would show a table of all the recipes that contain more than 1/2 a cup of flour, and the number of cups they contain:

Note the "mainlabel=-" parameter in the query: that hides the names of the internal objects from users, since those names are confusing and basically meaningless.

Bugs and feature requests
You should use the Semantic MediaWiki mailing list, semediawiki-user, for any questions, suggestions or bug reports about Semantic Internal Objects. If possible, please add "[SIO]" at the beginning of the subject line, to clarify the subject matter.

You can also send specific code patches to Yaron Koren, at yaron57 -at- gmail.com.