Extension:Semantic Internal Objects

From MediaWiki.org

Jump to: navigation, search

         

Manual on MediaWiki Extensions
List of MediaWiki Extensions
Crystal Clear action run.png
Semantic Internal Objects

Release status: beta

Implementation  Parser function
Description Defines a parser function, #set_internal, that is used to define "internal objects" or "n-ary relations" within Semantic MediaWiki
Author(s)  Yaron Koren <yaron57@gmail.com>
Last Version  0.1 (August 2009)
MediaWiki  1.11.* or greater
License GPL
Download See here

check usage (experimental)

Contents

[edit] Description

Semantic Internal Objects is an extension to MediaWiki, based on of Semantic MediaWiki. It defines a parser function, '#set_internal', which 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.

[edit] Download

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

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/

[edit] 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:

include_once("$IP/extensions/SemanticInternalObjects/SemanticInternalObjects.php");

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:

		wfRunHooks('smwDeleteSemanticData', array($subject));

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

That is how the section should look after insertion of the code:

	array( 'smw_title' => , 'smw_namespace' => $id, 'smw_iw' => SMW_SQL2_SMWIW ),
			'SMW::deleteSubject::NaryIds'
		);
			wfRunHooks('smwDeleteSemanticData', array($subject));
	}

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

[edit] Author

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

[edit] Version

Semantic Internal Objects is currently at version 0.1.

[edit] Usage

The syntax of #set_internal is as follows:

{{#set_internal:object_to_page_property
|property1=value1
|property2=value2
...
}}

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:

{{#set_internal:Is part of recipe
|Has quantity=1
|Has unit=cup
|Has ingredient=flour
}}

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.

[edit] 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:

{{#ask:[[Is part of recipe::+]][[Has ingredient::flour]][[Has unit::cup]][[Has quantity::>.5]]
|mainlabel=-
|? Is part of recipe
|? Has quantity
}}

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.

[edit] RDF export

Unfortunately, RDF export is still not supported for Semantic Internal Objects - doing any sort of RDF export in Semantic MediaWiki will simply ignore the internal objects of the wiki. Getting this to work will require a small change to Semantic MediaWiki that we are hoping to get accomplished soon.

[edit] 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.