Example #1
0
        public async Task StartAsync(CancellationToken cancellationToken)
        {
            var startedAt = DateTime.Now;

            _logger.LogInformation("NCSTaskService started");
            var allLines = await File.ReadAllLinesAsync(_filePath, cancellationToken);

            var lines = allLines.Where(t => !string.IsNullOrEmpty(t) && !t.StartsWith("#")).ToArray();

            if (lines.Length < 2)
            {
                throw new InvalidOperationException($"Too few lines in the file '{_filePath}");
            }

            var blockTree = new SVBlockTree();
            int index     = 2;
            int count     = 0;

            while (index < lines.Length)
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    return;
                }

                _logger.LogDebug($"ELB: {lines[index]}");
                var elbLine = new ELBLine(lines[index]);                 // [ELB samples = 3 patterns = 5]

                _logger.LogDebug($"SV: {lines[index + 1]}");
                var vector = SVVector.FromSV(lines[index + 1]);                 // [SV 0 0 0 0 0 0 0 1 1 1 1 0 1]

                var words = Enumerable.Range(index + 2, elbLine.Patterns).Select(i => lines[i]);
                _logger.LogDebug($"Words ({elbLine.Patterns}): {string.Join(' ', words)}");

                var block = SVBlock.FromSV(vector, words);
                blockTree = blockTree.Merge(new SVBlockTree(block));
                count++;
                index += elbLine.Patterns + 2;
            }

            var time = (DateTime.Now - startedAt).TotalSeconds;

            _logger.LogInformation(string.Join(Environment.NewLine, blockTree.Children.Select(t => t.Block)));
            _logger.LogInformation($"{blockTree.Count} blocks from total {count} found for total time {time}");
        }
Example #2
0
        private static IEnumerable <SVBlock> ReadLines(string file)
        {
            var allLines = file.Split(Environment.NewLine);
            var lines    = allLines.Where(t => !string.IsNullOrEmpty(t) && !t.StartsWith("#")).ToArray();
            var index    = 2;

            while (index < lines.Length)
            {
                var elbLine = new ELBLine(lines[index]);                 // [ELB samples = 3 patterns = 5]

                var vector = SVVector.FromSV(lines[index + 1]);          // [SV 0 0 0 0 0 0 0 1 1 1 1 0 1]

                var words = Enumerable.Range(index + 2, elbLine.Patterns).Select(i => lines[i]);

                var block = SVBlock.FromSV(vector, words);
                yield return(block);

                index += elbLine.Patterns + 2;
            }
        }