16 Oct 2009 @ 6:09 PM 

Today I’ve wrote a small change to Semantic MediaWiki that adds aliasing supports to it’s result formats. I’ve been working (mainly theorizing) on this for quite a while, and came up with some rather complex solutions, that where not feasible since they required PHP 5.3. The implementation I ended up with is ridiculously easy, and works with an $smwgResultAliases array. This array holds result formats as the keys, and the aliases as (array) value. A simple example of adding aliases using this array is:

$smwgResultAliases['googlemaps'] = array(‘googlemap’, ‘gmap’, ‘google’);

Here googlemap, gmap and google will do the same as googlemaps, which is the actual result format. To hold into account these aliases, I only needed to add some simple code to the getResultFormat function in SMWQueryProcessor. This is the code:

    static protected function getResultFormat($params) {
        global $smwgResultAliases;
       
        $format = 'auto';
        if (array_key_exists('format', $params)) {
            $format = strtolower(trim($params['format']));
            global $smwgResultFormats;

            if ( !array_key_exists($format, $smwgResultFormats) ) {
               
                foreach($smwgResultAliases as $mainFormat => $aliases) {
                    if (in_array($format, $aliases)) {
                        $format = $mainFormat;
                        $isAlias = true;
                        continue;
                    }
                }
               
                if (! $isAlias) $format = 'auto';  // If it is an unknown format, defaults to list/table again
            }
        }
        return $format;
    }

Semantic result formats displayed on a special:ask page
This implementation is fully working with Semantic Maps, and has fixed an issue this extension had with the display of it’s result formats on the special:ask page (see screenshot).

Anyway, my first direct contribution to SMW – yay :)

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)
Posted By: Jeroen De Dauw
Last Edit: 16 Oct 2009 @ 07:33 PM

EmailPermalink
Tags


 

Responses to this post » (None)

 
Post a Comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


 Last 50 Posts
 Back
Change Theme...
  • Users » 1329
  • Posts/Pages » 169
  • Comments » 119
Change Theme...
  • VoidVoid « Default
  • LifeLife
  • EarthEarth
  • WindWind
  • WaterWater
  • FireFire
  • LightLight

About me



    No Child Pages.