Beispiel #1
0
        public bool IsTrue(Sentence clause)
        {
            object result = clause.Accept(this, null);

            return((result == null) ? false
                    : ((bool)result));
        }
Beispiel #2
0
        /**
         * Elimina las implicaciones de una sentencia.
         *
         * @param sentence
         *            una sentencia de lógica proposicional
         * @return una sentencia equivalente a la de entrada con todas las implicaciones eliminadas.
         */
        public static Sentence Eliminate(Sentence sentence)
        {
            ImplicationElimination eliminator = new ImplicationElimination();

            Sentence result = sentence.Accept(eliminator, null);

            return(result);
        }
Beispiel #3
0
        /**
         * Eliminate las bicondicionales de una sentencia.
         *
         * @param sentence
         *            una sentencia de lógica proposicional
         * @return una sentencia equivalente a la de entrada con todas las bicondicionales eliminadas.
         */
        public static Sentence Eliminate(Sentence sentence)
        {
            BiconditionalElimination eliminator = new BiconditionalElimination();

            Sentence result = sentence.Accept(eliminator, null);

            return(result);
        }
Beispiel #4
0
        // Era privado, pero al sacar esta clase fuera ahora es público
        public static ISet <Literal> getLiterals(Sentence disjunctiveSentence)
        {
            ISet <Literal> result = new HashSet <Literal>();

            LiteralCollector literalCollector = new LiteralCollector();

            result = disjunctiveSentence.Accept(literalCollector, result);

            return(result);
        }
Beispiel #5
0
        /**
         * Mueve ~ hacia dentro.
         *
         * @param sentence
         *            una sentencia de lógica proposicional que tiene sus bicondicionales e implicaciones quitadas.
         * @return una sentencia equivalente a la de la entrada con todas las negaciones movidas hacia dentro.
         * @throws ArgumentException
         *             si se encuentra una bicondicional o una implicación en la entrada
         */
        public static Sentence MoveNotsInward(Sentence sentence)
        {
            Sentence result = null;

            MoveNotInwards moveNotsIn = new MoveNotInwards();

            result = sentence.Accept(moveNotsIn, null);

            return(result);
        }
Beispiel #6
0
        /**
         * Distribuye o's (|) sobre y's (&).
         *
         * @param sentence
         *            una sentencia en lógica proposicional. A esta sentencia se le debe haber quitado bicondicionales, implicaciones y las negaciones tienen que haberse llevado hacia dentro.
         * @return una sentencia equivalente a la de entrada con las o'es distribuidas por las y'es.
         */
        public static Sentence Distribute(Sentence sentence)
        {
            Sentence result = null;

            DistributeOrOverAnd distributeOrOverAnd = new DistributeOrOverAnd();

            result = sentence.Accept(distributeOrOverAnd, null);

            return(result);
        }
Beispiel #7
0
 private ISet <Sentence> ProcessSubTerm(Sentence s, ISet <Sentence> soFar)
 {
     if (detector.ContainsEmbeddedAnd(s))
     {
         return((ISet <Sentence>)s.Accept(this, soFar));
     }
     else
     {
         soFar.Add(s);
         return(soFar);
     }
 }
        private Sentence DistributeOrOverAnd(BinarySentence bs)
        {
            BinarySentence andTerm = bs.FirstTermIsAndSentence() ? (BinarySentence)bs
                                     .First
                    : (BinarySentence)bs.Second;
            Sentence otherterm = bs.FirstTermIsAndSentence() ? bs.Second : bs
                                 .First;
            // (alpha or (beta and gamma) = ((alpha or beta) and (alpha or gamma))
            Sentence alpha       = (Sentence)otherterm.Accept(this, null);
            Sentence beta        = (Sentence)andTerm.First.Accept(this, null);
            Sentence gamma       = (Sentence)andTerm.Second.Accept(this, null);
            Sentence distributed = new BinarySentence("AND", new BinarySentence(
                                                          "OR", alpha, beta), new BinarySentence("OR", alpha, gamma));

            return(distributed);
        }
Beispiel #9
0
        public override Sentence VisitUnarySentence(ComplexSentence s, object arg)
        {
            Sentence result = null;

            Sentence negated = s.GetSimplerSentence(0);

            if (negated.IsPropositionSymbol())
            {
                // Ya se ha movido completamente
                result = s;
            }
            else if (negated.IsNotSentence())
            {
                // ~(~&alpha;) &equiv; &alpha; (eliminación de la doble negación)
                Sentence alpha = negated.GetSimplerSentence(0);
                result = alpha.Accept(this, arg);
            }
            else if (negated.IsAndSentence() || negated.IsOrSentence())
            {
                Sentence alpha = negated.GetSimplerSentence(0);
                Sentence beta  = negated.GetSimplerSentence(1);

                // Esto asegura que la eliminación de la doble negación sucede
                Sentence notAlpha = (new ComplexSentence(Connective.NOT, alpha))
                                    .Accept(this, null);
                Sentence notBeta = (new ComplexSentence(Connective.NOT, beta))
                                   .Accept(this, null);
                if (negated.IsAndSentence())
                {
                    // ~(&alpha; & &beta;) &equiv; (~&alpha; | ~&beta;) (De Morgan)
                    result = new ComplexSentence(Connective.OR, notAlpha, notBeta);
                }
                else
                {
                    // ~(&alpha; | &beta;) &equiv; (~&alpha; & ~&beta;) (De Morgan)
                    result = new ComplexSentence(Connective.AND, notAlpha, notBeta);
                }
            }
            else
            {
                throw new ArgumentException(             //IllegalArgumentException
                          "Biconditionals and Implications should not exist in input: "
                          + s);
            }

            return(result);
        }
Beispiel #10
0
        public ISet <Sentence> GetClausesFrom(Sentence sentence)
        {
            ISet <Sentence> set = new HashedSet <Sentence>();

            if (sentence is Symbol)
            {
                set.Add(sentence);
            }
            else if (sentence is UnarySentence)
            {
                set.Add(sentence);
            }
            else
            {
                set = (ISet <Sentence>)sentence.Accept(this, set);
            }
            return(set);
        }
        public ISet <Symbol> GetSymbolsIn(Sentence s)
        {
            if (s == null)  // empty knowledge bases == null fix this later
            {
                return(new HashedSet <Symbol>());
            }

            var ret = new HashedSet <Symbol>();

            foreach (var part in (ISet <Sentence>)s.Accept(this, new HashedSet <Sentence>()))
            {
                if (part is Symbol)
                {
                    ret.Add((Symbol)part);
                }
            }
            return(ret);
        }
Beispiel #12
0
        public bool IsActiveImplication(Sentence clause)
        {
            // returns true when (A=>B), A=t, B=t
            // Or  (A=>B) translated into (-A OR B), A=f (since its been inverted),B=t ...

            object result = clause.Accept(this, null);

            if (result == null)
            {
                return(false);
            }
            if (!(clause is BinarySentence))
            {
                return(false);
            }
            BinarySentence bs   = (BinarySentence)clause;
            string         oper = bs.Operator;

            if (oper.Equals("=>") || oper.Equals("IMPLIES"))
            {
                object firstValue  = bs.First.Accept(this, null);
                object secondValue = bs.Second.Accept(this, null);
                if ((firstValue.Equals(true)) && (secondValue.Equals(true)))
                {
                    return(true);
                }
            }
            if (oper.Equals("OR"))
            {
                object firstValue  = bs.First.Accept(this, null);
                object secondValue = bs.Second.Accept(this, null);
                if ((firstValue.Equals(false)) && (secondValue.Equals(true)))
                {
                    return(true);
                }
            }
            return(false);
        }
 public ISet <Symbol> GetPositiveSymbolsIn(Sentence sentence)
 {
     return((ISet <Symbol>)sentence.Accept(this, new HashedSet <Sentence>()));
 }
Beispiel #14
0
 public bool ContainsEmbeddedAnd(Sentence s)
 {
     return((bool)s.Accept(this, null));
 }
 public ISet <Symbol> GetNegativeSymbolsIn(Sentence s)
 {
     return((ISet <Symbol>)s.Accept(this, new HashedSet <Sentence>()));
 }
Beispiel #16
0
 public bool IsUnknown(Sentence s)
 {
     return(null == s.Accept(this, null));
 }
Beispiel #17
0
 public bool IsFalse(Sentence s)
 {
     return(false.Equals(s.Accept(this, null))); // Había un bool.FalseString ... que no tiene mucho sentido
 }
 private Sentence Step(Sentence s)
 {
     return((Sentence)s.Accept(this, null));
 }
Beispiel #19
0
        public bool IsFalse(Sentence clause)
        {
            object o = clause.Accept(this, null);

            return((o != null) ? ((bool)o) == false : false);
        }
Beispiel #20
0
        public bool IsUnknown(Sentence clause)   // TODO TEST WELL
        {
            object o = clause.Accept(this, null);

            return(o == null);
        }