Professional > Table scripting > Working with metadata > Working with labels
 
Working with labels
Sample script file: WorkingWithLabels.mrs
This example script is based on the Museum sample data set. See Running the sample table scripts for information on running the example scripts.
By default, UNICOM Intelligence Reporter creates labels for the axes and elements in your tables from the labels in the variables and categories on which they are based.
Axis and element labels in a table
In the MDM Document, labels for variables and elements are stored in a two-dimensional array for each language, in which the dimensions are user contexts and label types.
User contexts. These define different usages for the metadata, so that different texts and custom properties can be used depending on how the metadata is being used. For example, the Question user context is typically used to define the texts for use during interviewing and the Analysis user context is typically used to define shorter texts for use when analyzing the response data.
Label types. These enable different types of labels to be created for different types of information. For example, the default label type of Label is used for question and category texts and variable descriptions, and the Instruction label type is used for interviewer instructions.
By default, UNICOM Intelligence Reporter creates the axis and element labels from the variable and element labels in the Analysis user context and the default label type. However, you can change the user context and the label type if necessary, using the Document.Context and Document.LabelType properties. For example, to use the Question user context, set the Document.Context property to "Question":
TableDoc.Context = "Question"
Note that changing the user context or label type in the table document does not change the current user context or label type for the MDM document, which is exposed through the Document.MDMDocument property.
Sometimes, you may find that you want to use a user context that doesn't have texts for all the variables and categories you want to use. When this happens, you can define an alternative context that should be used when texts are not available in your first choice user context. For example, to specify that texts should be taken from the Analysis user context when they are not available in the Question user context, you would use script similar to this:
TableDoc.DataSet.MDMDocument.Contexts.Item["Question"].Alternatives.Add("Analysis")
You can overwrite the labels that the Table Object Model creates for an axis using the Axis.Label property. For example, the following changes the label of the expect axis, which is on the side of the table:
MyTable.Side.expect.Label = "Expectation of visit"
This example makes use of the dynamic property expansion feature of mrScriptBasic, which enables you to access the expect item as if it is a property of the Side axis. Note that you cannot use this feature with variables that have a period (.) in their name (for example, variables that are inside a grid or loop). For these variables you would define the axis label like this:
MyTable.Side.SubAxes["expect"].Label = "Expectation of visit"
If you want to change the label for use in multiple tables, it is easier to change it in the MDM Document, because then it will apply to all tables. For example:
TableDoc.DataSet.MDMDocument.Fields["expect"].Label = "Expectation of visit"
The MDM Document is opened in no-save mode, which means that any changes you make are not saved.
You can overwrite the labels that the Table Object Model creates for an element using the Element list syntax or the Element.Label property. For example, if you want to change the label on the autobase element to read "Total" instead of "Base", you can use script similar to the following:
MyTable.Side.MyAxis.Elements.Base.Label = "Total"
When defining labels for axes and elements, the language is assumed to be the currently selected language if you do not specify otherwise. If you are working in a multilingual environment and want to specify a label for a different language, you simply specify the language code. See Working with languages for more information.
When you export your tables, you can optionally export the axis and element names instead of the labels. You do this by setting the UseVariableLabels and UseElementLabels export properties to False. For example:
TableDoc.Exports["mrHtmlExport"].Properties["UseVariableLabels"] = False
See also
A complete example
Working with metadata