This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
yap-6.3/packages/pyswip/examples/knowledgebase.py
2010-06-01 00:33:32 +01:00

34 lines
652 B
Python

from pyswip import *
p = Prolog()
assertz = Functor("assertz")
parent = Functor("parent", 2)
test1 = newModule("test1")
test2 = newModule("test2")
call(assertz(parent("john", "bob")), module=test1)
call(assertz(parent("jane", "bob")), module=test1)
call(assertz(parent("mike", "bob")), module=test2)
call(assertz(parent("gina", "bob")), module=test2)
print "knowledgebase test1"
X = Variable()
print "ok"
q = Query(parent(X, "bob"), module=test1)
print "ok"
while q.nextSolution():
print X.value
q.closeQuery()
print "knowledgebase test2"
q = Query(parent(X, "bob"), module=test2)
while q.nextSolution():
print X.value
q.closeQuery()