Recursively defining properties on SMW

From semantic-mediawiki.org
Edited by another user.
Last edit: 04:32, 7 June 2013

I'm using SMW to create a course made out of several pages and would like to add something along the lines of a progress counter. Each wiki page has a property indicating which course it belongs to and a property indicating the preceding page.

With this idea, I thought it might actually be possible to recursively define the page number of each particular page belonging to a particular course. This is probably the fastest way to define page numbers without having to manually write in the page number for each page. The latter would definitely bring about a lot of work if I were to insert a page in say, between the first and second page.

However, the question is then, how do I implement this with SMW?

I was guessing I could define a page number variable which will then be SET in the template itself. {{#if: {{{PreviousPage|}}} | {{ #set: PageNumber={{#expr ( {{#ask: <call page number of preceding page?> }} + 1) | {{#set: PageNumber=1}} }}

Would the set function actually work in this case (assuming this recursive method even works)? Or is there a more elegant method to accomplish the said task?

16:17, 20 May 2013

Have you tried asking via the mailing list? The chances are higher over there that you will get a response.

20:19, 6 June 2013
 

{{#if: {{{PreviousPage|}}} | {{ #set: PageNumber={{#expr: {{#show: {{{PreviousPage}}} | ?PageNumber }} + 1 }} | {{#set: PageNumber=1}} }}. This should work, I think, although not immediately. You may need to touch all pages in correct order starting from the first to set page numbers.

There may be a healthier way of ordering pages. Do not set {{{PreviousPage}}} in your template. Instead, set some number denoting page position, not necessarily incrementing by one: {{#set:Ordering = {{{Order|1}}} }}. Thence you can get the page number: {{#expr: {{#ask:[[Ordering::<{{{Order|1}}}]] [[Course::{{{Course}}}]] | format = count}} + 1}} and previous page: {{#ask: [[Ordering::{{#ask:[[Ordering::<{{{Order|1}}}]] [[Course::{{{Course}}}]] | ?Ordering | mainlabel = - | format = max}}]] | ? }}.

04:44, 7 June 2013