Status: | effective |
Progress: | 90% |
Version: | 2.3.0+ |
Help:Adding subobjects
(Redirected from Help:Subobjects)
Template:Interlanguagelink: en
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 annotations made with Semantic MediaWiki 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"Holds the subobjects set on a page.
The parser function #set_recurring_event
uses subobjects to store annotation values (see Help:Recurring events).
Syntax
{{#subobject:mysubobject
|Has property 1=value
|Has property 2=values|+sep=...
|...
}}
#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
The syntax for specifying subobjects is very similar to the one used when setting values. Starting with Semantic MediaWiki 2.2.0Released on an unknown date unknown versions of MediaWiki a subobject with no valid annotation content (property-value declaration) is no longer permitted / stored.1
Add multiple lines
{{#subobject:mysubobject
|Has property 1=value1
|Has property 1=value2
|Has property 2=value1
...
}}
Add one line and separate values using a pipe
Starting with Semantic MediaWiki 1.8.0Released on an unknown date unknown versions of MediaWiki 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
|Has property=value1|value2
...
}}
|
" for setting multiple values like e.g. "{{#subobject: Has property=value1|value2 }}
" was deprecated starting with Semantic MediaWiki 3.0.0Released on an unknown date unknown versions of MediaWiki and will be removed in a later version. It is strongly recommended to migrate to using the "|+sep
" parameter.2
Add one line and separate values using a named separator
Semantic MediaWiki 1.9.0Released on an unknown date unknown versions of MediaWiki introduces |+sep=...
to identify the separator (see a demo):
{{#subobject:mysubobject
|Has property 1=Value 1;Value 2;Value 3;Value 4|+sep=;
|Has property 2=12+22+3+4+5+6+7+8+9+10|+sep=+
|Has property 3=123,1234,12345,|+sep=
|Has property 4=One,or,two,more,values|+sep
...
}}
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
}}
A named identifier shall not contain a dot (i.e foo.bar) in the first five characters, this naming scheme is reserved for extensions (starting with Semantic MediaWiki 2.4.0Released on an unknown date unknown versions of MediaWiki this convention is enforced).
Anonymous identifier
Semantic MediaWiki 1.8.0Released on an unknown date unknown versions of MediaWiki 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:|
...
}}
Identifier starting with:
_QUERY...
tag a query meta container_ERR...
tag an error container
Specifying a sortkey
Semantic MediaWiki 2.0.0Released on an unknown date unknown versions of MediaWiki introduces |@sortkey=...
to allow to set an arbitrary sort value for a particular subobject. It will be treated case sensitive, i.e. values are stored as a "string" and will not appear (in terms of visibility) to the end-user but will be ordered as any other 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 in above example is "A".
Conceptional notes
Value declaration
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
As of Semantic MediaWiki 2.3.0Released on an unknown date unknown versions of MediaWiki, @category
can be used to add a category classification. While subobjects with categories can be queried as any other object, they will not appear in an individual Category: ...
list because a subobject is a Semantic MediaWiki and not a MediaWiki concept.
{{#subobject: |Has page=Example/0301/1 |@category=ABC;123|+sep=; }}
Prior to Semantic MediaWiki 2.3.0Released on an unknown date unknown versions of MediaWiki, an alternative approach based solely on properties can be used:
- Name your category-like properties as you would name a category, e.g. "Property:Detective fiction".
- 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.
- In order to classify a subobject in this method, assign, within the subobject, any value to the property which corresponds to the desired classification. The value assigned to the property is irrelevant.
- 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. 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
- Demo:Subobject
- Demo:Setting multiple values using a separator
- Issue with row values vs single values, see Examples/Queries/Bubble chart on aggregate numbers
- Understanding content modelling using subobjects, see Incorrect Sum if more than one property has same numerical value
- Clarify subobject identifiers (named vs. anonymous) output characteristics
Troubleshooting
- Problem with subobjects that have a '=' character in a parameter value when using a template
- See this issue for a workaround.
See also
- Adding subobjects using the Page Forms extension
- Querying subobjects
- Help:Avoiding whitespace when using parser functions
- Some development notes about subobject handling