Extension:Semantic Internal Objects

Description
Semantic Internal Objects is an extension to MediaWiki, based on Semantic MediaWiki. It defines two parser functions, '#set_internal' and '#set_internal_recurring_event', both of which are 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 the "Record" type, though this approach has problems with flexibility and queriability. Instead, #set_internal and #set_internal_recurring_event 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.

Semantic Internal Objects was initially 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.6.1.tar.gz
 * semantic_internal_objects_0.6.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 versions of Semantic MediaWiki before 1.5, you will also need to add one line to the SMW code: in the file '/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2.php' at the very bottom of the function updateData, add this line:

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

Enabling RDF export
If you're using version 1.5.1 or greater of Semantic MediaWiki, internal objects will be automatically included when an RDF export is done. If you want RDF export of SIO to work with version 1.5 of SMW, you will have to add a few lines to SMW. In the 'SemanticMediaWiki' directory, in the file /specials/Export/SMW_SpecialOWLExport.php, right after the line: (around line 678), add the following code:

Unfortunately, RDF export will not work with versions of SMW before 1.5.

Author
Semantic Internal Objects was written by Yaron Koren, reachable at yaron57 -at- gmail.com. Important contributions were made by Jamey Wood.

Version
Semantic Internal Objects is currently at version 0.6.2.

The version history is:
 * 0.1 - August 19, 2009 - Initial version
 * 0.2 - January 1, 2010 - Database calls turned into a single transaction; support for many languages added
 * 0.3 - February 10, 2010 - Support added for SMW 1.5 and properties of type 'Text'
 * 0.4 - March 2, 2010 - Better handling for automated SMW updating; handling of lists of values added, via '#list'; support for values containing '='
 * 0.4.1 - May 13, 2010 - Support added for SMW 1.5.1; possible fix for some data-refresh issues
 * 0.5 - June 4, 2010 - RDF export added; handling added for new coordinates representation in Semantic Maps 0.6
 * 0.6 - July 16, 2010 - Fix for "duplicate rows" bug; fix for when Semantic Maps is not installed; improvements to RDF export
 * 0.6.1 - September 26, 2010 - Fix for duplicate rows for *main page*, occurring with SMW 1.5.2 and higher; #set_internal_recurring_event added

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 page, and not the other way around! This is a bit counter-intuitive, but it makes meaningful querying possible. To follow the recipe example above, the value of object_to_page_property could be 'Is part of recipe', but not 'has ingredient'.

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).

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.

Lists of values
You can have #set_internal store a list of values for a property, instead of just one. To do that, you just need to append "#list" to the property name, and separate the values by commas. For instance, to record, in a page called "United States", the names of all presidents and their vice-presidents, you could have calls like:

Creating recurring events
The #set_recurring_event function in Semantic MediaWiki lets you set a series of date values for a single page, representing a recurring event. Unfortunately, because of the way SMW's querying works, this is sometimes not an ideal solution, because individual instances of the event can't be easily separated from one another. Instead, you can call #set_internal_recurring_event, which has a syntax that's a cross between #set_internal and #set_recurring_event, and defines a separate internal object for each instance of the event, with a different date for each. This allows for precise querying and display of only those event instances that fall within a certain date range.

The (abridged) syntax for #set_internal_recurring_event is:

Here is an example of such a call, on a page that defines a recurring event:

You could then display a table of all the events that happened in a certain week, along with their date, with the following call:


 * 1) set_internal_recurring_event requires at least SIO 0.6.1 and SMW 1.5.2 in order to work.

Known issues

 * For versions of SMW before 1.5.2, internal-object data will unfortunately not appear when a page with #set_internal is first created - the page must be saved at least twice for the data to show up.
 * Some users of Semantic Internal Objects previously encountered a problem where some internal objects were stored, and displayed, twice. This problem tended to occur after a template used by pages that store internal objects is resaved, or after a full SMW data refresh is called. This bug seems to have been fully fixed in version 0.6 - if you experience this problem using version 0.6 or later, though, please contact me (Yaron) at yaron57@gmail.com

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.