Difference between revisions of "Adding fields"
m (→Modification of the templates for Project) |
(→Modification of the templates for Project) |
||
Line 64: | Line 64: | ||
| ?PrjTutor | | ?PrjTutor | ||
| ?PrjStarts | | ?PrjStarts | ||
− | |||
− | |||
− | |||
− | |||
| ?PrjResArea | | ?PrjResArea | ||
| ?PrjResTopic | | ?PrjResTopic | ||
Line 75: | Line 71: | ||
</nowiki></pre> | </nowiki></pre> | ||
− | The tricky part is that | + | (note the reference to the template in the last line). The tricky part is that the wiki code of the template includes references to the single data fields output by the query, and that such references are '''positional'''. A template used to visualize data is something like this: |
<pre><nowiki> | <pre><nowiki> | ||
Line 86: | Line 82: | ||
Number {N} between curly brackets is a reference to the Nth value output by the query, with reference to the order of the fields in the query. | Number {N} between curly brackets is a reference to the Nth value output by the query, with reference to the order of the fields in the query. | ||
+ | |||
+ | Returning to the modification to [[Category:Project]] that we performed (addition of field "Coordinator"): if we want the [[Template:ProjectViz]] and [[Template:ProjectVizSlim]] templates to be able to show the new field, we have to take into consideration also the ''queries'' which use such templates, to avoid possible mismatchings between the data output from the queries and their management on the part of the templates. |
Revision as of 12:14, 15 February 2010
Sometimes, you have to modify the semantic description of a category. The typical case happens when you find out that you have left out a crucial feature and you have to add it. To do that, you have to add a field to the semantic description of the category... and go through the additional modification to the wiki required to make the new field fully integrated with AIRWiki, and in particular to make it usable for semantic queries.
As an example, we will describe the operations performed to add a new field to the description of, in order to integrate the new field with the SMW framework of AIRWiki. Of course, the procedure can be easily generalized.
IMPORTANT: this kind of operations introduce structural changes in the AIRWiki. They should be performed only after consultation with professor Bonarini.
Let's add the field "Coordinator" to the Project category, to describe the person that is managing the project (while the "Tutor" is in charge of the students participating to it). These are the steps:
Contents
- 1 Creation of a new category called "Coordinator"
- 2 Choice of the forms which are influenced by the change
- 3 Modification of the form for Project
- 4 Creation of the new property PrjCoordinator associated to category Project
- 5 Definition of the new property
- 6 Choice of the templates which are influenced by the change
- 7 Modification of the templates for Project
Creation of a new category called "Coordinator"
By using the Special:CreateCategory page, this is easy, but we are asked to specify which category (if any) Coordinator should be a subcategory of. The general rule is: define a new category B as a subcategory of a category A which includes all the possible elements of B, but the minimum number of elements outside B. If A doesn't exist, do not define B as a subcategory. By applying this rule, we define "Coordinator" as a subcategory of "Person": in fact the coordinator is most certainly a person, but can be even external to Politecnico di Milano.
Choice of the forms which are influenced by the change
The forms are used for simplified input of data, and are the preferred method to create new pages (when a form is available for the page, of course). Available forms are listed in the Special:Forms page: in our case, the only form to be changed is Form:Project.
Modification of the form for Project
By editing the Form:Project wiki page, we must now insert a field associated to the Coordinator category into the form. Beware: this is a dangerous operation, if you are not an expert of SMW syntax. The best option is to use copy-and-paste judiciously. By adding
! [[Property:PrjCoordinator|Coordinator(s)]]: (NameSurname1; NameSurname2; ...) | {{{field|coordinator|mandatory|autocomplete on category=Coordinator|delimiter=; }}} |-
to the form in a suitable place, we ensure that:
- a new field (called "coordinator") is added to the form: from now on, any page created or edited using this form will possess a box where the coordinator must (note the "mandatory") be specified;
- a new property (called PrjCoordinator) has been introduced but not yet defined.
Creation of the new property PrjCoordinator associated to category Project
After its definition, the value of the property for a specific page belonging to that category will be usable to perform queries. This is done using the special page Special:CreateProperty. This creation mask asks you to specify the kind of values of the property: in our case, we choose one at random since we are going to replace the property page's wiki code immediately after.
Definition of the new property
This is done by editing page Property:PrjCoordinator; in this case we simply substituted the wiki code in it with the following text, adapted from Property:PrjTutor:
This property is used to indicate that a [[:Category:Project|Project]] is managed by one (ore more) [[:Category:Coordinator|Coodinators]].
Choice of the templates which are influenced by the change
The templates are used to format in a standardized way the data of a page. Available templates are listed in the Special:Templates page: in our case, the forms to be changed are:
- Template:Project (it must be changed because it defines the category Project)
- Template:ProjectViz, Template:ProjectVizSlim (to be changed because they are used to display data about the items in a list of Projects) .
Modification of the templates for Project
Beware: this is a dangerous operation, if you are not an expert of SMW syntax. The best option is to use copy-and-paste judiciously.
For template Template:Project, we have to perform two modifications. First, alteration of the description of the template by inserting the following text:
| coordinator=Leonardo Da Vinci | ***NOTE:*** you can specify a LIST of coordinators, separating them with a semicolon (;). Coordinators and tutors can overlap.
Then, alteration of the graphical description of the template to add a table row showing the coordinator(s). This requires adding the following text:
|- {{Tablerow|Label=Coordinator|Value={{#ifeq:{{{coordinator|}}}|||{{#arraymap:{{{coordinator|}}}|; |x|[[prjCoordinator::User:x|x]] ({{#show: User:x| ?Email }})}}}}}}
Templates Template:ProjectViz and Template:ProjectVizSlim are used to format the output of a semantic query such as
{{#ask: [[Category:Project]] | ?PrjTitle | ?PrjImage | ?PrjDescription | ?PrjCoordinator | ?PrjTutor | ?PrjStarts | ?PrjResArea | ?PrjResTopic | format = template | template = ProjectVizSlim }}
(note the reference to the template in the last line). The tricky part is that the wiki code of the template includes references to the single data fields output by the query, and that such references are positional. A template used to visualize data is something like this:
{| style="color:#333333;background-color:#eeeeff;" cellpadding="2" cellspacing="2" frame="border" width="100%" '''Title:''' {{{1}}} <br> '''Description:''' {{{3}}} <br> '''Coordinator:''' {{#arraymap:{{{4|}}}|, |x|x ({{#ask: x| ?Email= }})}} <br> |}
Number {N} between curly brackets is a reference to the Nth value output by the query, with reference to the order of the fields in the query.
Returning to the modification to that we performed (addition of field "Coordinator"): if we want the Template:ProjectViz and Template:ProjectVizSlim templates to be able to show the new field, we have to take into consideration also the queries which use such templates, to avoid possible mismatchings between the data output from the queries and their management on the part of the templates.