Data Model > Extending the UNICOM Intelligence Data Model > Working with the Alias Map component > Examples of configuring the Generator > 5: Short aliases
 
5: Short aliases
This topic illustrates ways of maximizing the readability of the alias name when there is an upper limit on its length.
Starting from scratch
VBScript examples
Private Sub Example_5a()
Dim MyConfiguration As MRALIASMAPLib.IGeneratorConfiguration
Dim MyGenerator As New MRALIASMAPLib.Generator
Dim MyMapper As New MRALIASMAPLib.Mapper
Dim MyAlias As MRALIASMAPLib.Alias
Dim MyRule As MRALIASMAPLib.Rule
Dim MyCounter As MRALIASMAPLib.Counter
Dim i As Integer

Set MyConfiguration = MyGenerator.Configuration

MyConfiguration.Clear
MyConfiguration.MaxLength = 8
MyConfiguration.Rules.Clear
Set MyRule = MyConfiguration.Rules.AddNew("$")
MyRule.Replacements.AddOperator ropAutoCounter
MyConfiguration.AutoCounters.AddNew
Set MyCounter = MyConfiguration.AutoCounters.Item(0)
MyCounter.Prefix = "~"
Set MyMapper.Generator = MyGenerator

For i = 0 To 30
Set MyAlias = MyMapper.CreateAlias("Data Collection Development Library")
Debug.Print MyAlias.Name
Next i
End Sub
mrScript example
Sub Example_5a()
Dim MyConfiguration, MyGenerator, MyMapper, MyAlias, MyRule, MyCounter, i
Set MyGenerator = CreateObject("MRALIASMAP.Generator")
Set MyMapper = CreateObject("MRALIASMAP.Mapper")
Set MyAlias = CreateObject("MRALIASMAP.Alias")
Set MyRule = CreateObject("MRALIASMAP.Rule")
Set MyCounter = CreateObject("MRALIASMAP.Counter")

Set MyConfiguration = MyGenerator.Configuration

MyConfiguration.Clear()
MyConfiguration.MaxLength = 8
MyConfiguration.Rules.Clear()
Set MyRule = MyConfiguration.Rules.AddNew("$")
MyRule.Replacements.AddOperator(2 '!ropAutoCounter!')
MyConfiguration.AutoCounters.AddNew()
Set MyCounter = MyConfiguration.AutoCounters[0]
MyCounter.Prefix = "~"

Set MyMapper.Generator = MyGenerator

For i = 0 To 30
Set MyAlias = MyMapper.CreateAlias("Data Collection Development Library")
Debug.Log( MyAlias.Name)
Next
End Sub
This gives aliases of the form Dimensio, Dimens~1, Dimens~2, Dimens~3, and so on.
You can improve this by adding the following lines to add a rule to truncate each section before the uppercase letter.
VBScript example
Set MyRule = MyConfiguration.Rules.AddNew ("[A-Z]")
MyRule.Replacements.AddOperator ropBoundary
MyRule.Replacements.AddOperator ropMatch
mrScript example
Set MyRule = MyConfiguration.Rules.AddNew(("[A-Z]")
MyRule.Replacements.AddOperator(5 '!ropBoundary!')
MyRule.Replacements.AddOperator(7 '!ropMatch!')
This gives aliases of the form DimDevLi, DiDevL~1, DiDevL~2, DiDevL~3, and so on.
Using the ropMatch operand keeps the uppercase letters in the result, but after the boundary, so that they are the last, and not the first, thing to be truncated.
You can use CutFactor to define whether the characters at the beginning or the end of the input text have priority for being retained. When CutFactor is set to 1, the last part of the name has priority. For example, when we add the following line to the example:
MyConfiguration.CutFactor = 1
The results become DLibrary, Librar~1, Librar~2, Librar~3, and so on.
When CutFactor is set to 0, the first part has priority. For example, when we change the CutFactor in the example to 0, the results are Dimensio, Dimens~1, Dimens~2, Dimens~3, and so on.
CutFactor defaults to 0.5 which is an even distribution. It can be anything between 0.0 and 1.0. However, it is overridden by the overall requirement of MaxLength.
See also
1: Simple example
2: Avoiding duplicates
3: Configuring the counter
4: Further examples of configuring the counter
6: Complete examples
7: Multiple aliases
Examples of configuring the Generator