예제 #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)
            });
        }
예제 #2
0
 public Entity(string name, bool generateRandomSequence = true)
 {
     Name     = name;
     Sequence = generateRandomSequence
 ? SequenceProcessor.PopulateBitArray(Settings.SequenceLength)
 : new BitArray(Settings.SequenceLength);
 }
예제 #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);
        }
예제 #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);
        }
예제 #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);
        }
예제 #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());
        }
예제 #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);
        }
예제 #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)
            });
        }
예제 #9
0
 private void ReadFullExpression(SequenceProcessor sequenceProcessor)
 {
     while (sequenceProcessor.ReadNextSequence().Length > 0)
     {
     }
 }