An introduction to SMWs architecture

Tutorial by @JeroenDeDauw

bit.ly/smw-arch

SMWCon Fall 2013, Berlin

About me

  • Jeroen De Dauw
  • (S)MW dev since 2009
  • Architect Wikidata at WMDE
  • Domain layer guy
  • Software craftsmanship
  • Passion for interoperability and reuse
  • Lolcats!

Overview

  • The data model
  • Data access layer
  • Core workflows
  • Presentation layer
  • Extension points

The data model

  • SMW\DataItem
  • SMW\DataValue
  • SMW\SemanticData

DataItem

  • Represent a basic kind of value, ie number, coordinate, page
  • Immutable
  • Context independent
  • Limited implementations

DataValue

  • Contains a DataItem
  • Contains a DIProperty and a data type
  • Parsing user input
  • Formatting values

SemanticData

  • A subject (DIWikiPage)
  • A list of values (DataItem)
  • Indexed by property (DIProperty)

Data access layer: SMWStore

  • Reading
  • Writing
  • Query answering
  • Setup

SMWStore: reading


SMWSemanticData getSemanticData(SMWDIWikiPage $subject)
                

SMWDataItem[] getPropertyValues($subject, SMWDIProperty $property)
                

SMWDIWikiPage[] getPropertySubjects(SMWDIProperty $property, $value)
                

SMWDIProperty[] getProperties(SMWDIWikiPage $subject)
                

SMWStore: writing


updateData(SMWSemanticData $data)
                

deleteSubject(Title $title)
                

clearData(SMWDIWikiPage $di)
                

SMWStore: query answering


SMWQueryResult getQueryResult(SMWQuery $query)
                

Domain layer query answering


string SMWQueryProcessor::getResultFromQuery(SMWQuery $query, array $params)
                

Domain layer query answering: SMWQuery

  • Contains an SMWDescription
    [[Category:Talks]] [[Has speaker:Jeroen]]
  • Contains an array of SMWPrintRequest
    ? Has title | ?Has length
  • Options such as limit and offset

Core workflow: page save

  • Page saved
  • Data collected into SMWSemanticData
  • Data written to SMWStore

Core workflow: inline queries

  • Page rebuild
  • Ask parser function invoked
  • Ask query wikitext parsed
  • Query passed to store
  • Query result passed to result printer
  • Result printer output added to page

Presentation layer

  • Result formats
  • Parser hooks
  • Special pages
  • Web API

Result printers

Takes an SMWQueryResult, returns a string

Implementations implement SMWIResultPrinter,
typically derive from SMW\ResultPrinter

includes/queryprinters

semantic-mediawiki.org/wiki/Writing_result_formats


protected function getResultText(SMWQueryResult $res, $outputMode) {
    // ...
    return 'some string computed from $res';
}
                    

public function getParamDefinitions(array $definitions) {
    $definitions[] = array(
        'type' => 'string',
        'name' => 'conference',
        'default' => 'SMWCon',
        'message' => 'smw-paramdesc-conference',
    );

    // ...

    return $definitions;
}
                    

protected function getResultText(SMWQueryResult $res, $outputMode) {
    // ...
    if ( $this->params['displaylolcats'] ) {
        // ...
    }
    // ...
}
                    

Parser Hooks

  • includes/parserhooks
  • ask, concept, declare, show, subobject, info, smwdoc, recurring events

Special pages

includes/specials

Web API

includes/api

Extension points

  • Result formats
  • Data values
  • Hooks

Hooks


$wgHooks['someEvent'][] = function() {
    // Handle the event
};
                

docs/hooks.md, ctrl+f "wfRunHooks"

SMWStore::updateData => SMWStore::updateData[Before/After]

Special:Links

View slides at bit.ly/smw-arch

Slides on GitHub (source)

semantic-mediawiki.org

@SemanticMW on Twitter

Special:Attribution