Exemple #1
0
def testSetMinusPartial(p, q):

    # compute the set difference of the extension of p minus the one of q
    input = dlvhex.getInputAtoms()
    for x in input:
        tup = x.tuple()

        # for each possible input atom p(x) (according to the grouding, it is not necessarily true in the current input)
        if tup[0].value() == p.value():

            qAtom = dlvhex.storeAtom((q, tup[1]))

            # if p(x) is true and the corresponding atom q(x) is not true (i.e., false or undefined)
            if dlvhex.isTrue(x) and not dlvhex.isTrue(qAtom):
                # if q(x) is false, then x is definitely in the output
                if not dlvhex.isInputAtom(qAtom) or dlvhex.isFalse(qAtom):
                    #					print "Definitely true: " + tup[1].value()
                    dlvhex.output((tup[1], ))

                # if q(x) is undefined, then x might be in the output
                else:
                    #					print "Could be true: " + tup[1].value()
                    dlvhex.outputUnknown((tup[1], ))
                    v = 0

            # if p(x) is undefined and q(x) is not true (i.e., false or undefined), then x might be in the output
            if not dlvhex.isTrue(x) and not dlvhex.isFalse(
                    x) and not dlvhex.isTrue(qAtom):
                #				print "Could be true: " + tup[1].value()
                dlvhex.outputUnknown((tup[1], ))
                v = 0
Exemple #2
0
def testSetMinusPartial(p, q):

	# compute the set difference of the extension of p minus the one of q
	input = dlvhex.getInputAtoms()
	for x in input:
		tup = x.tuple()

		# for each possible input atom p(x) (according to the grouding, it is not necessarily true in the current input)
		if tup[0].value() == p.value():

			qAtom = dlvhex.storeAtom((q, tup[1]))

			# if p(x) is true and the corresponding atom q(x) is not true (i.e., false or undefined)
			if dlvhex.isTrue(x) and not dlvhex.isTrue(qAtom):
				# if q(x) is false, then x is definitely in the output
				if not dlvhex.isInputAtom(qAtom) or dlvhex.isFalse(qAtom):
#					print "Definitely true: " + tup[1].value()
					dlvhex.output((tup[1], ))

				# if q(x) is undefined, then x might be in the output
				else:
#					print "Could be true: " + tup[1].value()
					dlvhex.outputUnknown((tup[1], ))
					v=0

			# if p(x) is undefined and q(x) is not true (i.e., false or undefined), then x might be in the output
			if not dlvhex.isTrue(x) and not dlvhex.isFalse(x) and not dlvhex.isTrue(qAtom):
#				print "Could be true: " + tup[1].value()
				dlvhex.outputUnknown((tup[1], ))
				v=0
Exemple #3
0
def setdiff(p,q):
	# for all input atoms (over p or q)
	for x in dlvhex.getTrueInputAtoms():
		# check if the predicate is p
		if x.tuple()[0] == p:
			# check if the atom with predicate
			# being changed to q is NOT in the input
			if dlvhex.isFalse(dlvhex.storeAtom((q, x.tuple()[1]))):
				# then the element is in the output
				dlvhex.output((x.tuple()[1], ));
Exemple #4
0
def setdiff(p, q):
  # go over all input atoms (p or q)
  for x in dlvhex.getTrueInputAtoms():
    # get predicate/argument of atom
    pred, arg = x.tuple() # pred(arg)
    # check if x is of form p(arg)
    if pred == p:
      # produce atom q(arg)
      qatom = dlvhex.storeAtom( (q, arg) )
      # check q(arg) is NOT in input
      if dlvhex.isFalse(qatom):
        # then put arg into the output
        dlvhex.output( (arg,) )
Exemple #5
0
def aOrNotB(a,b):

	if dlvhex.learnSupportSets():
		dlvhex.learn((
				dlvhex.storeAtom((a, )),
				dlvhex.storeOutputAtom(()).negate()	# then () is in the output
				));
		dlvhex.learn((
				dlvhex.storeAtom((b, )).negate(),
				dlvhex.storeOutputAtom(()).negate()	# then () is in the output
				));
	else:
		aIsTrue = dlvhex.isTrue(dlvhex.storeAtom((a, )))
		bIsFalse = dlvhex.isFalse(dlvhex.storeAtom((b, )))
		if aIsTrue or bIsFalse:
			dlvhex.output(())
Exemple #6
0
def aOrNotB(a,b):

	if dlvhex.learnSupportSets():
		dlvhex.learn((
				dlvhex.storeAtom((a, )),
				dlvhex.storeOutputAtom(()).negate()	# then () is in the output
				));
		dlvhex.learn((
				dlvhex.storeAtom((b, )).negate(),
				dlvhex.storeOutputAtom(()).negate()	# then () is in the output
				));
	else:
		aIsTrue = dlvhex.isTrue(dlvhex.storeAtom((a, )))
		bIsFalse = dlvhex.isFalse(dlvhex.storeAtom((b, )))
		if aIsTrue or bIsFalse:
			dlvhex.output(())