Ejemplo n.º 1
0
        public void VerbQuantificationTest()
        {
            var o = new Ontology(nameof(VerbQuantificationTest));

            o.ParseAndExecute(
                "employee and employer are kinds of person",
                "an employee must work for one employer",
                "an employer must be worked for by at least two employees");
            var g        = o.CommonNoun("person").MakeGenerator(10);
            var employee = o.CommonNoun("employee");
            var employer = o.CommonNoun("employer");
            var workFor  = o.Verb("work", "for");

            for (var count = 0; count < 100; count++)
            {
                var invention = g.Generate();
                foreach (var person in invention.PossibleIndividuals)
                {
                    if (person.IsA(employee))
                    {
                        Assert.AreEqual(1, invention.PossibleIndividuals.Count(p => person.RelatesTo(p, workFor)));
                    }
                    else if (person.IsA(employer))
                    {
                        Assert.IsTrue(2 <= invention.PossibleIndividuals.Count(p => p.RelatesTo(person, workFor)));
                    }
                    else
                    {
                        throw new Exception("Object in model that is neither an employee or employer");
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void UnnamedPartTest()
        {
            var o = new Ontology("UnnamedPartTest");

            o.Parser.ParseAndExecute("a cat is a kind of person",
                                     "a cat has a color");
            var cat   = o.CommonNoun("cat");
            var color = o.CommonNoun("color");
            var i     = o.Generator(cat).Generate();

            Assert.AreEqual(1, cat.Parts.Count);
            Assert.AreEqual("color", cat.Parts[0].StandardName.Untokenize());
            Assert.IsTrue(i.IsA(i.Individuals[0], cat));
            Assert.IsTrue(i.IsA(i.Individuals[1], color));
        }
Ejemplo n.º 3
0
        public void AntiReflexive()
        {
            Ontology.EraseConcepts();
            Parser.ParseAndExecute("people can love other people");
            Parser.ParseAndExecute("people cannot love themselves");
            var v = Ontology.Verb("loves");
            var g = new Generator(Ontology.CommonNoun("person"), new MonadicConceptLiteral[0], 10);

            for (int n = 0; n < 100; n++)
            {
                var s = g.Generate();
                foreach (var i in s.Individuals)
                {
                    Assert.IsFalse(s.Holds(v, i, i));
                }
            }
        }
Ejemplo n.º 4
0
        public void MonsterTest()
        {
            var o = new Ontology(nameof(MonsterTest));

            foreach (var decl in MonsterSource.Replace("\r", "").Split(new [] { '\n' }, StringSplitOptions.RemoveEmptyEntries))
            {
                o.ParseAndExecute(decl);
            }
            var g = o.CommonNoun("monster").MakeGenerator(20);

            for (var n = 0; n < 100; n++)
            {
                g.Generate();
            }
            Console.WriteLine(g.Problem.PerformanceStatistics);
            Console.WriteLine($"Average flips per solve: {g.Problem.SolveFlips.Average}");
        }
Ejemplo n.º 5
0
        public void OverlappingAdjectivesTest()
        {
            var o = new Ontology(nameof(OverlappingAdjectivesTest));

            o.ParseAndExecute("x, y, and z are kinds of thing",
                              "a x is between 4 and 5 of b, c, d, e, f, or g",
                              "a y is between 1 and 2 of b, c, d, e, f, or g",
                              "a z is any 3 of b, c, d, e, f, or g");
            var adjectives = new[] { "b", "c", "d", "e", "f", "g" }.Select(a => o.Adjective(a)).ToArray();
            var g = o.CommonNoun("thing").MakeGenerator();

            for (var i = 0; i < 100; i++)
            {
                var thing = g.Generate().PossibleIndividuals[0];
                var count = adjectives.Count(a => thing.IsA(a));
                Assert.IsTrue(
                    (thing.IsA("x") && count >= 4 && count <= 5) ||
                    (thing.IsA("y") && count >= 1 && count <= 2) ||
                    (thing.IsA("z") && count == 3)
                    );
            }
        }
Ejemplo n.º 6
0
        public void IdentifiedAsTest()
        {
            var o = new Ontology(nameof(IdentifiedAsTest));

            o.ParseAndExecute("esoteric crops, dangerous crops, and psychoactive crops are kinds of plant",
                              "wolf's bane, and foo are kinds of esoteric crops",
                              "triffids, poison ivy, and venus flytrap are kinds of dangerous crops",
                              "dartura, wormwood, peyote, ayahuasca, tobacco, and chocolate are kinds of psychoactive crops",
                              "a plant is described as \"[Modifiers] [Noun]\"",
                              "vodka, gin, bourbon, and absinthe are kinds of alcohol base",
                              "an alcohol base is described as \"[Modifiers] [Noun]\"",
                              "an infusion has an alcohol base",
                              "an infusion has a plant",
                              "an infusion is described as \"[plant]-infused [alcohol]\"");
            var g = o.CommonNoun("infusion").MakeGenerator();

            for (var i = 0; i < 100; i++)
            {
                var invention = g.Generate();
                invention.PossibleIndividuals[0].Description();
            }
        }
Ejemplo n.º 7
0
 public void PluralDeclarationTest()
 {
     Ontology.EraseConcepts();
     Parser.ParseAndExecute("the plural of person is people");
     Assert.AreEqual("people", Ontology.CommonNoun("person").PluralForm[0]);
 }