Help:Semantic MediaWiki

From Tardis Wiki, the free Doctor Who reference
(Redirected from T:SMW)

Semantic MediaWiki, or SMW, is, without fear of hyperbole, one of the coolest things ever to be added to the basic MediaWiki software.

It transforms the wiki into a truly relational database, with which you can actually use the data that the wiki has been collecting. SMW lets you actually ask questions of the wiki.

With it, you can get answers to questions like:

The questions you can ask are mostly limited by your imagination, and the infrastructure you're willing to add to the wiki.

Moreover all of SMW's output is dynamic. Thus, if you asked the system to tell you which stories were directed by Euros Lyn, it would automatically update Euros Lyn's page if he ever directed more episodes.

In short, SMW gives us the power to convert this wiki into a real database, but also to easily "futureproof" the accuracy of our articles.

A basic example[[edit source]]

Let's imagine that you wanted to know the names of the stories on which Stephan Pehrsson was the director of photography. In the past, your only real hope was going to Stephan's page and hoping that another editor had maintained the list of Stephan's contributions. Now, however you can type this simple command:

{{#ask:[[Category:Doctor Who (2005) television stories]] [[DOP::Stephan Pehrsson]]}}

To break this down, you're asking the database, within the category, Doctor Who (2005) television stories, in which did the property called "DOP" have a value of "Stephan Pehrsson"?

The answer? The Big Bang (TV story), A Christmas Carol (TV story), The Crimson Horror (TV story), Day of the Moon (TV story), Dinosaurs on a Spaceship (TV story), The Doctor, the Widow and the Wardrobe (TV story), A Good Man Goes to War (TV story), The Impossible Astronaut (TV story), The Pandorica Opens (TV story), The Snowmen (TV story), A Town Called Mercy (TV story)

Now, that'll get you your answer, but it's not very pretty. So let's quickly throw it into a more tabular form.

{{#ask:[[Category:Doctor Who (2005) television stories]] [[DOP::Stephan Pehrsson]]
| ? DOP
}}

The code | ? DOP creates a new column into which the property DOP is placed.

 DOP
The Big Bang (TV story)Stephan Pehrsson
A Christmas Carol (TV story)Stephan Pehrsson
The Crimson Horror (TV story)Stephan Pehrsson
Day of the Moon (TV story)Stephan Pehrsson
Dinosaurs on a Spaceship (TV story)Stephan Pehrsson
The Doctor, the Widow and the Wardrobe (TV story)Stephan Pehrsson
A Good Man Goes to War (TV story)Stephan Pehrsson
The Impossible Astronaut (TV story)Stephan Pehrsson
The Pandorica Opens (TV story)Stephan Pehrsson
The Snowmen (TV story)Stephan Pehrsson
A Town Called Mercy (TV story)Stephan Pehrsson

And that's a lot more readable. Not pretty, of course, but readable. We can then dress it up in all sorts of ways. But that involves knowing something about coding tables, which is a little off-topic for us now.

One thing that's easy to spot is that we've created a redlink. We haven't created the property DOP yet, so therefore we get a redlink. For the moment, we can sort of "paper over the crack" by simply unlinking the title. Let's also add in a header for the first column.

{{#ask:[[Category:Doctor Who (2005) television stories]] [[DOP::Stephan Pehrsson]]
| ? DOP
| headers = plain
| mainlabel = Episode name
}}

Making the headers plain and adding a mainlabel of "Episode name" results in this:

Episode nameDOP
The Big Bang (TV story)Stephan Pehrsson
A Christmas Carol (TV story)Stephan Pehrsson
The Crimson Horror (TV story)Stephan Pehrsson
Day of the Moon (TV story)Stephan Pehrsson
Dinosaurs on a Spaceship (TV story)Stephan Pehrsson
The Doctor, the Widow and the Wardrobe (TV story)Stephan Pehrsson
A Good Man Goes to War (TV story)Stephan Pehrsson
The Impossible Astronaut (TV story)Stephan Pehrsson
The Pandorica Opens (TV story)Stephan Pehrsson
The Snowmen (TV story)Stephan Pehrsson
A Town Called Mercy (TV story)Stephan Pehrsson

Truth is, though, you probably wouldn't want a table for something like this, because you really only have one variable — the name of the episode. If you wanted to put this dynamic list on the page Stephan Pehrsson, a simple list would do.

 
{{#ask:[[Category:Doctor Who (2005) television stories]] [[DOP::Stephan Pehrsson]]
| format = ul
}}

If we simply define format = ul, we'll get a bulleted list.

If we simply define format = ul, we'll get a bulleted list. Cool, huh? But there's still one unsatisfactory element. Our dab terms are showing. So how do we get rid of them so that we're just looking at pure titles? Easy. We force the output to run through {{dab away}}, our dab term stripper.

{{#ask:[[Category:Doctor Who (2005) television stories]] [[DOP::Stephan Pehrsson]]
| format = ul
| link = none
| template= dai
}}

Note here that we also have to set link = none simply because {{dai}} — which means dab away italics —  outputs a linked, italicized version of a raw name. So if you give it Castrovalva (TV story) it will give you Castrovalva . Stripping the links before you pass the data to {{dai}} is necessary, or you'd end up with [[Castrovalva (TV story)]].

The final result then is precisely what we want: a list that looks like any other list on any other page about a crew member. It's simple, bulleted, respects both {{TitleSort}} and {{dab away}}.

Best of all, if he comes back and does a new episode, we won't have to update the page. It'll be done for us. Automatically. Simple, perpetual accuracy.

How it works[[edit source]]

Before we go on to more advanced (read: fun) queries, let's stop for a moment to consider how this all works. What voodoo magic allows us to ask the wiki anything and expect an answer?

Basically, in order to get useful data back from the page, you have to change the way you link things. Imagine we add the following to a page:

[[DOP::Stephan Persson]]

This will mark that page as having the property of DOP equalling Stephan Pehrsson. So any time I look for that property value, that page will pop up.

Note, too, that there is no cosmetic difference between these two things:

[[Stephan Pehrsson]], the traditional link
and
[[DOP::Stephan Persson]], the SMW link

Both of these look the same way to anyone reading the page, even down to the mouseover. Stephan Pehrsson (normal) Stephan Pehrsson (SMW). See?

This doesn't mean that we have to go around to every page and start changing these links. To be fair, there are some times when manual editing might be required. But most of this can be handled easily by modifying a single template.

In this case, {{Wales crew}} — which appears on every BBC Wales-made programme — is hugely helpful. We can simply change the to output something like this:

[[producer::{{{producer}}]], [[director::{{{director}}}]], [[DOP::{{{DOP}}}]]

This globally converts all those links in the crew sections of BBC Wales pages from a sea of hundreds of tiny links into something you can really use.

The fun stuff[[edit source]]

Okay, let's move away from Stephan Pehrsson and his simple, one-variable question. If that's all SMW could do, it would be useful, but it wouldn't be much different from DynamicPageList.

The power of SMW is in combining properties so that intelligent questions can be asked.

Let's imagine that we could remember that Verity Lambert had an episode dedicated to her, but we couldn't remember which one. We could go to Verity Lambert/WhatLinksHere and scan through that massive list until we got to a new series episode. But that's pretty slow. Instead let's just do this:

{{#ask:[[Category:Doctor Who (2005) television stories]] [[dedication::Verity Lambert]]}}

That simple little statement gives us an answer in no time: Voyage of the Damned (TV story).