Beispiel #1
0
        public Link StrengthenLink(Entity entity, List <Pattern> currentPatterns, LinkSeverity severity = LinkSeverity.Weak)
        {
            var strongestPattern = currentPatterns.OrderByDescending(item => item.Length).FirstOrDefault();

            if (strongestPattern == null)
            {
                return(CreateLink(entity, severity));
            }

            var randomGenerator = new Random(DateTime.Now.Millisecond);
            var linkSize        = GetLinkSize(randomGenerator, severity, LinkApplyType.Strengthen);
            var startIndex      = strongestPattern.EndIndex + linkSize <= Settings.SequenceLength - 1 ? strongestPattern.EndIndex + 1 : strongestPattern.StartIndex - linkSize;

            if (startIndex >= 0 && startIndex < Settings.SequenceLength - linkSize - 1)
            {
                for (var i = startIndex; i < startIndex + linkSize; i++)
                {
                    Sequence.Set(i, entity.Sequence.Get(i));
                }
            }

            return(new Link {
                Left = this,
                Right = entity,
                Pattern = SequenceProcessor.CalculateSimillarPatterns(this.Sequence, entity.Sequence, Settings.MinimumPatternLength)
            });
        }
Beispiel #2
0
 public Entity(string name, bool generateRandomSequence = true)
 {
     Name     = name;
     Sequence = generateRandomSequence
 ? SequenceProcessor.PopulateBitArray(Settings.SequenceLength)
 : new BitArray(Settings.SequenceLength);
 }
Beispiel #3
0
        public void Init_ValidInput_CheckState()
        {
            var sequenceProcessor = new SequenceProcessor("123abc");

            Assert.Equal("123abc", sequenceProcessor.Sequence);
            Assert.Equal(0, sequenceProcessor.CurrentIndex);
            Assert.True(sequenceProcessor.BracketsValid);
        }
Beispiel #4
0
        private static void BuildDocumentation(string content, List <string> matches)
        {
            ICollection <PgSequence> sequences = SequenceProcessor.GetSequences(Program.SchemaPattern, Program.xSchemaPattern);

            content = content.Replace("[DBName]", Program.Database.ToUpperInvariant());
            content = Parsers.SequenceParser.Parse(content, matches, sequences);

            FileHelper.WriteFile(content, OutputPath);
        }
Beispiel #5
0
        private static void BuildDocumentation(string content, List <string> matches, string schemaName)
        {
            PGSchema schema = SchemaProcessor.GetSchema(schemaName);

            content = content.Replace("[DBName]", Program.Database.ToUpperInvariant());
            content = content.Replace("[SchemaName]", schemaName);

            content = SequenceParser.Parse(content, matches, SequenceProcessor.GetSequences(schemaName));
            content = TableParser.Parse(content, matches, schema.Tables);
            content = ViewParser.Parse(content, matches, schema.Views);
            content = SequenceParser.Parse(content, matches, schema.Sequences);
            content = MaterializedViewParser.Parse(content, matches, schema.MaterializedViews);
            content = FunctionParser.Parse(content, matches, schema.Functions);
            content = FunctionParser.ParseTriggers(content, matches, schema.TriggerFunctions);
            content = TypeParser.Parse(content, matches, schema.Types);

            foreach (PgTable table in schema.Tables)
            {
                Console.WriteLine("Generating documentation for table \"{0}\".", table.Name);
                TableRunner.Run(table);
            }


            foreach (PgFunction function in schema.Functions)
            {
                Console.WriteLine("Generating documentation for function \"{0}\".", function.Name);
                FunctionRunner.Run(function);
            }

            foreach (PgFunction function in schema.TriggerFunctions)
            {
                Console.WriteLine("Generating documentation for trigger function \"{0}\".", function.Name);
                FunctionRunner.Run(function);
            }

            foreach (PgMaterializedView materializedView in schema.MaterializedViews)
            {
                Console.WriteLine("Generating documentation for materialized view \"{0}\".", materializedView.Name);
                MaterializedViewRunner.Run(materializedView);
            }

            foreach (PgView view in schema.Views)
            {
                Console.WriteLine("Generating documentation for view \"{0}\".", view.Name);
                ViewRunner.Run(view);
            }
            foreach (PgType type in schema.Types)
            {
                Console.WriteLine("Generating documentation for type \"{0}\".", type.Name);
                TypeRunner.Run(type);
            }

            string targetPath = System.IO.Path.Combine(OutputPath, schemaName + ".html");

            FileHelper.WriteFile(content, targetPath);
        }
Beispiel #6
0
        public void ReadNextSequence_ValidInput_String()
        {
            var sequenceProcessor = new SequenceProcessor("   123   + b +(  44");

            Assert.Equal("123", sequenceProcessor.ReadNextSequence());
            Assert.Equal("+", sequenceProcessor.ReadNextSequence());
            Assert.Equal("b", sequenceProcessor.ReadNextSequence());
            Assert.Equal("+", sequenceProcessor.ReadNextSequence());
            Assert.Equal("(", sequenceProcessor.ReadNextSequence());
            Assert.Equal("44", sequenceProcessor.ReadNextSequence());
        }
Beispiel #7
0
        public void Reset_CallReset_StateReset()
        {
            var sequenceProcessor = new SequenceProcessor("(123456");

            sequenceProcessor.ReadNextSequence();
            sequenceProcessor.ReadNextSequence();

            sequenceProcessor.Reset();

            Assert.True(sequenceProcessor.BracketsValid);
            Assert.Equal(0, sequenceProcessor.CurrentIndex);
        }
Beispiel #8
0
        public Link CreateLink(Entity to, LinkSeverity severity = LinkSeverity.Weak)
        {
            if (!Name.Equals(to.Name, StringComparison.InvariantCultureIgnoreCase))
            {
                var randomGenerator = new Random(DateTime.Now.Millisecond);
                var linkSize        = GetLinkSize(randomGenerator, severity);
                var startIndex      = randomGenerator.Next(Settings.SequenceLength - linkSize - 1);

                for (var i = startIndex; i < startIndex + linkSize; i++)
                {
                    Sequence.Set(i, to.Sequence.Get(i));
                }
            }

            return(new Link {
                Left = this,
                Right = to,
                Pattern = SequenceProcessor.CalculateSimillarPatterns(this.Sequence, to.Sequence, Settings.MinimumPatternLength)
            });
        }
Beispiel #9
0
 private void ReadFullExpression(SequenceProcessor sequenceProcessor)
 {
     while (sequenceProcessor.ReadNextSequence().Length > 0)
     {
     }
 }