Help:Type Record/Record vs. subobject

From semantic-mediawiki.org
< Help:Datatype "Record"
Help:Datatype "Record"Help:Type Record/Record vs. subobject

If you have a one to many relationship, then one of the two alternatives, preferably the #subobject parser function, is going to be more appropriate, because you can query for them on one property, and retrieve the other properties (see examples below). Think of them as pages without having to have their own page and thus avoids cluttering up your wiki.

However, if you have a one to one (page to property value) relationship (enforced by form and template), then you could use either, but a record is going to be easier.

Parser function #subobject[edit]

See the help page Adding subobjects for a detailed description of this built-in alternative, which is available since Semantic MediaWiki 1.7.0Released on 1 January 2012 and compatible with MW 1.16.x - 1.19.x..

Example "Semantic City"

It has several museums:

  • {{Museum|Museum of Modern Art|1000|1800}}
  • {{Museum|Museum of Natural History|0930|1730}}

Where your museum template would set an subobject and display something too:

{{#subobject:
 |Is museum in city={{PAGENAME}}
 |Has name={{{1}}}
 |Has opening time={{{2|}}}
 |Has closing time={{{3|}}}
}}

Now you can query for museums in a given city, and display their opening times:

{{#ask:
 [[Is museum in city::Semantic City]]
 [[Has name::~*History*]]
 |?Has name=Museum
 |?Has opening time=opens
 |?Has closing time=closes
 |mainlabel=-
}}

As a result you should get the "Museum of Natural History" together with its opening and closing times.1

Parser function #set_internal[edit]

This alternative is provided by the extension "Semantic Internal Objects"Allows setting of internal objects in Semantic MediaWiki but basically obsolete when using Semantic MediaWiki 1.9.0Released on 3 January 2014 and compatible with MW 1.19.0 - 1.22.x. or higher due to enhancements to parser function #subobject

Example "Semantic City"

It has several museums:

  • {{Museum|Museum of Modern Art|1000|1800}}
  • {{Museum|Museum of Natural History|0930|1730}}

Where your museum template would set an internal object and display something too:

{{#set_internal:
 Is museum in city
 |Has name={{{1}}}
 |Has opening time={{{2|}}}
 |Has closing time={{{3|}}}
}}

Now you can query for museums in a given city, and display their opening times:

{{#ask:
 [[Is museum in city::Semantic City]]
 [[Has name::~*History*]]
 |?Has name=Museum
 |?Has opening time=opens
 |?Has closing time=closes
 |mainlabel=-
}}

As a result you should get the "Museum of Natural History" together with its opening and closing times.

See also[edit]

References

  1. ^  Semantic MediaWiki: Sandbox example sb:smw:semantic-city