Help:Adding subobjects

From semantic-mediawiki.org
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. The pages containing values set with this parser function are stored with special property Has subobject.

Syntax

{{#subobject:mysubobject
 |property1=value
 |property2=values|+sep=...
 |property3=value1|value2|value3
 |...
}}

Note Note: Like the #set parser function the #subobject parser function is a form of silent annotation: it adds values to properties but does not print anything to the page.

Specifying multiple values for the same property

Add multiple lines

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

Add one line and seperate 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
 |property2=value1|value2
 ...
}}

Add one line and seperate values using a named separator

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

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

Note Note: To use a named separator is required if multiple values to a single property should be assigned to e.g. multi-instance templates.

Specifying an identifier

Subobjects can have a named 'identifier'. This can be used to directly specify multiple property value combinations to a given data object.

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. If two subobject entities are identical in content (meaning they build an identical hash key) within the same page then only one entity will be stored and available for query representation.

{{#subobject:|
 ...
}}

Specifying a sortkey

SMW 2.0 introduces |@sortkey=... allowing to to set an arbitrary sort value for a particular subobject. This will be treated case sensitive, i.e. values are stored as a "string" and further will not appear visible to the end-user. The subobject with a dedicated sortkey will work as a regular wiki page using a sortkey.

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

The sortkey is thus "A" for this suboject.

Conceptional notes

Using properties

If a subobject contains the same declarations then it is being recognized as being the same (technically a hash is produced to compare those entities) unless it describes something different (using an explicit name opposed to the auto-identifier given without an explicit name). Using a different name on a subobject embedded within the same subject creates an independent entity about something that may or may not be described by the same facts.

{{#subobject:
 |Foo=Bar
}}
{{#subobject:
 |Foo=Bar
}}

Both subobjects declare the same attributes while

{{#subobject:Foo
 |Foo=Bar
}}
{{#subobject:Bar
 |Foo=Bar
}}

are equal in its declaration to produce the same annotation but are different to the end that it represents a Subject X#Foo and the other a Subject X#Bar. Another way to create a distinctions is by using `@sortkey` (those are not equal hence treated as different entities and therefore can be queried individually):

{{#subobject:
 |Foo=Bar
 |@sortkey=Foo
}}
{{#subobject:
 |Foo=Bar
 |@sortkey=Bar
}}

Using categories

A subobject being a 2-ary about a thing (explaining a thing not a set of things, see Help:Category vs. property) and linking to a subject not a class of things therefore MediaWiki's native categories (as being a class) cannot be applied to a subobject. If you need the functionality of a category and cannot achieve this with traditional property-value pairs, there is still room for an alternative approach based solely on properties:

  • Name your category-like properties as you would name a category, e.g. "Property:Detective fiction".
  • The values used for this property need not concern us here.
  • Using Property:Subproperty of, you can arrange these category-like properties into a deeply nested hierarchy (e.g. "Property:Detective fiction" is a member of "Property:Crime fiction" is a member of "Property:Genres", etc.). In this way, you can closely mimic a category hierarchy.
  • While with a traditional category-based approach, you would query on [[Category:Crime fiction]] and retrieve only pages belonging to this category and its subcategories, you can now query on [[Crime fiction::+]] and retrieve pages as well as subobjects that belong to this property and its subproperties.

Querying for subobjects

Main page: Help:Subobjects and queries

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

For more information about subobjects and queries, see here.

Examples

Troubleshooting

Problem with subobjects that have a '=' character in a parameter value when using a template
See this issue for a workaround.

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