Data Model > Extending the UNICOM Intelligence Data Model > Working with the Alias Map component > Examples of using the Alias Map component
 
Examples of using the Alias Map component
This topic provides examples to illustrate using the Alias Map component. The examples assume that the generator has been configured appropriately and show the results that you get using the default configuration. The examples define the dictionary as case insensitive.
Using the Mapper
VBScript example:
Private Sub UsingMapper()
Dim MyMapper As New MRALIASMAPLib.Mapper
Dim MyAlias As MRALIASMAPLib.Alias
Dim i As Integer

MyMapper.Dictionary.IsCaseInsensitive = True

For i = 0 To 10
Set MyAlias = MyMapper.CreateAlias("Hello World!")
Debug.Print MyAlias.Name
Next i
End Sub
mrScript example:
Function UsingMapper()
Dim MyMapper, MyAlias, i
Set MyMapper = CreateObject("MRALIASMAP.Mapper")
Set MyAlias = CreateObject("MRALIASMAP.Alias")

MyMapper.Dictionary.IsCaseInsensitive = True
For i = 0 To 10
Set MyAlias = MyMapper.CreateAlias("Hello World!")
Debug.Log(MyAlias.Name)
Next
End Function
Using the default configuration, the results are:
HellWorl
HellWor1
HellWor2
HellWor3
HellWor4
HellWor5
HellWor6
HellWor7
HellWor8
HellWor9
HelWor10
Using the GeneratorDirectly
To get a unique alias, repeat creating aliases with IGenerator.Next until IDictionary.Retrieve returns null. Then you use IDictionary.Store to store the alias. This is what IMapper.CreateAlias does.
VBScript example
Private Sub UsingGeneratorDirectly()
Dim MyGenerator As New MRALIASMAPLib.Generator
Dim MyDictionary As New MRALIASMAPLib.Dictionary
Dim MyAlias As MRALIASMAPLib.Alias
Dim GoodAlias As Boolean
Dim i As Integer

MyDictionary.IsCaseInsensitive = True

For i = 0 To 10
MyGenerator.Text = "Hello World!"
GoodAlias = False
Do
Set MyAlias = MyDictionary.Retrieve(MyGenerator.Alias)
If MyAlias Is Nothing Then
MyDictionary.Store MyGenerator.Alias
GoodAlias = True
Debug.Print MyGenerator.Alias
Else
MyGenerator.Next
End If
Loop Until GoodAlias = True
Next i
End Sub
mrScript example
Sub UsingGeneratorDirectly()
Dim MyGenerator, MyDictionary, MyAlias, GoodAlias, i
Set MyGenerator = CreateObject("MRALIASMAP.Generator")
Set MyDictionary = CreateObject("MRALIASMAP.Dictionary")
Set MyAlias = CreateObject("MRALIASMAP.Alias")

MyDictionary.IsCaseInsensitive = True

For i = 0 To 10
MyGenerator.Text = "Hello World!"
GoodAlias = False
Do
Set MyAlias = MyDictionary.Retrieve(MyGenerator.Alias)
If MyAlias = Null Then
MyDictionary.Store(MyGenerator.Alias)
GoodAlias = True
Debug.Log(MyGenerator.Alias)
Else
MyGenerator.Next()
End If
Loop Until GoodAlias = True
Next
End Sub
When the default configuration is used, the results are the same as the results given by the previous example.
See also
Regular expressions
Working with the Alias Map component