예제 #1
0
        private void Store(ISentence aSentence)
        {
            originalSentences.Add(aSentence);

            // Convert the sentence to CNF
            CNF cnfOfOrig = cnfConverter.ConvertToCNF(aSentence);

            foreach (Clause c in cnfOfOrig.GetConjunctionOfClauses())
            {
                c.SetProofStep(new ProofStepClauseClausifySentence(c, aSentence));
                if (c.IsEmpty())
                {
                    // This should not happen, if so the user
                    // is trying to add an unsatisfiable sentence
                    // to the KB.
                    throw new InvalidOperationException(
                              "Attempted to add unsatisfiable sentence to KB, orig=["
                              + aSentence + "] CNF=" + cnfOfOrig);
                }

                // Ensure all clauses added to the KB are Standardized Apart.
                var standardizedC = standardizeApart.GetStandardizeApartResult(c, variableIndexical);

                // Will make all clauses immutable
                // so that they cannot be modified externally.
                standardizedC.Immutable = true;
                if (clauses.Add(standardizedC))
                {
                    // If added keep track of special types of
                    // clauses, as useful for query purposes
                    if (standardizedC.IsDefiniteClause())
                    {
                        allDefiniteClauses.Add(standardizedC);
                    }
                    if (standardizedC.IsImplicationDefiniteClause())
                    {
                        implicationDefiniteClauses.Add(standardizedC);
                    }
                    if (standardizedC.IsUnitClause())
                    {
                        this.IndexFact(standardizedC.GetLiterals().First());
                    }
                }
            }
        }
예제 #2
0
        public ISet <Clause> ConvertToClauses(ISentence aSentence)
        {
            CNF cnf = cnfConverter.ConvertToCNF(aSentence);

            return(new HashedSet <Clause>(cnf.GetConjunctionOfClauses()));
        }