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
2012-10-08 18:27:05 +01:00

32 lines
630 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()
q = Query(parent(X, "bob"), module=test1)
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()