Ejemplo n.º 1
0
        public void PartTest()
        {
            Ontology.EraseConcepts();
            ParseAndExecute("a cat is a kind of person",
                            "a persian is a kind of cat",
                            "a tabby is a kind of cat",
                            "a siamese is a kind of cat",
                            "a cat can be haughty",
                            "a cat can be cuddly",
                            "a cat can be crazy",
                            "a persian can be matted",
                            "red, blue, and green are kinds of color",
                            "a cat has a color called its favorite color");
            var cat   = (CommonNoun)Noun.Find("cat");
            var color = (CommonNoun)Noun.Find("color");
            var g     = new Generator(cat);

            for (var n = 0; n < 100; n++)
            {
                var i = g.Solve();
                Assert.IsTrue(i.IsA(i.Individuals[0], cat));
                Assert.IsTrue(i.IsA(i.Individuals[0], "persian") ||
                              i.IsA(i.Individuals[0], "tabby") ||
                              i.IsA(i.Individuals[0], "siamese"));
                Assert.AreEqual(i.Individuals[0], i.Individuals[1].Container);
                Assert.IsTrue(i.IsA(i.Individuals[1], color));
                Console.WriteLine(i.Model.Model);
                Console.WriteLine(i.Description(i.Individuals[0]));
            }
        }
Ejemplo n.º 2
0
        public void ProperNameTest()
        {
            Ontology.EraseConcepts();
            ParseAndExecute("a cat is a kind of person",
                            "a persian is a kind of cat",
                            "a tabby is a kind of cat",
                            "a siamese is a kind of cat",
                            "a cat can be haughty",
                            "a cat can be cuddly",
                            "a cat can be crazy",
                            "a persian can be matted",
                            "thaumaturgy is a form of magic",
                            "necromancy is a form of magic",
                            "a magic user must practice one form of magic");
            var cat         = (CommonNoun)Noun.Find("cat");
            var magicUser   = (CommonNoun)Noun.Find("magic", "user");
            var thaumaturgy = Individual.AllPermanentIndividuals["thaumaturgy"];
            var necromancy  = Individual.AllPermanentIndividuals["necromancy"];
            var g           = new Generator(cat, magicUser);

            for (var n = 0; n < 100; n++)
            {
                var i = g.Solve();
                Assert.IsTrue(i.Holds("practices", i.Individuals[0], thaumaturgy) ||
                              i.Holds("practices", i.Individuals[0], necromancy));
                Console.WriteLine(i.Model.Model);
                Console.WriteLine(i.Description(i.Individuals[0]));
            }
        }
Ejemplo n.º 3
0
 public void InterningNounTest()
 {
     Ontology.EraseConcepts();
     ParseAndExecute("Tabby, Persian, and Maine Coon are kinds of cat");
     Assert.IsNotNull(Noun.Find("Persian"));
     Assert.IsNotNull(Noun.Find("Persians"));
 }
Ejemplo n.º 4
0
        public void  CompoundNounTest()
        {
            Ontology.EraseConcepts();
            ParseAndExecute("a cat is a kind of person",
                            "a persian is a kind of cat",
                            "a tabby is a kind of cat",
                            "a siamese is a kind of cat",
                            "a cat can be haughty",
                            "a cat can be cuddly",
                            "a cat can be crazy",
                            "a persian can be matted",
                            "thaumaturge and necromancer are kinds of magic user");
            var cat       = (CommonNoun)Noun.Find("cat");
            var magicUser = (CommonNoun)Noun.Find("magic", "user");
            var g         = new Generator(cat, magicUser);

            for (var n = 0; n < 100; n++)
            {
                var i = g.Solve();
                Assert.IsTrue(i.IsA(i.Individuals[0], cat));
                Assert.IsTrue(i.IsA(i.Individuals[0], "persian") ||
                              i.IsA(i.Individuals[0], "tabby") ||
                              i.IsA(i.Individuals[0], "siamese"));
                Console.WriteLine(i.Model.Model);
                Console.WriteLine(i.Description(i.Individuals[0]));
            }
        }
Ejemplo n.º 5
0
        public void BeRelatedToTest()
        {
            Ontology.EraseConcepts();
            ParseAndExecute("A character can be related to one other character");
            var love = Verb.Find("be", "related", "to");

            Assert.IsNotNull(love);
        }
Ejemplo n.º 6
0
        public void OptionalAlternativeSetTest()
        {
            Ontology.EraseConcepts();
            ParseAndExecute("cats can be big or small");
            var cat = CommonNoun.Find("cat");

            Assert.AreEqual(1, cat.AlternativeSets.Count);
        }
Ejemplo n.º 7
0
        public void RequiredAlternativeSetTest()
        {
            Ontology.EraseConcepts();
            ParseAndExecute("cats are long haired or short haired");
            var cat = CommonNoun.Find("cat");

            Assert.AreEqual(1, cat.AlternativeSets.Count);
        }
Ejemplo n.º 8
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.º 9
0
        public void CatTest()
        {
            Ontology.EraseConcepts();
            Parser.ParseAndExecute("a cat is a kind of person",
                                   "a persian is a kind of cat",
                                   "a tabby is a kind of cat",
                                   "a siamese is a kind of cat",
                                   "a cat can be haughty",
                                   "a cat can be cuddly",
                                   "a cat can be crazy",
                                   "a persian can be matted");
            var cat = Ontology.CommonNoun("cat");
            var g   = new Generator(cat);

            for (var n = 0; n < 100; n++)
            {
                var i = g.Generate();
                Assert.IsTrue(i.IsA(i.Individuals[0], cat));
                Assert.IsTrue(i.IsA(i.Individuals[0], "persian") ||
                              i.IsA(i.Individuals[0], "tabby") ||
                              i.IsA(i.Individuals[0], "siamese"));
                Console.WriteLine(i.Model.Model);
                Console.WriteLine(i.Description(i.Individuals[0]));
            }
        }
Ejemplo n.º 10
0
        public void ParseAntiReflexiveTest()
        {
            Ontology.EraseConcepts();
            ParseAndExecute("Cats are a kind of person.",
                            "Cats cannot love themselves");
            var love = Verb.Find("love");

            Assert.IsNotNull(love);
        }
Ejemplo n.º 11
0
        public void ImpliedAdjectiveTest()
        {
            Ontology.EraseConcepts();
            ParseAndExecute("cats are fuzzy");
            var cat   = CommonNoun.Find("cat");
            var fuzzy = Adjective.Find("fuzzy");
            var g     = new Generator(cat);

            for (var n = 0; n < 100; n++)
            {
                var i = g.Solve();
                Assert.IsTrue(i.IsA(i.Individuals[0], fuzzy));
            }
        }
Ejemplo n.º 12
0
        public void Symmetric()
        {
            Ontology.EraseConcepts();
            ParseAndExecute("people can love each other");
            var v = Verb.Find("loves");
            var g = new Generator(CommonNoun.Find("person"), new MonadicConceptLiteral[0], 10);

            foreach (var i1 in g.Individuals)
            {
                foreach (var i2 in g.Individuals)
                {
                    Assert.IsTrue(ReferenceEquals(g.Holds(v, i1, i2), g.Holds(v, i2, i1)));
                }
            }
        }
Ejemplo n.º 13
0
        public void Reflexive()
        {
            Ontology.EraseConcepts();
            ParseAndExecute("people must love themselves");
            var v = Verb.Find("loves");
            var g = new Generator(CommonNoun.Find("person"), new MonadicConceptLiteral[0], 10);

            for (int n = 0; n < 100; n++)
            {
                var s = g.Solve();
                foreach (var i in s.Individuals)
                {
                    Assert.IsTrue(s.Holds(v, i, i));
                }
            }
        }
Ejemplo n.º 14
0
        public void NumericPropertyTest()
        {
            Ontology.EraseConcepts();
            ParseAndExecute("cats have an age between 1 and 20");
            var cat = CommonNoun.Find("cat");
            var age = cat.Properties[0];
            var g   = new Generator(cat);

            for (var n = 0; n < 100; n++)
            {
                var i        = g.Solve();
                var ageVar   = i.Individuals[0].Properties[age];
                var ageValue = (float)i.Model[ageVar];
                Assert.IsTrue(ageValue >= 1 && ageValue <= 20);
            }
        }
Ejemplo n.º 15
0
        public void TotalFunction()
        {
            Ontology.EraseConcepts();
            ParseAndExecute("people must love one person");
            var v = Verb.Find("loves");
            var g = new Generator(CommonNoun.Find("person"), new MonadicConceptLiteral[0], 10);

            for (var n = 0; n < 100; n++)
            {
                var s = g.Solve();
                foreach (var i in s.Individuals)
                {
                    var count = s.Individuals.Count(i2 => s.Holds(v, i, i2));
                    Assert.IsTrue(count == 1);
                }
            }
        }
Ejemplo n.º 16
0
        public void PartialFunction()
        {
            Ontology.EraseConcepts();
            ParseAndExecute("people can love one person");
            var  v           = Verb.Find("loves");
            var  g           = new Generator(CommonNoun.Find("person"), new MonadicConceptLiteral[0], 3);
            bool sawNonTotal = false;

            for (var n = 0; n < 300; n++)
            {
                var s = g.Solve();
                foreach (var i in s.Individuals)
                {
                    var count = s.Individuals.Count(i2 => s.Holds(v, i, i2));
                    Assert.IsFalse(count > 1);
                    sawNonTotal |= count == 0;
                }
            }
            Assert.IsTrue(sawNonTotal);
        }
Ejemplo n.º 17
0
 public void PluralDeclarationTest()
 {
     Ontology.EraseConcepts();
     ParseAndExecute("the plural of person is people");
     Assert.AreEqual("people", ((CommonNoun)Noun.Find("person")).PluralForm[0]);
 }
Ejemplo n.º 18
0
 public void APListTest()
 {
     Ontology.EraseConcepts();
     ParseAndExecute("Cats can be white, black, or ginger");
 }