语义mediawiki#询问查询:在同一查询上显示嵌套属性 [英] Semantic mediawiki #ask query: Displaying nested properties on the same query

查看:152
本文介绍了语义mediawiki#询问查询:在同一查询上显示嵌套属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在与我正在查询的页面相关的页面的相同查询属性中显示.

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.

类似这样的内容:{{#ask: [[Category:City]] [[location::Germany]] |?mainlabel |?Location.surface }}

我知道这行不通,但是您可以看到我想要实现的目标.

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

推荐答案

我不确定是否可以将查询直接嵌套在其他查询中.通常的方法是使用模板.因此,您可以定义一个名为{{tablerow}}的模板(如果进入模板,则为模板的子页面),该模板包括:

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>

<includeonly>标记很重要,原因是我不太了解,有时将其遗漏会产生错误.然后,您只需使用format = template运行#ask查询. (您可以将标头构建到查询中,但我发现将标头放到外部更简单.)

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
}}

|}

这会将查询返回的每个结果作为{{{1}}}贯穿模板,并基于该行生成一行.如果您还有其他要从主查询返回的数据,则您要查询的其他属性将作为连续的未命名参数出现(因此,如果包含| ?population,它将作为{{{2}}}进入模板,并且需要添加到行结构,否则将被删除.)

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).

这篇关于语义mediawiki#询问查询:在同一查询上显示嵌套属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆