Inheritance: ComplexSentence
示例#1
0
 private Sentence transformImpliedSentence(BinarySentence bs)
 {
     Sentence first = new UnarySentence((Sentence)bs.getFirst().accept(
             this, null));
     return new BinarySentence("OR", first, (Sentence)bs.getSecond()
             .accept(this, null));
 }
示例#2
0
 private Sentence transformBiConditionalSentence(BinarySentence bs)
 {
     Sentence first = new BinarySentence("=>", (Sentence)bs.getFirst()
             .accept(this, null), (Sentence)bs.getSecond().accept(this,
             null));
     Sentence second = new BinarySentence("=>", (Sentence)bs.getSecond()
             .accept(this, null), (Sentence)bs.getFirst()
             .accept(this, null));
     return new BinarySentence("AND", first, second);
 }
示例#3
0
        public override Object visitBinarySentence(BinarySentence bs, Object args)
        {

            List<Sentence> soFar = (List<Sentence>)args;

            Sentence first = bs.getFirst();
            Sentence second = bs.getSecond();
            processSubTerm(second, processSubTerm(first, soFar));

            return soFar;

        }
示例#4
0
 public Object visitBinarySentence(BinarySentence fs, Object arg)
 {
     if (fs.isAndSentence())
     {
         return true;
     }
     else
     {
         bool first = ((bool)fs.getFirst().accept(this, null));
         bool second = ((bool)fs.getSecond().accept(this, null));
         return (first || second);
     }
 }
示例#5
0
        public override bool Equals(Object o)
        {
            if (this == o)
            {
                return(true);
            }
            if ((o == null) || !(o is BinarySentence))
            {
                return(false);
            }
            BinarySentence bs = (BinarySentence)o;

            return((bs.getOperator().Equals(getOperator())) &&
                   (bs.getFirst().Equals(first)) && (bs.getSecond()
                                                     .Equals(second)));
        }
示例#6
0
 public virtual Object visitBinarySentence(BinarySentence bs, Object arg)
 {
     List<Sentence> s = new List<Sentence>();
     if (arg is List<Symbol>)
     {
         List<Symbol> symbols = ((List<Symbol>)arg);
         foreach (Symbol symbol in symbols)
         {
             s.Add((Sentence)symbol);
         }
     }
     else
     {
         throw new ArgumentException("Could not cast arg to List<Sentence>");
     }
     List<Sentence> termunion = SetOps.union((List<Sentence>)bs.getFirst().accept(this, arg),
             (List<Sentence>)bs.getSecond().accept(this, arg));
     return SetOps.union(s, termunion);
 }
示例#7
0
 public override Object visitBinarySentence(BinarySentence bs, Object arg)
 {
     if (bs.isBiconditional())
     {
         return transformBiConditionalSentence(bs);
     }
     else if (bs.isImplication())
     {
         return transformImpliedSentence(bs);
     }
     else if (bs.isOrSentence()
           && (bs.firstTermIsAndSentence() || bs.secondTermIsAndSentence()))
     {
         return distributeOrOverAnd(bs);
     }
     else
     {
         return base.visitBinarySentence(bs, arg);
     }
 }
示例#8
0
 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;
     }
 }
示例#9
0
        public bool plResolution(KnowledgeBase kb, Sentence alpha)
        {
            Sentence kBAndNotAlpha = new BinarySentence("AND", kb.asSentence(),
                    new UnarySentence(alpha));
            List<Sentence> clauses = new CNFClauseGatherer()
                    .getClausesFrom(new CNFTransformer().transform(kBAndNotAlpha));
            clauses = filterOutClausesWithTwoComplementaryLiterals(clauses);
            List<Sentence> newClauses = new List<Sentence>();
            while (true)
            {
                List<List<Sentence>> pairs = getCombinationPairs(clauses);

                for (int i = 0; i < pairs.Count; i++)
                {
                    List<Sentence> pair = pairs[i];
                    // System.Console.WriteLine("pair number" + i+" of "+pairs.Count);
                    List<Sentence> resolvents = plResolve(pair[0], pair[1]);
                    resolvents = filterOutClausesWithTwoComplementaryLiterals(resolvents);

                    if (resolvents.Contains(new Symbol("EMPTY_CLAUSE")))
                    {
                        return true;
                    }
                    newClauses = SetOps.union(newClauses, resolvents);
                    // System.Console.WriteLine("clauseslist size = " +clauses.Count);

                }
                if (SetOps.intersection(newClauses, clauses).Count == newClauses
                        .Count)
                {// subset test
                    return false;
                }
                clauses = SetOps.union(newClauses, clauses);
                clauses = filterOutClausesWithTwoComplementaryLiterals(clauses);
            }

        }
示例#10
0
 public virtual Object visitBinarySentence(BinarySentence fs, Object arg)
 {
     return new BinarySentence(fs.getOperator(), (Sentence)fs.getFirst()
             .accept(this, arg), (Sentence)fs.getSecond().accept(this, arg));
 }
示例#11
0
 private Sentence distributeOrOverAnd(BinarySentence bs)
 {
     BinarySentence andTerm = bs.firstTermIsAndSentence() ? (BinarySentence)bs
             .getFirst()
             : (BinarySentence)bs.getSecond();
     Sentence otherterm = bs.firstTermIsAndSentence() ? bs.getSecond() : bs
             .getFirst();
     // (alpha or (beta and gamma) = ((alpha or beta) and (alpha or gamma))
     Sentence alpha = (Sentence)otherterm.accept(this, null);
     Sentence beta = (Sentence)andTerm.getFirst().accept(this, null);
     Sentence gamma = (Sentence)andTerm.getSecond().accept(this, null);
     Sentence distributed = new BinarySentence("AND", new BinarySentence(
             "OR", alpha, beta), new BinarySentence("OR", alpha, gamma));
     return distributed;
 }
示例#12
0
	public Object visitBinarySentence(BinarySentence bs, Object arg) {
		bool? firstValue = (bool?) bs.getFirst().accept(this, null);
		bool? secondValue = (bool?) bs.getSecond().accept(this, null);
		if (!firstValue.HasValue  || !secondValue.HasValue) {
			// strictly not true for or/and
			// -FIX later
			return null;
		} else {
			String op = bs.getOperator();
			if (op.Equals("AND")) {
                return firstValue.Value && secondValue.Value;
			} else if (op.Equals("OR")) {
                return firstValue.Value || secondValue.Value;
			} else if (op.Equals("=>")) {
                return !(firstValue.Value && !secondValue.Value);
            }
            else if (op.Equals("<=>"))
            {
				return firstValue.Equals(secondValue);
			}
			return null;
		}
	}