On Wed, 2012-04-18 at 08:01 +0000, Dade Christian wrote:
> Hi,
>
> ParserFunctions (v1.1.1) are installed. Functions work within the query, i.e. when I use them as label. So this is working and would bring a table with "4" as label for column "SAP Contact"
>
> {{#ask:
> | [[SAP Objecttype::Hierarchie]]
> | ?SAP Unique Name =Unique Name
> | ?SAP Contact={{#len:blub}}
> }}
>
> This is running as well without error, but would bring no extra column
> (Result table has two columns). There should be an extra column
> "Length of blub", all cells filled with "4" (not very interesting, but
> calculated)
>
> {{#ask:
> | [[SAP Objecttype::Hierarchie]]
> | ?SAP Unique Name =Unique Name
> | ?SAP Contact=Contact
> | {{#len:blub}}=Length of blub
> }}
>
It seems everything work properly, but *your* expectations are totally
incorrect. You do not understand what are you doing. {{#len:blub}}
evaluates to "4", so you are executing the query:
{{#ask:
| [[SAP Objecttype::Hierarchie]]
| ?SAP Unique Name =Unique Name
| ?SAP Contact=Contact
| 4=Length of blub
}}
I am not sure what argument named "4" means for function #ask. It likely
is ignored. Anyway, it will not bring column named "Length of blub"
fulfilled with "4". No way.
If you add leading "?", actual query would be:
{{#ask:
| [[SAP Objecttype::Hierarchie]]
| ?SAP Unique Name =Unique Name
| ?SAP Contact=Contact
| ?4=Length of blub
}}
This queries column "Length of blub" fulfilled with value of property
named "4". I guess you do not have such property.
In my example I calculated *names of properties to request*. Using #if
(or other conditional functions, like #switch), you can choose what
properties to request:
{{#ask:
| ...
| {{ #if: Condition | ?Property1 | ?Property2 }}=Column name
or even control number of columns:
{{#ask:
| ...
| {{ #if: Condition | ?Property1=Column name }}
This works perfect and, I guess, works on your site.
You are trying to fulfill column with calculated data. #ask does not
support it directly, but you can emulate it:
{{#ask:
| ...
| format = template
| template = YouTemplate
Instead of rendering a table, #ask will call you template for every
line, passing row data as arguments. Withing the template, you are free
to format data whatever you like (e. g. add a column with calculated
data).
Beware: Using template is hard. It is hard to predict what would be
argument 1, 2, 3, etc. (That was the reason for implementing named
arguments). There are some hidden arguments like #. Anyway, if you
cannot update your server (MW, SMW, etc) you do not have many options.
Good luck.
Van.
>
> Christian
>
> -----Ursprüngliche Nachricht-----
> Von: Van de Bugger [mailto:van.de.bugger@...]
> Gesendet: Dienstag, 17. April 2012 21:08
> An: Dade Christian
> Cc: semediawiki-user@...
> Betreff: Re: AW: [Semediawiki-user] calculated columns with #ask:?
>
> > {{#ask:
> > [[Visit:+]]
> > {{#if:calculated column...}}
> > |?fixed column...
> > }}
>
> Err… I would say you have to show more complete piece of code. By this
> incomplete fragment I am not sure if it correct.
>
> Do you have ParserFunction extension installed? Does #if function work?
>
> My server runs MediaWiki 1.18.1, Semantic MediaWiki 1.7.1,
> ParserFunctions r105459. PHP and MySQL versions do not matter I believe.
> I am not sure if calculated columns work in earlier versions of MW and
> SMW, but I do not see reason why not. Start your investigation with
> ParserFunctions.
>
> And please "Reply to all", not to me personally.
>
> Van.
>
> On Tue, 2012-04-17 at 06:38 +0000, Dade Christian wrote:
> > Hi,
> >
> > sorry, if my question is somewhat stupid (Of course, I tried the code). I am working on SMW 1.4.0, SF 1.3.6 running on MediaWiki 1.12.0 (PHP 5.2.6, MySQL 5.0.16). I cannot change this configuration. The following/proposed syntax is not working on that installation
> >
> > {{#ask:
> > [[Visit:+]]
> > {{#if:calculated column...}}
> > |?fixed column...
> > }}
> >
> > I can change this to
> >
> > {{#ask:
> > | [[Visit:+]]
> > {{#if:calculated column...}}
> > |?fixed column...
> > }}
> >
> > what is running partly: The fixed columns are correct, the function {{#if:...}} is simply ignored (with and without a pipe; same with and without question mark). Are calculated columns a new feature and not working with my configuration?
> >
> > Best regards
> >
> > Christian
> >
> >
> > -----Ursprüngliche Nachricht-----
> > Von: Van de Bugger [mailto:van.de.bugger@...]
> > Gesendet: Montag, 16. April 2012 21:21
> > An: Dade Christian
> > Cc: 'semediawiki-user@...'
> > Betreff: Re: [Semediawiki-user] calculated columns with #ask:?
> >
> > Hi,
> >
> > Did you try it before asking? Did you face a problem?
> >
> > Yes, calculated columns are possible. For example, here is piece of my
> > working code:
> >
> > {{ #ask:
> > [[Visit:+]]
> > {{ #if: {{{ participant }}}
> > | [[Is participated by::User:{{{ participant }}}]]
> > }}
> > {{ #if: {{{ cache }}}
> > | [[Is paid to::Cache:{{{ cache }}}]]
> > }}
> > {{ #if: {{{ region }}}
> > | [[Is paid to::<q> [[Cache:+]] [[Is located
> > in::Region:{{{ region }}}]] </q>]]
> > }}
> > {{ #ifeq: {{{ type }}} | updated
> > | [[Is a new page::false]]
> > }}
> > | ?# = visit
> > | ?Happened on#ISO = happened on
> > | ?Happened on, TZ# = happened on, tz
> > | ?Is participated by# = is participated by
> > | ?Outcome# = outcome
> > | ?Is paid to# = is paid to
> > | {{ #if: {{{ date }}}
> > | ?{{{ date }}}#ISO = date
> > }}
> > ...
> >
> > Van.
> >
> >
> >
> > On Mon, 2012-04-16 at 14:39 +0000, Dade Christian wrote:
> > > Hello,
> > >
> > > is there a way to add a calculated column to an ask-query. Like:
> > >
> > > {{#ask:[[]] :[[Category:My pages]]
> > > | ?Attribute
> > > | ?{{#len:Attribute}}=length of Attribute
> > > }}
> > >
> > > Or do I have to set the calculated value to a new variable on each page?
> > >
> > > Best regards
> > >
> > > Christian
> > >
> > > ------------------------------------------------------------------------------
> > > For Developers, A Lot Can Happen In A Second.
> > > Boundary is the first to Know...and Tell You.
> > > Monitor Your Applications in Ultra-Fine Resolution. Try it FREE!
> > > http://p.sf.net/sfu/Boundary-d2dvs2
> > > _______________________________________________
> > > Semediawiki-user mailing list
> > > Semediawiki-user@...
> > > https://lists.sourceforge.net/lists/listinfo/semediawiki-user
> >
> >
>
>
|