Example #1
0
        public void Preprocess(ICrossDictionary aDict)
        {
            _horizontalPatterns = new List <CrossPattern>();
            _startWords.Sort(new YXStartWordComparer()); // first create horizontal patterns

            int wordIdx = 0;

            for (int y = 0; y < _sizeY; y++)
            {
                int nextX = 0;
                while (wordIdx < _startWords.Count)
                {
                    var sw = _startWords[wordIdx];
                    // Console.WriteLine("StartWord x:{0} y:{1} idx:{2}/cnt:{3}",sw.StartX,sw.StartY,wordIdx,_startWords.Count);
                    if (sw.StartY == y)
                    {
                        if (sw.StartX - nextX >= MinPatternLength)
                        {
                            var cp = new CrossPattern(nextX, y, sw.StartX - nextX, true);
                            // Console.WriteLine("SW pattern startX: {0} startY: {1} len: {2}",cp.StartX, cp.StartY, cp.Length);
                            _horizontalPatterns.Add(cp);
                        }
                        nextX = sw.StartX + 1;
                        wordIdx++;
                    }
                    else
                    {
                        break;
                    }
                }
                if (_sizeX - nextX >= MinPatternLength)
                {
                    var cp = new CrossPattern(nextX, y, _sizeX - nextX, true);
                    // Console.WriteLine("EL pattern startX: {0} startY: {1} len: {2}",cp.StartX, cp.StartY, cp.Length);
                    _horizontalPatterns.Add(cp);
                }
            }

            _verticalPatterns = new List <CrossPattern>();
            _startWords.Sort(new XYStartWordComparer()); // then create vertical patterns

            wordIdx = 0;
            for (int x = 0; x < _sizeX; x++)
            {
                int nextY = 0;
                while (wordIdx < _startWords.Count)
                {
                    var sw = _startWords[wordIdx];
                    // Console.WriteLine("StartWord x:{0} y:{1} idx:{2}/cnt:{3}",sw.StartX,sw.StartY,wordIdx,_startWords.Count);
                    if (sw.StartX == x)
                    {
                        if (sw.StartY - nextY >= MinPatternLength)
                        {
                            var cp = new CrossPattern(x, nextY, sw.StartY - nextY, false);
                            // Console.WriteLine("SW patternY startX: {0} startY: {1} len: {2}",cp.StartX, cp.StartY, cp.Length);
                            _verticalPatterns.Add(cp);
                        }
                        nextY = sw.StartY + 1;
                        wordIdx++;
                    }
                    else
                    {
                        break;
                    }
                }
                if (_sizeY - nextY >= MinPatternLength)
                {
                    var cp = new CrossPattern(x, nextY, _sizeY - nextY, false);
                    // Console.WriteLine("EL patternY startX: {0} startY: {1} len: {2}",cp.StartX, cp.StartY, cp.Length);
                    _verticalPatterns.Add(cp);
                }
            }

            BindAdjacentPatterns();

            // calculate instantiation count
            var wordLengthCount = new int[aDict.MaxWordLength + 1];

            for (int i = 1; i <= aDict.MaxWordLength; i++)
            {
                wordLengthCount[i] = aDict.GetWordOfLengthCount(i);
            }

            int patternCount = GetPatternCount();

            for (int i = 0; i < patternCount; i++)
            {
                var pattern = GetCrossPattern(i);
                if (pattern.Pattern == null)
                {
                    // empty
                    pattern.InstantiationCount = wordLengthCount[pattern.Length];
                    pattern.Pattern            = Enumerable.Repeat('.', pattern.Length).ToArray();
                }
                else
                {
                    // already set some letters
                    pattern.InstantiationCount = aDict.GetMatchCount(pattern.Pattern);
                }
            }
        }
Example #2
0
    public void Preprocess(ICrossDictionary aDict)
    {
        _horizontalPatterns.Clear();
        _startWords.Sort(new YXStartWordComparer()); //first create horizontal patterns

        int wordIdx = 0;

        for (int y = 0; y < _sizeY; y++)
        {
            int nextX = 0;
            while (wordIdx < _startWords.Count)
            {
                var sw = _startWords[wordIdx];
                //Console.WriteLine("StartWord x:{0} y:{1} idx:{2}/cnt:{3}",sw.StartX,sw.StartY,wordIdx,_startWords.Count);
                if (sw.StartY == y)
                {
                    if (sw.StartX - nextX >= MinPatternLength)
                    {
                        var cp = new CrossPattern(nextX, y, sw.StartX - nextX, true);
                        //Console.WriteLine("SW pattern startX: {0} startY: {1} len: {2}",cp.StartX, cp.StartY, cp.Length);
                        _horizontalPatterns.Add(cp);
                    }

                    nextX = sw.StartX + 1;
                    wordIdx++;
                }
                else
                {
                    break;
                }
            }

            if (_sizeX - nextX >= MinPatternLength)
            {
                var cp = new CrossPattern(nextX, y, _sizeX - nextX, true);
                //Console.WriteLine("EL pattern startX: {0} startY: {1} len: {2}",cp.StartX, cp.StartY, cp.Length);
                _horizontalPatterns.Add(cp);
            }
        }

        _verticalPatterns.Clear();
        _startWords.Sort(new XYStartWordComparer()); //first create horizontal patterns

        wordIdx = 0;
        for (int x = 0; x < _sizeX; x++)
        {
            int nextY = 0;
            while (wordIdx < _startWords.Count)
            {
                var sw = _startWords[wordIdx];
                //Console.WriteLine("StartWord x:{0} y:{1} idx:{2}/cnt:{3}",sw.StartX,sw.StartY,wordIdx,_startWords.Count);
                if (sw.StartX == x)
                {
                    if (sw.StartY - nextY >= MinPatternLength)
                    {
                        var cp = new CrossPattern(x, nextY, sw.StartY - nextY, false);
                        //Console.WriteLine("SW patternY startX: {0} startY: {1} len: {2}",cp.StartX, cp.StartY, cp.Length);
                        _verticalPatterns.Add(cp);
                    }

                    nextY = sw.StartY + 1;
                    wordIdx++;
                }
                else
                {
                    break;
                }
            }

            if (_sizeY - nextY >= MinPatternLength)
            {
                var cp = new CrossPattern(x, nextY, _sizeY - nextY, false);
                //Console.WriteLine("EL patternY startX: {0} startY: {1} len: {2}",cp.StartX, cp.StartY, cp.Length);
                _verticalPatterns.Add(cp);
            }
        }

        BindAdjacentPatterns();
        //set instantiation count
        int patternCount = GetPatternCount();

        for (int i = 0; i < patternCount; i++)
        {
            var pattern = GetCrossPattern(i);
            pattern.InstantiationCount = aDict.GetWordOfLengthCount(pattern.Length);
        }
    }