port of PYSWIP package.
This commit is contained in:
33
packages/pyswip/examples/knowledgebase.py
Normal file
33
packages/pyswip/examples/knowledgebase.py
Normal file
@@ -0,0 +1,33 @@
|
||||
|
||||
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()
|
||||
|
Reference in New Issue
Block a user