Creating new content (tables) through other tables

From semantic-mediawiki.org
Edited by author.
Last edit: 15:40, 15 September 2015

In addition to table lines on the page about a project, your template (I hope you use template for this) should create subobjects: {{#subobject: | Project = {{FULLPAGENAME}} | Role = {{{Role|}}} | Actor = {{{Actor|}}} | Voice actor = {{{Voice actor|}}} }}.

The tables you want will then be produced by queries: {{#ask: [[Voice actor::{{{Voice actor|+}}}]] | ?Project | ?Role | ?Actor | format = table }} and {{#ask: [[Actor::{{{Actor|+}}}]] | ?Project | ?Role | ?Voice actor | format = table }}.

Of course, you will need to create properties Project, Actor, Voice actor of the type Page and Role of the type Text.

11:07, 15 September 2015
Edited by author.
Last edit: 12:09, 15 September 2015

Thanks for the quick reply,

yes I am using templates for the projects (not for the tables yet since I didnt know how to create n+1 tables as of yesterday since I found this extension)

but it shouldnt be a problem to change the projects.

the template looks like that for now:


{{Movies
|Picture=
|Title=
|Original Title=
|Release=
|Bluray=
|Trailer=
|Dubbing Studio=
|Dialogue Script=
|Dialogue direction=
|Description=
}}

and then I am adding the tables by hand

{| class="wikitable sortable"
|-
! scope="col"|Actor
! scope="col"|Role 
! scope="col"|Voice Actor
|-
| [[Actor 1 ]]||Role 1||[[Voice Actor 1]]
|-
| [[Actor 2 ]]||Role 2||[[Voice Actor 2]]
|}
11:51, 15 September 2015

Hi Clemonde, Alexander made a mistake, probably by accident. Don't use #set for subobjects but #subobject, which is documented here.

12:07, 15 September 2015

Yes, it should be #subobject.

15:41, 15 September 2015
 
Edited by author.
Last edit: 23:38, 15 September 2015

You can define template {{role}} like this:

 <tr><td>[[{{{Actor|}}}]]</td><td>{{{Role|}}}</td><td>[[{{{Voice actor|}}}]]{{#subobject: | Project = {{FULLPAGENAME}} | Role = {{{Role|}}} | Actor = {{{Actor|}}} | Voice actor = {{{Voice actor|}}} }}</td></tr>

and call any number of times it on any project page between <table class="sortable wikitable"><thead><tr><th>Actor</th><th>Role</th><th>Voice actor</th></tr></thead><tbody> and </tbody></table>.

These table header and footer can also be wrapped in a template {{roles}}: <table class="sortable wikitable"><thead><tr><th>Actor</th><th>Role</th><th>Voice actor</th></tr></thead><tbody>{{{1|<tr><td colspan="3">put one or more role templates here</td></tr>}}}</tbody></table>.


Or better, create a Lua function that can accept a variable number of arguments.

15:48, 15 September 2015

thanks guys, I will see if it works and give feedback tomorrow

17:43, 15 September 2015

before I can can even start testing:

maybe I am just too stupid for the basic installation of semantic mediawiki ...

do I need to install composer on my server where the wiki is located or on my local machine?

Maybe I should use the tarball method :D

22:32, 15 September 2015

The recommended way to install SMW is with composer, yes. The second best (I hope it is still working) is with git, although it will not take care of the dependencies. Downloading tarball will make upgrading difficult.

23:37, 15 September 2015

Composer is the recommended installation method (this is to ensure that dependencies as specified are loaded and not added by random selection or version).

I would not recommend git unless you are a developer or know what you are doing (if we change dependencies then this will have to be taken care of by the user him(her)self, and we do change dependencies).

Tarball is another option but if a new release occurred then you need to replace files in the extension and vendor directory to update all dependencies deployed by the new tarball.

23:51, 15 September 2015
 

> do I need to install composer on my server where the wiki is located or on my local machine?

Please have look at Help:Composer#Individual_file_release.

23:54, 15 September 2015
 
 

dear Alexander Mashin, could you show me the {{{role}}} and {{{roles}}} templates with an example in wiki please?

btw the ask function does work perfectly:


{{#ask: [[Actor::{{{Actor|+}}}]] 
| mainlabel=-
| ?Year
| ?Project 
| ?Role 
| ?Voice Actor
| format = sortable 
| sort = Year
| order = desc
}}


btw you can use "nocinclude" to make it look like I did

and is it possible to set a width for the output-table?

23:07, 17 September 2015

I have not created those templates in any wiki. You could just copy the wikitext for them that I wrote in one of my previous replies.

As to table's width, you can use widetable format or set the table width for .smwtable class with site-wide CSS in MediaWiki:Common.css.

23:24, 17 September 2015

adding

.smwtable {
    width: 650px;
}

in the Mediawiki.Common.css works like a charm

, and is no wikicode, is it?

17:28, 18 September 2015

It's plain HTML, which is also allowed in wikis. You can try to use equivalent wikicode, but there might be issues while assembling a table from several templates. You may need to screen pipes (| → {{!}}) and carefully avoid extra spaces.

17:39, 18 September 2015

this is how it looks like for now:

Men in Black (1997)

and

Template:Name

(it's just my wiki where I test stuff)

18:47, 18 September 2015
 
 

I've got the link to this community-portal from Clemonde and tried it on a fresh mediawiki with smw extension.

My sobobject tuples look like this.

{{#subobject: 
| Project = {{FULLPAGENAME}} 
| Year = 1995
| Role = Det. Mike Lowrey
| Actor = Will Smith
| Voice Actor = Leon Boden
}}

{{#subobject: 
| Project = {{FULLPAGENAME}} 
| Year = 1995
| Role = Det. Marcus Burnett
| Actor = Martin Lawrence
| Voice Actor = Torsten Michaelis
}}

The following statement made it possible to put these subobjects in one table:

{{#ask: [[Actor::{{{Actor|+}}}]] 
| mainlabel= -
| ?Actor
| ?Role
| ?Voice Actor 
| format = sortable 
| sort = Year
| order = desc
}}

What exactly does [[Actor::{{{Actor|+}}}]] do? I red the user-manual but could not figured it out properly


I tried to write two actor/voice-actor/role tuple in one subobject. But as a result the site of the Actor/Voice-Actor did show all tuple and not just the one WHERE Actor.Name = Will Smith

The ask command in the actor template:

{{#ask: [[Actor::{{FULLPAGENAME}}]] 
| mainlabel=-
| ?Year
| ?Project
| ?Role 
| ?Voice Actor
| format = sortable
| sort = Year
| order = desc
}}


Is there an easy way to fill the project table manually (by hand) and extract the needed data in the pages of Actor/Voice actor? A subobject for every tuple is a bit overwhelming.

Maybe a pseudo SQL statement helps:

SELECT Actor.Name, Role.Name, VoiceActor.Name
FROM Project
WHERE Actor.Name = Will Smith
02:50, 20 September 2015

> What exactly does [[Actor::{{{Actor|+}}}]]</code> do? This is the WHERE clause of the query.

My example assumes that the {{{#ask:…}} statement is used on the template called, say Template:Actor's roles, which receives Actor as an argument: {{Actor's roles|Actor=John Smith}}.

If Actor is not given ({{Actor's roles}}), + will be used to choose all role subobjects where Actor property is set.

Another possible solution is to use the page title as the default value for Actor argument: [[Actor::{{{Actor|{{FULLPAGENAME}}}}}]]. In this case the template call on a page about an actor will look simply like this: {{Actor's roles}}.

22:40, 21 September 2015