Example #1
0
        public List <string> missingInMt(string proposalMt)
        {
            List <Dictionary <string, string> > bingingsList = new List <Dictionary <string, string> >();
            // Find Desired List
            string        reqQuery = "requires(NEED)";
            List <string> needList = new List <string>();

            prologEngine.askQuery(reqQuery, proposalMt, out bingingsList);
            foreach (Dictionary <string, string> bindings in bingingsList)
            {
                foreach (string k in bindings.Keys)
                {
                    if (k == "NEED")
                    {
                        if (!needList.Contains(bindings[k]))
                        {
                            needList.Add(bindings[k]);
                        }
                    }
                }
            }
            if (needList.Count == 0)
            {
                return(new List <string> ());
            }
            // Find out what is missing
            List <string> missingList = new List <string>();

            foreach (string need in needList)
            {
                if (isPrologish(need))
                {
                    string needQuery     = need.Replace('"', ' ');
                    bool   needSatisfied = prologEngine.isTrueIn(needQuery, proposalMt);
                    if (!needSatisfied)
                    {
                        if (!missingList.Contains(need))
                        {
                            missingList.Add(need);
                        }
                    }
                }
                else
                {
                    string needQuery     = String.Format("provides({0})", need);
                    bool   needSatisfied = prologEngine.isTrueIn(needQuery, proposalMt);
                    if (!needSatisfied)
                    {
                        if (!missingList.Contains(need))
                        {
                            missingList.Add(need);
                        }
                    }
                }
            }
            return(missingList);
        }
Example #2
0
        public static void RunAllTests(SIProlog testIt)
        {
            if (runningTests != null)
            {
                SIProlog.Warn("Already started tests");
                return;
            }
            runningTests = testIt;
            prologEngine = testIt;
            //testProlog4();
            testPrologBuiltins();
            //testRDFServer();
            testCema();
            testSat();
            //return;
            testProlog1();
            testProlog2();
            testKBload();
            testProlog3();
            testPrologBuiltins();
            prologEngine.mtest();
            if (SIProlog.RdfDeveloperSanityChecks > 2)
            {
                prologEngine.askQuery("triple(SUBJECT,PRED,OBJ)", "testRDF");
                if (prologEngine.HasKBNamed("dbpediaRdfMemory"))
                {
                    prologEngine.askQuery("triple(SUBJECT,PRED,OBJ)", "dbpediaRdfMemory");
                }
            }
            testProlog4();
            //p1();
            p2();
            p3();

            ourFilter.defMeanParticle();
            //ourFilter.dump();
            Console.WriteLine("meanP raw:{0}", ourFilter.meanParticle.ToString());
            ourFilter.meanParticle.normalize(ourFilter.constraintSet);
            Console.WriteLine("meanP norm:{0}", ourFilter.meanParticle.ToString());
            Console.WriteLine("done");
        }
Example #3
0
        public double getModuleCost(string moduleMt)
        {
            // be pessimistic on the module cost
            // if no cost found then assume a step of +1
            // all costs should be positive and found in the module mt

            List <Dictionary <string, string> > bingingsList = new List <Dictionary <string, string> >();
            string costQuery = "cost(COST)";

            prologEngine.askQuery(costQuery, moduleMt, out bingingsList);
            double worstCost = -1;

            foreach (Dictionary <string, string> bindings in bingingsList)
            {
                foreach (string k in bindings.Keys)
                {
                    if (k == "COST")
                    {
                        double newCost = double.Parse(bindings[k].Trim());
                        if (newCost > worstCost)
                        {
                            worstCost = newCost;
                        }
                    }
                }
            }
            if (worstCost == -1)
            {
                worstCost = 1;
            }
            return(worstCost);
        }
        private void load()
        {
            this.TableName = "samples";
            string[] columns;
            string   query = "";
            Dictionary <string, int>    IDTable        = new Dictionary <string, int> ();
            Dictionary <string, int>    AttributeTable = new Dictionary <string, int>();
            Dictionary <string, string> IDV            = new Dictionary <string, string>();

            List <Dictionary <string, string> > bingingsList = new List <Dictionary <string, string> >();

            //Get collection of instances ID's and Attribute Names
            query = "dataset(ID,ATTRIBUTE,VALUE)";
            prologEngine.askQuery(query, _sourceMt, out bingingsList);
            foreach (Dictionary <string, string> bindings in bingingsList)
            {
                foreach (string k in bindings.Keys)
                {
                    if (k == "ID")
                    {
                        IDTable[bindings[k]] = 1;
                    }
                    if (k == "ATTRIBUTE")
                    {
                        AttributeTable[bindings[k]] = 1;
                    }
                }
                string IDVKey = bindings["ID"] + "_" + bindings["ATTRIBUTE"];
                IDV[IDVKey] = bindings["VALUE"];
            }
            // Scan to create the header
            foreach (string attr in AttributeTable.Keys)
            {
                this.Columns.Add(attr.Trim());
            }
            // Scan to create the dataset
            foreach (string id in IDTable.Keys)
            {
                DataRow row = this.NewRow();
                foreach (string attr in AttributeTable.Keys)
                {
                    string IDVKey = id + "_" + attr;
                    string val    = "unknown";
                    if (IDV.ContainsKey(IDVKey))
                    {
                        val = IDV[IDVKey];
                    }
                    row[attr] = val;
                }
                this.Rows.Add(row);
            }
        }
        public object Eval(object code)
        {
            TermList partList = code as TermList;

            if (partList == null)
            {
                if (code is SIProlog.Part)
                {
                    partList = new TermList((SIProlog.Part)code);
                }
            }
            if (code is string)
            {
                partList = prologEngine.ParseQuery(code.ToString(), MT);
            }
            List <Dictionary <string, SIProlog.Part> > results = new List <Dictionary <string, SIProlog.Part> >();

            prologEngine.askQuery(partList, MT, true, results, null);
            return(results);
        }
        public void GenRulesFromMt(SIProlog pEngine, string sourceMt, string destMt)
        {
            string targetAttr = "result";

            List <Dictionary <string, string> > bingingsList = new List <Dictionary <string, string> >();
            //Get collection of instances ID's and Attribute Names
            string query = "targetAttribute(ATTRIBUTE)";

            pEngine.askQuery(query, sourceMt, out bingingsList);
            foreach (Dictionary <string, string> bindings in bingingsList)
            {
                foreach (string k in bindings.Keys)
                {
                    if (k == "ATTRIBUTE")
                    {
                        targetAttr = bindings[k];
                    }
                }
            }

            GenRulesFromMt(pEngine, sourceMt, destMt, targetAttr);
        }
Example #7
0
        static void testProlog3()
        {
            // we can  do a graph of connected kb's
            // the query is from a point in the graph and the system gathers the KB
            // Wonder if we "logicRank" the graph in someway so we inference over what's relevant
            // Also what kind of connected graphs can we concoct ?
            // Maybe we want to have prove walk the KB graph?
            // Should the KB be constructed depth-first or breath first ?
            //  (It may not matter so long as the items of a given predicate appear in one MT)
            // probably should have classic optomizations like first term indexing for speed
            // Should work on built-ins. (Done except for eval) (Dmiles did eval)

            prologEngine.connectMT("sense1MT", "baseKB");
            prologEngine.connectMT("sense2MT", "baseKB");
            prologEngine.connectMT("spindleMT", "sense1MT");
            prologEngine.connectMT("spindleMT", "sense2MT");
            prologEngine.insertKB("canSense(X):-sense(X).\n", "baseKB");
            prologEngine.appendKB("genls(A,B):-genls(A,X),genls(X,B).\n", "baseKB");
            prologEngine.appendKB("isa(A,B):-isa(A,X),genls(X,B).\n", "baseKB");

            prologEngine.insertKB("sense(dog).\nsense(cat).\n", "sense1MT");
            prologEngine.insertKB("sense(boy).\nsense(girl).\n", "sense2MT");
            prologEngine.appendKB("isa(john,boy).\ngenls(boy,human).\ngenls(human,mammal).\n", "sense2MT");
            prologEngine.askQuery("canSense(WHAT1)", "sense1MT");
            prologEngine.askQuery("canSense(WHAT2)", "sense2MT");
            prologEngine.askQuery("canSense(WHAT3)", "spindleMT");
            prologEngine.askQuery("isa(john,JOHN_IS)", "spindleMT");
            //prologEngine.KBGraph.PrintToConsole();
        }