Adding fields

From AIRWiki
Revision as of 12:51, 15 February 2010 by GiulioFontana (Talk | contribs) (Modification of the form for Project)

Jump to: navigation, search

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:

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.

Selection 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

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 editing the Form:Project wiki page, we must now insert a field associated to the Coordinator category into the form. 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]].

Selection 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. At the time of writing this, the forms which are used to process data associated to a Project are the following:

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. (Note that not all the data output by the query is used by the template.) The point is: as the only connection between data output by a query and data input into a template is the position of such data within the query, if you change the template (e.g., adding a field), you could also have to change the query. So before changing a visualization template, you also have to find all AIRWiki pages using that template (use the "search" tool on the left of the wiki pages, searching for the name of the template): and possibly modify them too.

Let's return to the modification to that we performed (addition of field "Coordinator"). The first issue to define is this: are the ProjectViz and/or ProjectVizSlim templates in need of a modification? This need emerges if we want them to display the new data (the Coordinator field) added to the Project category. Unfortunately, this is the case for both templates: in fact we want them to show the Coordinator, so we will have to modify both of them by adding a new element. In the case of ProjectVizSlim, this is done by substituting the display of the Tutor field with that of the Coordinator field, changing the wiki code from

{| style="color:#333333;background-color:#eeeeff;" cellpadding="2" cellspacing="2" frame="border" width="100%"
| '''Wiki Page:''' {{{1}}} {{#ifeq:{{{3|}}}|||[[{{{3}}}|frameless|border|right]]}} <br> 
'''Title:''' {{{2}}} <br> 
'''Description:''' {{{4}}} <br>
'''Tutor:''' {{#arraymap:{{{4|}}}|, |x|x ({{#ask: x| ?Email= }})}} <br>
|}

to

{| style="color:#333333;background-color:#eeeeff;" cellpadding="2" cellspacing="2" frame="border" width="100%"
| '''Wiki Page:''' {{{1}}} {{#ifeq:{{{3|}}}|||[[{{{3}}}|frameless|border|right]]}} <br> 
'''Title:''' {{{2}}} <br> 
'''Description:''' {{{4}}} <br>
'''Coordinator:''' {{#arraymap:{{{5|}}}|, |x|x ({{#ask: x| ?Email= }})}} <br>
|}

Why the change from {4|} to {5|}? Because we also had to modify the query to provide the




point is: if the modification performed on category Project requires that one of the already existing queries using Template:ProjectViz or Template:ProjectVizSlim requires a modification, then the relevant template will have to be checked (and possibly modified too). So we have to search for existing AIRWiki pages