Difference between revisions of "SMWpc Documentation API Class"
m (1 revision(s)) |
|
(No difference)
|
Latest revision as of 23:44, 23 March 2008
Contents
SMWpc: API on Class level
The following functions operate on class level. This means that they are applied to MediaWiki pages which describe an SMWpc Class. See also the complete list of SMWpc interfaces.
Template:.class definition
Defines a class and sets its basic attributes.
Syntax: {{.class definition|<class>|color=<color>|icon=<icon>|extends=<base class>|doc=<doc>}}
- expects as first parameter the name of the class without the 'Class' prefix.
- color = an optional color (in rrggbb Notation without a leading '#'), defaults to #f7f7f7
- icon = an optional icon file name (without the Image: prefix)
- extends = an optional name of a base class (without 'Class ') from which the current class is derived
- doc = an optional text describing the semantic concept of the class
This template should only be used within a class definition article (like 'Class Foo').
Implementation notes
- It could be useful to have a 'Special:Classes' page.
- This template assigns the meta properties .class color, .class icon, .class extends and .class doc to the class.
Template:.class description
Displays a list of properties of the class. Inherited properties are 'not' included.
Syntax: {{.class description|<class>}}
- expects the name of a class without the 'Class' prefix.
Example
- get the properties specific to 'Students': {{.class description|Student|}} returns:
{{#vardefine:desc|{{#ask:mainlabel=Property|.prop describes::Class Student .prop doc::* .prop refers to::* .prop assigned by::* .prop derived from::*}}}}{{#var:desc}}
Template:.class inheritance
Print all superclasses and the direct subclasse for a class
Syntax: {{.class inheritance|<class>}}
- expects the name of a class, e.g. 'Class Foo'
Template:.class instances
Displays a list of instances of the given class, including inherited properties.
Syntax: {{.class instances|<class>|[<criteria>]}}
- expects the name of a class (or the generic symbol '...') without the 'Class' prefix.
- criteria = an optional condition which restricts the amount of instances; syntax follows #ask.
Example
- get all chess playing students: {{.class instances|Student|[[plays game::Chess]]}}
returns:
{{#ask:format=table|mainlabel=Student|.obj is a::Class Student {{#replace:{{#replace:{{#replace:{{#replace:{{#replace:{{#ask:link=none|Property:+.prop describes::Class Student}}, {{#ask:link=none|Property:+[[.prop describes::{{#vardefine:x|{{#replace:{{#ask:format=list|Class Student.class extends::*}}|/^.*\|([^\]]*)\]\] */|\1}}}}{{#var:x}}]]}}, {{#ask:link=none|Property:+[[.prop describes::{{#vardefine:x|{{#replace:{{#ask:format=list|[[{{#vardefine:x|{{#replace:{{#ask:format=list|Class Student.class extends::*}}|/^.*\|([^\]]*)\]\] */|\1}}}}{{#var:x}}]].class extends::*}}|/^.*\|([^\]]*)\]\] */|\1}}}}{{#var:x}}]]}}, {{#ask:link=none|Property:+[[.prop describes::{{#vardefine:x|{{#replace:{{#ask:format=list|[[{{#vardefine:x|{{#replace:{{#ask:format=list|[[{{#vardefine:x|{{#replace:{{#ask:format=list|Class Student.class extends::*}}|/^.*\|([^\]]*)\]\] */|\1}}}}{{#var:x}}]].class extends::*}}|/^.*\|([^\]]*)\]\] */|\1}}}}{{#var:x}}]].class extends::*}}|/^.*\|([^\]]*)\]\] */|\1}}}}{{#var:x}}]]}}, Template:.class properties 5|/,? [ua]nd( )/|,\1}}|/^,$/|}},|/,+ ?/|::*]³]³}}|/(Attribut|Property):/|³[³[|}}|³|}}}}
Displays a navigation aid to browse class definitions. If the currently selected class has an icon attached it will be shown. Also provides links to graphs of the model an of the meta model.
- expects as first parameter the name of a class (or the generic symbol '...') without the 'Class' prefix.
- color = the background color for the navigation bar; typically this will be the color of the current class
Template:.class references
Displays a list of properties (and their classes) which point to instances of the specified class.
Syntax: {{.class references|<class>}}
- expects the name of a class without the 'Class' prefix.
Example
- get all references to Locations: {{.class references|Location|}}
returns:
{{#vardefine:refs|{{#ask:mainlabel=Property|.prop refers to::Class Location .prop describes::* .prop assigned by::*}}}}A Location may be referenced by:
{{#var:refs}}
Implementation notes
- This template uses a sub-template Template:.class references.ask within its #ask command
Template:.class summary
Displays a summary information about the specified class:
- description
- inheritance
- properties
- references
- instances
Syntax: {{.class summary|<class>}}
- expects the name of a class without the 'Class' prefix.
Template:.class properties
Get a list of all properties for a class
Syntax: {{.class properties|<class>|[all]}}
- expects the name of a class (without the 'Class ' prefix)
- returns a comma separated string which contains the names of all properties which can be used to describe instances of that class.
- If the second parameter is 'all' the string will also contain properties attached to base classes of the specified class ('inherited properties').
Examples
- get the property list of class 'Person': {{.class properties|Person}} returns: {{#replace:{{#replace:{{#ask:link=none|Property:+.prop describes::Class Person}}|/,? [ua]nd( )/|,\1}}|/^,$/|}}
- get the property list of class 'Student' (where 'Student' is a subclass of 'Person'): {{.class properties|Student}} returns: {{#replace:{{#replace:{{#ask:link=none|Property:+.prop describes::Class Student}}|/,? [ua]nd( )/|,\1}}|/^,$/|}}
- get the property list of class 'Student' and of all its base classes: {{.class properties|Student|all}} returns: {{#replace:{{#replace:{{#ask:link=none|Property:+.prop describes::Class Student}}, {{#ask:link=none|Property:+[[.prop describes::{{#vardefine:x|{{#replace:{{#ask:format=list|Class Student.class extends::*}}|/^.*\|([^\]]*)\]\] */|\1}}}}{{#var:x}}]]}}, {{#ask:link=none|Property:+[[.prop describes::{{#vardefine:x|{{#replace:{{#ask:format=list|[[{{#vardefine:x|{{#replace:{{#ask:format=list|Class Student.class extends::*}}|/^.*\|([^\]]*)\]\] */|\1}}}}{{#var:x}}]].class extends::*}}|/^.*\|([^\]]*)\]\] */|\1}}}}{{#var:x}}]]}}, {{#ask:link=none|Property:+[[.prop describes::{{#vardefine:x|{{#replace:{{#ask:format=list|[[{{#vardefine:x|{{#replace:{{#ask:format=list|[[{{#vardefine:x|{{#replace:{{#ask:format=list|Class Student.class extends::*}}|/^.*\|([^\]]*)\]\] */|\1}}}}{{#var:x}}]].class extends::*}}|/^.*\|([^\]]*)\]\] */|\1}}}}{{#var:x}}]].class extends::*}}|/^.*\|([^\]]*)\]\] */|\1}}}}{{#var:x}}]]}}, Template:.class properties 5|/,? [ua]nd( )/|,\1}}|/^,$/|}}
Implementation notes
- 'Template:.class properties' does not use recursion because MediaWiki truncates recursive template calls. Instead it uses a fixed number of sub-templates - which limits the maximum depth of the class tree to 5.
- This could be improved in a php implementation.
- The proposed syntax for an implementation as a parser function is: {{#class:properties|<class>|[all]}}.
Template:.class parents
Get the parent class(es) of a class.
Syntax: {{.class parents|<class>}}
- expects the name of a class (without the 'Class ' prefix)
- returns a string which contains a chain of hyperlinks to all superclasses of the given class.
Example
- get the superclasses of class 'Freshman': {{.class parents|Freshman}} returns: {{#vardefine:parent|{{#vardefine:x|{{#replace:{{#ask:format=list|Class Freshman.class extends::*}}|/^.*\|([^\]]*)\]\] */|\1}}}}{{#var:x}}}}{{#replace:{{#vardefine:parent|{{#vardefine:x|{{#replace:{{#ask:format=list|[[{{#var:parent}}]].class extends::*}}|/^.*\|([^\]]*)\]\] */|\1}}}}{{#var:x}}}}{{#vardefine:parent|{{#vardefine:x|{{#replace:{{#ask:format=list|[[{{#var:parent}}]].class extends::*}}|/^.*\|([^\]]*)\]\] */|\1}}}}{{#var:x}}}}{{#vardefine:parent|{{#vardefine:x|{{#replace:{{#ask:format=list|[[{{#var:parent}}]].class extends::*}}|/^.*\|([^\]]*)\]\] */|\1}}}}{{#var:x}}}}[[{{#var:parent}}]] → [[{{#var:parent}}]] → [[{{#var:parent}}]] → [[{{#var:parent}}]] →|/Class ([^\]]+)/|Class \1|\1}}
Implementation notes
- 'Template:.class parents' does not use recursion because MediaWiki truncates recursive template calls. Instead it uses sub-templates which limits the maximum depth of the class tree to 5.
- An implementation in php would be more efficient and could avoid this limit.
- The proposed syntax for an implementation as a parser function is: {{#class:parents|Foo}}.