Beispiel #1
0
        public void Check_if_vector_does_not_include_other_vector()
        {
            var v1 = SVVector.FromSV("[SV 1 0 0 1 0 0 3 1 0 0 1 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0]");
            var v2 = SVVector.FromSV("[SV 0 1 0 1 0 0 2 1 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0]");

            Assert.False(v1.Includes(v2));
        }
Beispiel #2
0
        public void Compares_long_equal_vectors()
        {
            var v1 = SVVector.FromSV("[SV 0 0 0 0 1 0 0 3 1 0 0 1 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 ]");
            var v2 = SVVector.FromSV("[SV 0 0 0 0 1 0 0 3 1 0 0 1 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 ]");

            Assert.Equal(0, v1.CompareTo(v2));
        }
Beispiel #3
0
        public void Compares_long_vectors_of_different_length2()
        {
            var v1 = SVVector.FromSV("[SV 0 0 0 1 0 0 3 1 0 0 1 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0]");
            var v2 = SVVector.FromSV("[SV 0 0 0 1 0 0 3 1 0 0 1 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0]");

            Assert.Equal(1, v1.CompareTo(v2));
        }
Beispiel #4
0
        public void Check_if_long_equal_vectors_are_equal()
        {
            var v1 = SVVector.FromSV("[SV 0 0 0 0 1 0 0 3 1 0 0 1 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 ]");
            var v2 = SVVector.FromSV("[SV 0 0 0 0 1 0 0 3 1 0 0 1 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 ]");

            Assert.True(v1.Equals(v2));
        }
Beispiel #5
0
        public void Create_SVVector_from_SV_string()
        {
            const string svString = "[SV 0 0 0 0 0 0 1 0 1 1 1 0 1]";
            var          vector   = SVVector.FromSV(svString);

            Assert.Equal(svString, vector.ToString());
        }
Beispiel #6
0
        public void Create_SVBlock_from_SV_string_with_equal_block()
        {
            const string fileContent = @"[ELB samples = 3 patterns = 5]
[SV 0 0 0 0 0 0 1 0 1 1 1 0 1]
DND
DDC
DAN
ANN
ADD
[ELB samples = 3 patterns = 5]
[SV 0 0 0 0 0 0 0 1 1 1 1 0 1]
CDD
DNC
DDN
DAD
AND
[ELB samples = 3 patterns = 5]
[SV 0 0 0 0 0 0 0 1 1 1 1 0 1]
CDD
DNC
DDN
DAD
AND";
            var          blocks      = new List <SVBlock>();
            const int    patterns    = 5;

            using (var reader = new StringReader(fileContent))
            {
                while (true)
                {
                    var line = reader.ReadLine();
                    if (string.IsNullOrEmpty(line))
                    {
                        break;
                    }
                    if (line.StartsWith("[SV"))
                    {
                        var svVector = SVVector.FromSV(line);
                        var words    = Enumerable.Range(0, patterns).Select(_ => reader.ReadLine());
                        var block    = SVBlock.FromSV(svVector, words);
                        blocks.Add(block);
                    }
                }
            }

            var blockList = new SVBlockList(blocks);
            var svKeys    = blockList.Keys.ToArray();

            Assert.Equal(new[]
            {
                "[SV 0 0 0 0 0 0 0 1 1 1 1 0 1]",
                "[SV 0 0 0 0 0 0 1 0 1 1 1 0 1]"
            },
                         svKeys);
        }
Beispiel #7
0
        public static IEnumerable <SVBlock> GenerateBlocks(int count = 35_500)
        {
            var rand = new Random(42);

            foreach (var i in Enumerable.Range(0, count))
            {
                var bytes = new byte[13];
                rand.NextBytes(bytes);
                var sb = new StringBuilder("SV ");
                sb.Append(string.Join(' ', bytes));
                sb.Append(']');
                var v = SVVector.FromSV(sb.ToString());
                yield return(SVBlock.FromSV(v, new string[] { "ABC" }));
            }
        }
Beispiel #8
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}");
        }
Beispiel #9
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;
            }
        }