chainWith() public static method

public static chainWith ( String connector, List sentences ) : Sentence
connector String
sentences List
return AIMA.Core.Logic.Propositional.Parsing.Ast.Sentence
Exemplo n.º 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));
            }
        }
Exemplo n.º 2
0
 public Sentence asSentence()
 {
     return(LogicUtils.chainWith("AND", sentences));
 }
Exemplo n.º 3
0
        public SymbolValuePair findPureSymbolValuePair(List <Sentence> clauseList,
                                                       Model model, List <Symbol> symbols)
        {
            List <Sentence> _clausesWithNonTrueValues = clausesWithNonTrueValues(clauseList,
                                                                                 model);
            Sentence nonTrueClauses = LogicUtils.chainWith("AND",
                                                           _clausesWithNonTrueValues);
            // System.Console.WriteLine("Unsatisfied clauses = "
            // + clausesWithNonTrueValues.Count);
            List <Symbol> symbolsAlreadyAssigned = new List <Symbol>(model.getAssignedSymbols());

            // debug
            // List symList = asList(symbolsAlreadyAssigned);
            //
            // System.Console.WriteLine(" assignedSymbols = " + symList.Count);
            // if (symList.Count == 52) {
            // System.Console.WriteLine("untrue clauses = " + clausesWithNonTrueValues);
            // System.Console.WriteLine("model= " + model);
            // }

            // debug
            List <Symbol> purePositiveSymbols = SetOps
                                                .difference(new SymbolClassifier()
                                                            .getPurePositiveSymbolsIn(nonTrueClauses),
                                                            symbolsAlreadyAssigned);

            List <Symbol> pureNegativeSymbols = SetOps
                                                .difference(new SymbolClassifier()
                                                            .getPureNegativeSymbolsIn(nonTrueClauses),
                                                            symbolsAlreadyAssigned);

            // if none found return "not found
            if ((purePositiveSymbols.Count == 0) &&
                (pureNegativeSymbols.Count == 0))
            {
                return(new SymbolValuePair());// automatically set to null values
            }
            else
            {
                if (purePositiveSymbols.Count > 0)
                {
                    Symbol symbol = purePositiveSymbols[0];
                    if (pureNegativeSymbols.Contains(symbol))
                    {
                        throw new ApplicationException("Symbol " + symbol.getValue()
                                                       + "misclassified");
                    }
                    return(new SymbolValuePair(symbol, true));
                }
                else
                {
                    Symbol symbol = new Symbol((pureNegativeSymbols[0])
                                               .getValue());
                    if (purePositiveSymbols.Contains(symbol))
                    {
                        throw new ApplicationException("Symbol " + symbol.getValue()
                                                       + "misclassified");
                    }
                    return(new SymbolValuePair(symbol, false));
                }
            }
        }