Beispiel #1
0
        public void SVBlockTree()
        {
            var tree = new SVBlockTree();

            foreach (var block in TestData.GenerateBlocks())
            {
                tree = tree.Merge(new SVBlockTree(block));
            }
        }
Beispiel #2
0
        private static SVBlockTree CreateTree(string file)
        {
            if (file is null)
            {
                throw new ArgumentNullException(nameof(file));
            }

            var tree = new SVBlockTree();

            foreach (var block in ReadLines(file))
            {
                tree = tree.Merge(new SVBlockTree(block));
            }

            return(tree);
        }
Beispiel #3
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}");
        }