AIMA.Core.Logic.Propositional.Algorithms.LogicUtils.chainWith C# (CSharp) Method

chainWith() public static method

public static chainWith ( String connector, List sentences ) : Sentence
connector String
sentences List
return AIMA.Core.Logic.Propositional.Parsing.Ast.Sentence
        public static Sentence chainWith(String connector, List<Sentence> sentences)
        {
            if (sentences.Count == 0)
            {
                return null;
            }
            else if (sentences.Count == 1)
            {
                return (Sentence)sentences[0];
            }
            else
            {
                Sentence soFar = (Sentence)sentences[0];
                for (int i = 1; i < sentences.Count; i++)
                {
                    Sentence next = (Sentence)sentences[i];
                    soFar = new BinarySentence(connector, soFar, next);
                }
                return soFar;
            }
        }
    }

Usage Example

Beispiel #1
0
        private Sentence createResolventClause(ClauseSymbols cs, Symbol toRemove)
        {
            List <Symbol> positiveSymbols = SetOps
                                            .union(cs.clause1PositiveSymbols, cs.clause2PositiveSymbols);
            List <Symbol> negativeSymbols = SetOps
                                            .union(cs.clause1NegativeSymbols, cs.clause2NegativeSymbols);

            if (positiveSymbols.Contains(toRemove))
            {
                positiveSymbols.Remove(toRemove);
            }
            if (negativeSymbols.Contains(toRemove))
            {
                negativeSymbols.Remove(toRemove);
            }

            positiveSymbols.Sort(new SymbolComparator());
            negativeSymbols.Sort(new SymbolComparator());

            List <Sentence> sentences = new List <Sentence>();

            for (int i = 0; i < positiveSymbols.Count; i++)
            {
                sentences.Add(positiveSymbols[i]);
            }
            for (int i = 0; i < negativeSymbols.Count; i++)
            {
                sentences.Add(new UnarySentence(negativeSymbols[i]));
            }
            if (sentences.Count == 0)
            {
                return(new Symbol("EMPTY_CLAUSE")); // == empty clause
            }
            else
            {
                return(LogicUtils.chainWith("OR", sentences));
            }
        }
All Usage Examples Of AIMA.Core.Logic.Propositional.Algorithms.LogicUtils::chainWith
LogicUtils