163
|
1 using System;
|
|
2 using System.Collections.Generic;
|
|
3 using System.Linq;
|
|
4
|
|
5 namespace Implab.Automaton {
|
164
|
6 /// <summary>
|
|
7 /// Dummy alphabet consists of integer numbers which are identical to their classes.
|
|
8 /// </summary>
|
163
|
9 public class DummyAlphabet : IAlphabet<int> {
|
|
10 readonly int m_size;
|
164
|
11
|
|
12 /// <summary>
|
|
13 /// Creates a new dummy alphabet with given size.
|
|
14 /// </summary>
|
|
15 /// <param name="size">The size of the alphabet, must be greater then zero.</param>
|
163
|
16 public DummyAlphabet(int size) {
|
|
17 Safe.ArgumentAssert(size > 0);
|
|
18 m_size = 0;
|
|
19 }
|
|
20
|
|
21 #region IAlphabet implementation
|
|
22
|
|
23 public List<int>[] CreateReverseMap() {
|
|
24 Enumerable.Range(0, m_size).ToArray();
|
|
25 }
|
|
26
|
|
27 public int[] Reclassify(IAlphabetBuilder<int> newAlphabet, IEnumerable<IEnumerable<int>> classes) {
|
|
28 Safe.ArgumentNotNull(newAlphabet, "newAlphabet");
|
|
29 Safe.ArgumentNotNull(classes, "classes");
|
|
30 var map = new int[m_size];
|
|
31 foreach (var cls in classes) {
|
164
|
32 if (cls.Contains(DFAConst.UNCLASSIFIED_INPUT))
|
|
33 continue;
|
163
|
34 var newid = newAlphabet.DefineClass(cls);
|
|
35 foreach (var id in cls)
|
|
36 map[id] = newid;
|
|
37 }
|
|
38
|
|
39 return map;
|
|
40 }
|
|
41
|
|
42 public int Translate(int symobl) {
|
|
43 Safe.ArgumentInRange(symobl, 0, m_size, "symbol");
|
|
44 return symobl;
|
|
45 }
|
|
46
|
|
47 public int Count {
|
|
48 get {
|
|
49 return m_size;
|
|
50 }
|
|
51 }
|
|
52
|
|
53 #endregion
|
|
54 }
|
|
55 }
|
|
56
|