Help:Subobjects and queries

From semantic-mediawiki.org
Subobjects and queries
Explains how to query for a subobject.
Table of Contents

This help page describes how to query for a subobject after they were added to your wiki.

Show all subobjects of a page[edit]

Using #subobject does not print out anything on the screen. Sometimes one would like to show the subobject data directly on the page where it is defined. This can be achieved with the ask query {{#ask: [[-Has subobject::{{FULLPAGENAME}}]] }} which is added after the definition of subobjects.

Example:
Defining two subobjects with identifiers "first" and "second":

{{#subobject:first
 |property1=value1
 |property2=value2
}}

{{#subobject:second
 |property1=value3
 |property2=value4
}}

Then to print out the subobjects one would insert this code on the same page:

{{#ask:
 [[-Has subobject::{{FULLPAGENAME}}]] 
 |?property1
 |?property2
}}

Note the "-" which is necessary to make the query work (see Inverse properties for more information).

Show properties of a subobject's parent page[edit]

In some cases one might not only want to query for subobject data but also for "usual" properties that are defined on the subobject's parent page. The process to do that contains the following steps:

Using property chains[edit]

Example
{{#ask:
 [[-Has subobject::{{FULLPAGENAME}}]] 
 |?-has subobject.YourParentProperty1
 |?-has subobject.YourParentProperty2
 |?YourSubobjectProperty1
 |?YourSubobjectProperty2
}}

Using templates[edit]

  1. Query for a property of a subobject.
  2. Use format=template.
  3. Add another query in this template where you ask for [[Has subobject::{{{1}}}]]. Has subobject returns the parent page of a subobject. The subobject is queried in the first query and passed on to the template as {{{1}}}.
Example
{{#ask:
 [[YourSubobjectProperty::Foo]]
 |?YourSubobjectProperty1
 |?YourSubobjectProperty2
 |format=template 
 |template=YourTemplate
}}

In Template:YourTemplate one adds the following:

{{#ask:
 [[Has subobject::{{{1}}}]]
 |?YourParentProperty1
 |?YourParentProperty2
}}

Examples/Queries/Use subobject with template

Searching for pages with certain subobject properties[edit]

When you want to query for (parent) pages that have certain subobject properties, you can use subqueries:

Example
{{#ask:
 [[Has subobject::<q>[[YourSubobjectProperty::Foo]]</q>]]
 |?YourParentProperty1
 |?YourParentProperty2
}}

This works, because with the query [[Has subobject::]] (without the "-"), you are querying for the (parent) pages that have subproperties. With the subquery, you can then select certain subobject properties. As you are queryinig for parent pages, you can select properties of the parent pages as printouts.

See also[edit]