introducing extension semanticscribunto · 2017. 5. 30. · tobias oetterer center for information...
TRANSCRIPT
-
Introducing Extension SemanticScribunto
EMWCon Fall 2017
-
Tobias OettererCenter for Information and Media Technologies
Topics
• Scribunto• Data retrieval• Data storage• Tooltips• Query building• Documentation references
-
Tobias OettererCenter for Information and Media Technologies
A short Introduction to Scribunto and Lua
Scribunto is an extension that allows for the embedding of lua scripts in MediaWiki.
“[Lua] is a lightweight multi-paradigm programming language designed primarily for embedded systems and clients”.
https://en.wikipedia.org/wiki/Lua_(programming_language)The introduction of Scribunto addresses performance issues in complex templates, tries to give a tool to write better code, and provides a way to divide display code and logic code. For people coming from a coding background it also offers more familiarity that “coding” in templates.For further reading, please see [0].
[0]: https://en.wikibooks.org/wiki/Scribunto:_An_Introduction
VorführenderPräsentationsnotizenSurvey: Who knows/uses Scribunto?
Explicitly designed to address the shortcomming of the template system
https://en.wikibooks.org/wiki/Scribunto:_An_Introduction/Background: the Scribunto version can be anything from twice as fast to 50 times as fast.[
https://en.wikipedia.org/wiki/Lua_(programming_language)https://en.wikibooks.org/wiki/Scribunto:_An_Introduction
-
Tobias OettererCenter for Information and Media Technologies
How does Scribunto interface with extensions?
When using Scribunto you have to ways of handling MediaWikifunctionalities:• Native Lua libraries• Parser function callsThe first option is preferable since it is normally better designed, more performant and easier to integrate. Unfortunately, the libraries have to be provided by the extension developer. In our case we are in luck: SMW has the Extension:SemanticScribunto.If there is no native support, Scribunto can call any parser function through a frame. However, return values (if present) are always strings.
VorführenderPräsentationsnotizenSurvey: Cargo users here?
-
Tobias OettererCenter for Information and Media Technologies
How does Scribunto interface with extensions?
Lua scriptExtension
Parser
frame:callParserFunction()
VorführenderPräsentationsnotizenVarious packages and functionsOne of which, frame. Args parserfunctions and –tags-- slow, only string#ask many string operations
-
Tobias OettererCenter for Information and Media Technologies
The preferred way
Lua scriptExtension
mw.ext..()
VorführenderPräsentationsnotizenNative lua functions++ more performant, arbitrary return values-- must be provided by devCargo: mw.ext.cargo.querySMW separate extension: Semantic Scribunto
-
Tobias OettererCenter for Information and Media Technologies
Data retrieval
Data retrieval
-
Tobias OettererCenter for Information and Media Technologies
Data retrieval
Three functions are available for data retrieval:1. mw.smw.getPropertyType2. mw.smw.ask3. mw.smw.getQueryResult
VorführenderPräsentationsnotizenmw.smw.getPropertyType: type of property. _dat or _wpg.Ask & getQueryResult: query on store.Query as string or tableDifferent in format of returned result table
-
Tobias OettererCenter for Information and Media Technologies
mw.smw.ask
VorführenderPräsentationsnotizenSimple result formatOne result per rowUses headlines as key, property names otherwiseKnows smw format string (date, headline, etc.)Other params as applicable (NOT link)
-
Tobias OettererCenter for Information and Media Technologies
mw.smw.getQueryResult
VorführenderPräsentationsnotizenMore infoMain sections:MetaPrintrequestsresults
-
Tobias OettererCenter for Information and Media Technologies
mw.smw.getQueryResult
VorführenderPräsentationsnotizenEach result more infoData in printoutsindexed by headline or property nameSome properties very detailed info (e.g. page)Structure as in json result format
-
Tobias OettererCenter for Information and Media Technologies
Data storage
Data storage
-
Tobias OettererCenter for Information and Media Technologies
Data storing
Two functions are available for data storing:1. mw.smw.set2. mw.smw.subobject
VorführenderPräsentationsnotizenWork the sameArguments as string or table (1st param)Subobjet 2nd param: idReturn bool or table
-
Tobias OettererCenter for Information and Media Technologies
Tooltips
Tooltips
-
Tobias OettererCenter for Information and Media Technologies
mw.smw.info
To complete the set of available function, there is also an implementation for the #info parser function. It takes one or two arguments:1. The text, you want to display in the tooltip2. [optional] the type of tooltip image to use [0].
[0]: https://www.semantic-mediawiki.org/wiki/Help:Adding_tooltips
https://www.semantic-mediawiki.org/wiki/Help:Adding_tooltips
-
Tobias OettererCenter for Information and Media Technologies
Query building
Query building
VorführenderPräsentationsnotizenSMW or CargoStory of shelved VW-ideaAlso: how I use my data (structure and cross-references. Tackling redundancy)
-
Tobias OettererCenter for Information and Media Technologies
Topics
VorführenderPräsentationsnotizenString (upper section); mind the pipe as separatorNumber indexed table (middle section)And additional string keys (lower)Note:Selector part firstLua scrambles order of string indexed tables
-
Tobias OettererCenter for Information and Media Technologies
Documentation references
You can find documentation about SemanticScribunto on
https://github.com/SemanticMediaWiki/SemanticScribunto/tree/master/docs
There are also some examples and a little bit more “hands-on” documentation available on
https://sandbox.semantic-mediawiki.org/wiki/Semantic_Scribunto_example
And
https://sandbox.semantic-mediawiki.org/wiki/Category:Semantic_Scribunto_example
VorführenderPräsentationsnotizenDocumentaiton on githubHands on examplesAdditional examples (one very complex set)
https://github.com/SemanticMediaWiki/SemanticScribunto/tree/master/docshttps://sandbox.semantic-mediawiki.org/wiki/Semantic_Scribunto_examplehttps://sandbox.semantic-mediawiki.org/wiki/Category:Semantic_Scribunto_example
-
Tobias OettererCenter for Information and Media Technologies
Try it yourself
What do you need to try it yourself?
VorführenderPräsentationsnotizenGo visit sandbox.semantic-mediawiki.org and try it out!
Introducing Extension SemanticScribuntoTopicsA short Introduction to Scribunto and LuaHow does Scribunto interface with extensions?How does Scribunto interface with extensions?The preferred wayData retrievalData retrievalmw.smw.askmw.smw.getQueryResultmw.smw.getQueryResultData storageData storingTooltipsmw.smw.infoQuery buildingTopicsDocumentation referencesTry it yourself