Search code examples
semantic-mediawiki

How to display properties of a nested query in semantic media wiki?


I have a category called actors and another called film. The category film has the property 'hasBudget' and 'hasActor'. Each actor has the property 'hasNationality'.

I need a to display a list of Australian actors who have features in films with a budget above 40 million.

I use the following query to list the actors and the corresponding films and the budget.

{{#ask:[[Category:Actor]] [[hasNationality::Australia]] [[-hasActor::<q>    
[[Category:Film]] [[hasBudget::>40000000]]</q>]]
|?#
|?-HasActor
|?HasBudget
|format=broadtable
|link=all
|headers=show
|searchlabel=... further results
|class=sortable wikitable smwtable
}}

However this is not able to pick the budget from the subquery. How can I extract the budget property?

Any help is very much appreciated..thanks


Solution

  • That's right - you're querying for Category:Actor so as result you're receiving Actor pages and not Film pages. There are no "joins" in SMW query syntax, so only way to achieve it is to use sub-queries along with template result format.

    The idea is to encapsulate sub-queries into templates, this way you will be able to query for particular Actors first, then query on results (like displaying list of Films and their budgets per Actor ).

    Modify your query like that:

    {{#ask:[[Category:Actor]] [[hasNationality::Australia]] [[-hasActor::<q>    
    [[Category:Film]] [[hasBudget::>40000000]]</q>]]
    |?=title
    |format=template
    |link=none
    |searchlabel=... further results
    |named args=yes
    |template=Actor result
    }}
    

    Create a template called something like Actor result:

    Actor: {{{?title}}}
    Actors films: {{#ask: [[Category:Film]] [[hasActor::{{{?title}}}]] |?hasBudget }}
    

    So, this way you will receive list of actors who featured films with >40000000 budget and then in Actor result template you will query for list of films & their budgets for each actor.