6: Complete examples
This example handles input texts of the form order[{dinosaurs}].order_view@OpenNumeric1 and creates eight-character aliases. These types of input texts are typical of UNICOM Intelligence Data Model VariableInstance FullNames. Sequences of brackets, [ ], spaces, and braces, { } are replaced with a single underscore, _, except when they are next to a period, when they are replaced with nothing. Truncation takes place after inserted underscores and before periods, but the period itself is not truncated.
VBScript example
Private Sub Example_6a()
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 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
' Strip unwanted characters at the end
Set MyRule = MyConfiguration.Rules.AddNew("[\.\s\{\}\[\]\(\)]+$")
' Strip unwanted characters at the beginning
Set MyRule = MyConfiguration.Rules.AddNew("^[\.\s\{\}\[\]\(\)]+")
' Replace unwanted characters containing periods(s) with one period
Set MyRule = MyConfiguration.Rules.AddNew("[\s\{\}\[\]\(\)]*\.[\.\s\{\}\[\]\(\)]*")
MyRule.Replacements.AddOperator ropProtect
MyRule.Replacements.AddText "."
MyRule.Replacements.AddOperator ropBoundary
'Strip unwanted characters with no periods
Set MyRule = MyConfiguration.Rules.AddNew("[\s\{\}\[\]\(\)]+")
MyRule.Replacements.AddText "_"
MyRule.Replacements.AddOperator ropBoundary
Set MyMapper.Generator = MyGenerator
For i = 0 To 10
Set MyAlias = MyMapper.CreateAlias("order[{wildlife}].order_view@OpenNumeric1")
Debug.Print MyAlias.Name
Next i
For i = 0 To 10
Set MyAlias = MyMapper.CreateAlias("order[{dinosaurs}].order_view@OpenNumeric1")
Debug.Print MyAlias.Name
Next i
End Sub
mrScript example
Sub Example_6a()
Dim MyConfiguration, MyGenerator, MyMapper, MyAlias, MyRule, i
Set MyGenerator = CreateObject("MRALIASMAP.Generator")
Set MyMapper = CreateObject("MRALIASMAP.Mapper")
Set MyAlias = CreateObject("MRALIASMAP.Alias")
Set MyRule = CreateObject("MRALIASMAP.Rule")
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()
' Strip unwanted characters at the end
Set MyRule = MyConfiguration.Rules.AddNew("[\.\s\{\}\[\]\(\)]+$")
' Strip unwanted characters at the beginning
Set MyRule = MyConfiguration.Rules.AddNew("^[\.\s\{\}\[\]\(\)]+")
' Replace unwanted characters containing periods(s) with one period
Set MyRule = MyConfiguration.Rules.AddNew("[\s\{\}\[\]\(\)]*\.[\.\s\{\}\[\]\(\)]*")
MyRule.Replacements.AddOperator(6 '!ropProtect!')
MyRule.Replacements.AddText(".")
MyRule.Replacements.AddOperator(5 '!ropBoundary!')
'Strip unwanted characters with no periods
Set MyRule = MyConfiguration.Rules.AddNew("[\s\{\}\[\]\(\)]+")
MyRule.Replacements.AddText("_")
MyRule.Replacements.AddOperator(5 '!ropBoundary!')
Set MyMapper.Generator = MyGenerator
For i = 0 To 10
Set MyAlias = MyMapper.CreateAlias("order[{wildlife}].order_view@OpenNumeric1")
Debug.Log( MyAlias.Name)
Next
For i = 0 To 10
Set MyAlias = MyMapper.CreateAlias("order[{dinosaurs}].order_view@OpenNumeric1")
Debug.Log( MyAlias.Name)
Next
End Sub
The results are owi.orde, ow.orde1, ow.orde2, ow.orde3, and so on, and odi.orde, od.orde1, od.orde2, od.orde3, and so on.
You can use CutFactor to move focus towards the first or last part of the name as required.
The next example removes unwanted characters and replaces them with an underscore when they are not at the end. There is no limit on the number of characters in the alias.
VBScript example
Private Sub Example_6b()
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 MyReplacements As MRALIASMAPLib.ReplacementCollection
Dim i As Integer
Set MyConfiguration = MyGenerator.Configuration
MyConfiguration.Clear
MyConfiguration.AutoCounters.AddNew
Set MyRule = MyConfiguration.Rules.AddNew("$")
MyRule.Replacements.AddOperator ropAutoCounter, 0
' Strip unwanted characters from the end
Set MyRule = MyConfiguration.Rules.AddNew("[^A-Za-z_0-9#@$]+$")
' Replace other unwanted characters with an underscore
Set MyRule = MyConfiguration.Rules.AddNew("[^A-Za-z_0-9#@$]+")
MyRule.Replacements.AddText "_"
MyRule.Replacements.AddOperator ropMatch, 1
Set MyMapper.Generator = MyGenerator
For i = 0 To 10
Set MyAlias = MyMapper.CreateAlias("order[{wildlife}].order_view@OpenNumeric1")
Debug.Print MyAlias.Name
Next i
For i = 0 To 10
Set MyAlias = MyMapper.CreateAlias("order[{dinosaurs}].order_view@OpenNumeric1")
Debug.Print MyAlias.Name
Next i
End Sub
mrScript example
Sub Example_6b()
Dim MyConfiguration, MyGenerator, MyMapper, MyAlias, MyRule, MyReplacements, i
Set MyGenerator = CreateObject("MRALIASMAP.Generator")
Set MyMapper = CreateObject("MRALIASMAP.Mapper")
Set MyAlias = CreateObject("MRALIASMAP.Alias")
Set MyRule = CreateObject("MRALIASMAP.Rule")
Set MyReplacements = CreateObject("MRALIASMAP.ReplacementCollection")
Set MyConfiguration = MyGenerator.Configuration
MyConfiguration.Clear()
MyConfiguration.AutoCounters.AddNew()
Set MyRule = MyConfiguration.Rules.AddNew("$")
MyRule.Replacements.AddOperator(2 '!ropAutoCounter!', 0)
' Strip unwanted characters from the end
Set MyRule = MyConfiguration.Rules.AddNew("[^A-Za-z_0-9#@$]+$")
' Replace other unwanted characters with an underscore
Set MyRule = MyConfiguration.Rules.AddNew("[^A-Za-z_0-9#@$]+")
MyRule.Replacements.AddText("_")
MyRule.Replacements.AddOperator(7 '!ropMatch!', 1)
Set MyMapper.Generator = MyGenerator
For i = 0 To 10
Set MyAlias = MyMapper.CreateAlias("order[{wildlife}].order_view@OpenNumeric1")
Debug.Log(MyAlias.Name)
Next
For i = 0 To 10
Set MyAlias = MyMapper.CreateAlias("order[{dinosaurs}].order_view@OpenNumeric1")
Debug.Log(MyAlias.Name)
Next
End Sub
The results are:
order_wildlife_order_view@OpenNumeric1, order_wildlife_order_view@OpenNumeric11, order_wildlife_order_view@OpenNumeric12, and so on,
and
order_dinosaurs_order_view@OpenNumeric1, order_dinosaurs_order_view@OpenNumeric11, order_dinosaurs_order_view@OpenNumeric12, and so on.
See also