Exemple #1
0
        public void Init(string tell)

        /* This is the agents set up. It sets up:
        * - the list of all symbols
        * - all the clauses for the knowledge base
        * - the facts about the world          */
        {
            string[] sentances = tell.Split(';');
            for (int i = 0; i < sentances.Length - 1; i++)
            {
                if (!sentances[i].Contains("=>"))                  // Checks to see if its a fact. eg b;
                {
                    if (!Agenda.Contains(sentances[i]))            // If the symbol is not already in the Symbols list
                    {
                        Agenda.Add(sentances[i]);                  // Adds this symbol to the symbols list
                    }
                    if (!Facts.Contains(sentances[i]))             // Checks if Facts already contains the symbol
                    {
                        Facts.Add(sentances[i]);                   // Adds the symbol to the list of symbols that are true
                    }
                }
                else
                {
                    // If it gets here; the current string is a Clause
                    Clauses.Add(sentances[i]);
                    string[] splitImp = sentances[i].Split("=>");   // Splits clause into pre-implication and post-implecation
                    if (!splitImp[0].Contains("&"))                 // if pre-implecation does not have &
                    {
                        for (int j = 0; j < splitImp.Length; j++)   // loop through clause
                        {
                            if (!Agenda.Contains(splitImp[j]))      // if agenda doesnt contain the symbol
                            {
                                Agenda.Add(splitImp[j]);            // add symbols
                            }
                        }
                    }
                    else
                    {                                                      // Pre-imp contains &
                        string[] splitLogic = splitImp[0].Split("&");      // split by logical separators
                        for (int j = 0; j < splitLogic.Length; j++)        // loop through strings split
                        {
                            if (!Agenda.Contains(splitLogic[j]))
                            {
                                Agenda.Add(splitLogic[j]);                    // add symbols to symbols base
                            }
                            if (!Agenda.Contains(splitImp[1]))
                            {
                                Agenda.Add(splitImp[1]);
                            }
                        }
                    }
                }
            }
        }
Exemple #2
0
        public bool BCentails()
        {
            while (Agenda.Count > 0)
            {
                // take the first item and process it
                string q = Agenda[Agenda.Count - 1];
                Agenda.RemoveAt(Agenda.Count - 1);

                if (q != Ask)
                {
                    if (!Entailed.Contains(q))
                    {
                        Entailed.Insert(0, q);
                    }
                }

                if (!(Facts.Contains(q)))
                {
                    List <string> prem = new List <string>();
                    // for each of the clauses...
                    for (int i = 0; i < Clauses.Count; i++)
                    {
                        // .... that contain p in its premise
                        if (ClauseContains(Clauses[i], q, 1))
                        {
                            List <string> temp = GetPremises(Clauses[i]);
                            for (int j = 0; j < temp.Count; j++)
                            {
                                prem.Add(temp[j]);
                            }
                        }
                    }
                    if (prem.Count == 0)
                    {
                        return(false);
                    }
                    else
                    {
                        for (int i = 0; i < prem.Count; i++)
                        {
                            if (!Entailed.Contains(prem[i]))
                            {
                                Agenda.Add(prem[i]);
                            }
                        }
                    }
                }
            }
            // while end
            return(true);
        }