Esempio n. 1
0
        public void TestAny02()
        {
            IEnumerable <string> actual   = Quantifiers.Any02();
            IEnumerable <string> expected = new string[] { "Condiments", "Meat/Poultry", "Dairy Products" };

            CollectionAssert.AreEqual(actual.ToList(), expected.ToList(), "You failed!");
        }
Esempio n. 2
0
        public void TestAll01()
        {
            bool?actual   = Quantifiers.All01();
            bool?expected = true;

            Assert.AreEqual(actual, expected, "You failed!");
        }
Esempio n. 3
0
        // others ------------
        private List <List <LinguisticVariable> > GetQws()
        {
            var qualifiersToUse = DecideWhichItemsUse(QualifiersLabel)
                ? _qualifiers
                : GetQualifiersFromComboBoxes();

            var summarizersToUse = DecideWhichItemsUse(SummarizersLabel)
                ? _summarizers
                : GetSummarizersFromComboBoxes();

            List <LinguisticVariable> quantifiersToUse;

            if (DecideWhichItemsUse(QuantifierLabel))
            {
                quantifiersToUse = _quantifiers;
            }
            else if (TypeComboBox.SelectedItem.ToString().Contains("Two") || qualifiersToUse != null)
            {
                quantifiersToUse = Quantifiers.GetRelativeQuantifiers();
            }
            else
            {
                quantifiersToUse = Quantifiers.GetAllQuantifiers();
            }



            return(new List <List <LinguisticVariable> > {
                quantifiersToUse, qualifiersToUse, summarizersToUse
            });
        }
Esempio n. 4
0
        public void TestAll02()
        {
            IEnumerable <string> actual   = Quantifiers.All02();
            IEnumerable <string> expected = new string[] { "Beverages", "Produce", "Seafood", "Confections", "Grains/Cereals" };

            CollectionAssert.AreEqual(actual.ToList(), expected.ToList(), "You failed!");
        }
        internal string FindQuantifierValue(string quantifierKey)
        {
            if (Quantifiers.ContainsKey(quantifierKey))
            {
                return(Quantifiers[quantifierKey]);
            }

            return(null);
        }
Esempio n. 6
0
        public void Backreference_Number()
        {
            var regex = RegularExpression.Of(
                CaptureGroup.Of(Quantifiers.OneOrMore(Literal.For("a"))),
                Quantifiers.ZeroOrMore(Literal.For("b")),
                Backreference.For(1)
                ).ToRegex();

            Assert.AreEqual(@"(a+)b*\1", regex.ToString());
        }
 private void OnRemove()
 {
     if (QuantifierSelected == null)
     {
         MessageBox.Show("Please choose summarizer");
         return;
     }
     Quantifiers.Remove(QuantifierSelected);
     Draw();
 }
 public void AddToCollection()
 {
     if (FunctionSelectionVm.Function == null)
     {
         MessageBox.Show("Please setup function in configurator!");
         return;
     }
     Quantifiers.Add(new Quantifier(LabelNameTB, new FuzzySet(FunctionSelectionVm.Function)));
     Draw();
 }
Esempio n. 9
0
        public void Alternation_ByCapture()
        {
            var regex = RegularExpression.Of(
                CaptureGroup.Of(new CaptureGroupOptions()
            {
                Name = "A"
            }, Quantifiers.OneOrMore(Literal.For("A"))),
                ConditionalAlternation.For(Literal.For("A"), Literal.For("Abc"), Literal.For("Xyz"))
                ).ToRegex();

            Assert.AreEqual("(?<A>A+)(?(A)Abc|Xyz)", regex.ToString());
        }
Esempio n. 10
0
        public void Backreference_Name_WithQuotes()
        {
            var regex = RegularExpression.Of(
                CaptureGroup.Of(new CaptureGroupOptions()
            {
                Name = "a", UseQuotes = true
            }, Quantifiers.OneOrMore(Literal.For("a"))),
                Quantifiers.ZeroOrMore(Literal.For("b")),
                Backreference.For("a", true)
                ).ToRegex();

            Assert.AreEqual(@"(?'a'a+)b*\k'a'", regex.ToString());
        }
Esempio n. 11
0
        public void Backreference_Name()
        {
            var regex = RegularExpression.Of(
                CaptureGroup.Of(new CaptureGroupOptions()
            {
                Name = "a"
            }, Quantifiers.OneOrMore(Literal.For("a"))),
                Quantifiers.ZeroOrMore(Literal.For("b")),
                Backreference.For("a")
                ).ToRegex();

            Assert.AreEqual(@"(?<a>a+)b*\k<a>", regex.ToString());
        }
Esempio n. 12
0
        public void PredicateConversionTest()
        {
            var coll = new object[] { 1, 2 };
            var pred = Predicates.ElementTypePredicate <int>();

            Assert.IsTrue(Quantifiers.All(pred)(coll));
            var pred2 = pred.ToPredicate();

            Assert.IsTrue(Quantifiers.All(pred2)(coll));
            var pred3 = pred2.ToElementTypePredicate <double>();

            Assert.IsFalse(Quantifiers.All(pred3)(coll));
            var pred3b = pred2.ToElementTypePredicate <int>();

            Assert.IsTrue(Quantifiers.All(pred3b)(coll));
        }
Esempio n. 13
0
        public void MPCQuantityTest()
        {
            var coll  = new ManyPredicateCollection();
            var pred  = Predicates.ElementTypePredicate <int>();
            var quant = Quantifiers.Count(pred, 2);

            Assert.ThrowsException <InvalidPredicateException>(() => coll.AddQuant(quant));
            coll.Add(1);
            Assert.ThrowsException <InvalidPredicateException>(() => coll.AddQuant(quant));
            coll.Add(2);
            coll.AddQuant(quant);
            Assert.IsTrue(new int[] { 1, 2 }.SequenceEqual(coll.Get(pred)));
            coll.Add(1, 2); // Repeated elements, ok
            Assert.ThrowsException <InvalidElementException>(() => coll.Add(3));
            Assert.IsTrue(new int[] { 1, 2 }.SequenceEqual(coll.Get(pred)));
        }
Esempio n. 14
0
        public void MPCPropertyTest1()
        {
            var coll = new ManyPredicateCollection();

            var typePred  = Predicates.ElementTypePredicate <CustomType1 <int> >();
            var typeQuant = Quantifiers.All(typePred);

            // Two equivalent predicates. The second one is converted to the first one.
            var propPred1 = new Predicate((object elem) => !(elem is CustomType1 <int>) ||
                                          ((CustomType1 <int>)elem).Value == 2);
            var propQuant1 = Quantifiers.All(propPred1);

            var propPred1Typed = new ForTypePredicate <CustomType1 <int> >((CustomType1 <int> elem) => elem.Value == 2)
                                 .ToPredicate();
            var propQuant1Typed = Quantifiers.All(propPred1Typed);

            var propPred2  = new Predicate((object elem) => ((CustomType1 <int>)elem).Prop);
            var propQuant2 = Quantifiers.All(propPred2);

            coll.AddQuant(typeQuant);
            coll.AddQuant(propQuant1);
            coll.AddQuant(propQuant2);

            Assert.ThrowsException <InvalidElementException>(() => coll.Add(1));
            Assert.ThrowsException <InvalidElementException>(() => coll.Add(new CustomType1 <int>()
            {
                Value = 2, Prop = false
            }));
            Assert.ThrowsException <InvalidElementException>(() => coll.Add(new CustomType1 <int>()
            {
                Value = 1, Prop = true
            }));
            coll.Add(new CustomType1 <int>()
            {
                Value = 2, Prop = true
            });

            // Typed get and predicate
            Assert.IsTrue(new CustomType1 <int>[] { new CustomType1 <int>()
                                                    {
                                                        Value = 2, Prop = true
                                                    } }
                          .SequenceEqual(coll.Get(typePred)));
        }
 private void ExtractQuality()
 {
     if (Quantifiers.ContainsKey(QUALITY_KEY))
     {
         decimal qualityAsDec;
         if (decimal.TryParse(Quantifiers[QUALITY_KEY], out qualityAsDec))
         {
             Quality = Math.Min(Math.Max(qualityAsDec, 0), 1);
         }
         else
         {
             Quality = 0;
         }
     }
     else
     {
         Quality = 1;
     }
 }
Esempio n. 16
0
        public void MPCBasicTest()
        {
            var coll = new ManyPredicateCollection();

            // The element predicate
            var pred = Predicates.ElementTypePredicate <int>();

            // The quantifier
            var quant = Quantifiers.All(pred);

            coll.Add(1);
            coll.AddQuant(quant);
            coll.AddQuant(quant); // Ignored

            // Invalid element
            Assert.ThrowsException <InvalidElementException>(() => coll.Add("a"));

            Assert.IsTrue(new int[] { 1 }.SequenceEqual(coll.Get(pred)));
        }
Esempio n. 17
0
            private static bool IsFunctionName(string tok)
            {
                char begin        = tok[0];
                bool isIdentifier = char.IsLetter(begin) || begin.CompareTo('$') == 0 || begin.CompareTo('_') == 0 || '"' == begin;

                return(isIdentifier && !Formatter.Logical.Contains(tok) && !EndClauses.Contains(tok) && !Quantifiers.Contains(tok) &&
                       !Dml.Contains(tok) && !Formatter.Misc.Contains(tok));
            }
Esempio n. 18
0
 public QuantifiersTests()
 {
     _quantifiers = new Quantifiers();
 }
Esempio n. 19
0
        public void UrlScheme()
        {
            var expression = RegularExpression.Of(
                Anchors.Carot,

                // scheme - (?:([A-Za-z]+):)?
                Quantifiers.ZeroOrOne(
                    NonCaptureGroup.Of(
                        CaptureGroup.Of(
                            Quantifiers.OneOrMore(
                                CharacterGroup.Of(
                                    Range.For(Literal.For('A'), Literal.For('Z')),
                                    Range.For(Literal.For('a'), Literal.For('z'))
                                    )
                                )
                            ),
                        Literal.For(":")
                        )
                    ),

                // slash - (/{0,3})
                CaptureGroup.Of(
                    Quantifiers.Between(Literal.For("/"), 0, 3)
                    ),

                // host - ([0-9.\-A-Za-z]+)
                CaptureGroup.Of(
                    Quantifiers.OneOrMore(
                        CharacterGroup.Of(
                            Range.For(Literal.For('0'), Literal.For('9')),
                            Literal.For("."),
                            Literal.For("-"),
                            Range.For(Literal.For('A'), Literal.For('Z')),
                            Range.For(Literal.For('a'), Literal.For('z'))
                            )
                        )
                    ),

                // port - (?::(\d+))?
                Quantifiers.ZeroOrOne(
                    NonCaptureGroup.Of(
                        Literal.For(":"),
                        CaptureGroup.Of(
                            Quantifiers.OneOrMore(CharacterClasses.Digit)
                            )
                        )
                    ),

                // path - (/[^?#]*)?
                Quantifiers.ZeroOrOne(
                    CaptureGroup.Of(
                        Literal.For("/"),
                        Quantifiers.ZeroOrMore(
                            CharacterGroup.Of(
                                new CharacterGroupOptions()
            {
                IsNegated = true
            },
                                Literal.For("?"),
                                Literal.For("#")
                                )
                            )
                        )
                    ),

                // query - (?:\?([^#]*))?
                Quantifiers.ZeroOrOne(
                    NonCaptureGroup.Of(
                        Literal.For("?"),
                        CaptureGroup.Of(
                            Quantifiers.ZeroOrMore(
                                CharacterGroup.Of(new CharacterGroupOptions()
            {
                IsNegated = true
            }, Literal.For("#"))
                                )
                            )
                        )
                    ),

                // hash - (?:#(.*))?
                Quantifiers.ZeroOrOne(
                    NonCaptureGroup.Of(
                        Literal.For("#"),
                        CaptureGroup.Of(
                            Quantifiers.ZeroOrMore(CharacterClasses.Wildcard)
                            )
                        )
                    ),

                Anchors.Dollar
                );

            var regex  = expression.ToRegex();
            var source = regex.ToString();

            const string urlRegex = @"^(?:([A-Za-z]+):)?(/{0,3})([0-9.\-A-Za-z]+)(?::(\d+))?(/[^?#]*)?(?:\?([^#]*))?(?:\#(.*))?$";

            Assert.AreEqual(urlRegex, source);
        }