Extension:Semantic Compound Queries

Description
Semantic Compound Queries is an extension to MediaWiki, based on top of Semantic MediaWiki, that allows for the display of more than one SMW inline query in one results display set. It uses its own parser function, #compound_query, that takes inputs similar to that of #ask but can take in an unlimited number of queries, instead of just one.

Semantic Compound Queries requires the presence of Semantic MediaWiki 1.0 or greater.

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


 * semantic_compound_queries_0.2.1.tar.gz
 * semantic_compound_queries_0.2.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/SemanticCompoundQueries/. From a command line, you can call the following:

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

Installation
To install this extension, create a 'SemanticCompoundQueries' 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:

Author
Semantic Compound Queries was written by Yaron Koren, reachable at yaron57 -at- gmail.com.

Version
Semantic Compound Queries is currently at version 0.2.1.

The version history is:
 * 0.1 - November 19, 2008 - Initial version
 * 0.2 - November 25, 2008 - Two defined classes moved to their own files; fix for semicolons contained within query filters
 * 0.2.1 - December 1, 2008 - Fix for map icons with MW 1.12 or earlier

Usage
A normal inline query, using the #ask parser function, takes in arguments of three types: (1) a filter that determines the results, (2) the names of properties to be displayed, and (3) arguments that determine the format and other aspects of the display. Here is an example of a normal inline query:

In this query, there are three arguments, and they belong to argument types 1, 2 and 3, respectively.

For compound queries, the first two types of arguments are unique to each sub-query, and separated from each other by semicolons, instead of pipes; pipes are used to separate one sub-query from the rest. The third type of argument, setting the display of the results, is common across all sub-queries. Here is an example of a call to #compound_query, this one showing both clothing stores and fast-food restaurants:

To make things more interesting, we can place all these results on a map, using the Semantic Google Maps extension. Here is the same set of results, using SGM's 'googlemaps' format, and a different property displayed for both sets of points to set their geographical coordinates:

We can set a different icon to appear for each location type in the map, by using the "icon" parameter, which Semantic Google Maps understands (note that this feature only works, however, with MediaWiki 1.13 or higher). Assuming your wiki contains uploaded images by the name of "Shirt.png" and "Hamburger.png", you could call the following:

This query also sets the height and width of the map - additional arguments of the third type.


 * 1) compound_query avoids displaying the same page more than once, so if a page gets returned by more than sub-query, it's displayed only for the first one. In this way, a compound query can have specific sub-queries, and then a general catch-all sub-query at the end:

There's also special handling for the 'calendar' format - if you display a calendar, you can set a different color for each set of events displayed. Here is an example:

Bugs and feature requests
Send any bug reports, requests or code patches to Yaron Koren, at yaron57 -at- gmail.com.