Semantic mediawiki #ask query: Displaying nested properties on the same query

China☆狼群 提交于 2019-12-07 07:27:11

问题


I would like to display in the same query properties of a page which is related to the pages im querying for.

Let's say I would like to query all the pages in the City category, which are located in Germany, and I want to display the title of the page, but also I want to display the surface data of Germany, for example.

Something like this: {{#ask: [[Category:City]] [[location::Germany]] |?mainlabel |?Location.surface }}

I know this wont work, but you can see what I want to achieve.


回答1:


I'm not sure if there's a way to nest queries directly inside other queries. The normal method of doing it is using a template. So you might define a template (or subpage of the template if this going into a template) called {{tablerow}} that consists of:

<includeonly>
|- valign="top"
| [[{{{1|}}}]]
| {{#show: {{{1|}}} | ?surface }}</includeonly>

The <includeonly> tags are important for reasons I don't really understand, it produces errors sometimes if you leave them out. Then you just run an #ask query with format = template. (You can build the header into the query, but I find it simpler to just put it outside.)

{| class="wikitable smwtable sortable"
|- valign="bottom"
! [[City]]
! [[Surface]]

{{#ask: [[Category:City]] [[location::Germany]]
  | format   = template
  | template = tablerow
  | link     = none
}}

|}

That will punch each result returned by the query through the template as {{{1}}} and generate a row based on it. If you have other data to return from the main query, additional properties that you ask for will come out as consecutive unnamed parameters (so if you include | ?population, that will go into the template as {{{2}}} and will need to be added to the row structure or it will be dropped).



来源:https://stackoverflow.com/questions/15273180/semantic-mediawiki-ask-query-displaying-nested-properties-on-the-same-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!