Help:Adding subobjects

From semantic-mediawiki.org
(Redirected from Subobject)
Jump to: navigation, search
Adding subobjects
Create a subobject on a page
Further Information
Provided by: Semantic MediaWiki
Minimum version: 1.7.0
Maximum version: still supported
Function: yes
Tag: no
Name: #subobject
Table of Contents

The parser function #subobject allows SMW annotations to refer to objects that have their own property-value pairs just like wiki pages, but that do not actually have a page in the wiki. This can be used to "group" property-value pairs given on one page without requiring new auxiliary pages to be created. It also integrates the main functionality of the Semantic Internal Objects (SIO) extension into SMW (note the syntax differences below). The pages containing values set with this parser function are stored with special property Has subobject.

Syntax

{{#subobject:mysubobject
|property1=value
|property2=value
|property3=value
|...
}}

Multiple values

Simply add multiple values for the same property:

{{#subobject:mysubobject
|property1=value1
|property1=value2
}}

Multiple values using a pipe

Starting with SMW 1.8.0 multiple values may be set with "|" as a delimiter. This does not create new restrictions on values but provides a convenient short-cut. The following is the same as the above:

{#subobject:mysubobject
|property1=value1|value2
}}

Multiple values using a named separator

SMW 1.9.0 introduces |+sep=... to identify the separator (see a demo):

{{#subobject:
 |property1=value1;value2;value3|+sep=;
 |property2=value1,value2,value3|+sep=,
...

Subobject Identifier

Unlike SIO, subobjects have a named 'identifier'. This can be used to ...

Named identifier

This subobject adds the street address to the page as a subobject which is identified by the name street address:

{{#subobject:street address
| street number=10
| street name=Parks Road
| postcode=OX1 3QD
| city=Oxford
| country=UK
}}

Anonymous identifier

SMW 1.8.0 supports anonymous identifiers (hash-numbering) for objects that do not use a named identifier:

{{#subobject:| ...}}

Querying for subobjects

Subobjects can be treated just like pages (but can't be associated with a given category). The simplest way to query for a set of subobjects is to ask for the existence of a property that is unique to the subobjects, e.g.

{{#ask: [[postcode::+]] |? street number |? street name ...}}

(assuming that all 'address' subobjects have the postcode property). For querying purposes, you can define a 'dummy' property for subobjects that you want to group together in this way, e.g. 'is address=1'.

Related tips

Using several #subobject data declarations within the same page can cause whitespace to appear in the article. This can be avoided by wrapping the declaration into a div-element:

<div style="display:none;">{{#subobject: ...}} ... {{#subobject: ...}}</div>

See also: stripnewlines.

See also


This documentation page applies to all SMW versions from 1.8.0 to the most current version.
Other versions: 1.7.0 – 1.7.1       Other languages: de

Help:Adding subobjects en 1.8.0