|
Basic Ideas and Use
Updated 14 Oct 2002
|
Upper levels: - Amzi Python Interface 0.2... |
|
2. Basic Ideas and Use |
[ - - ] |
|
Index |
|
Ideas |
[ Top ] |
|
The AmziProlog module provides several new types to Python:
The package itself doesn't provide any generators, but they can certainly be useful in managing access to the results of nondeterministic predicates. |
|
Use |
[ Top ] |
|
To begin with, import the module, and create an engine:
import AmziProlog
eng = AmziProlog(engine('<xplfile>'))
For a single-answer, deterministic call (equivalent to 'Exec' in the other lsapi's), use the engine .run() method:
answer = eng.run('query(X,Y)')
print "The answer is: %s"%answer print "The functor is: %s"answer[0] print "The second argument term is: %s"%answer[2]
answer = eng.run(('query', None, None))
And there are also engine methods for putting together terms, which can then be submitted to .run() (see 'Building'). For going through multiple answers, one possibility is the engine methods .call() and .redo(), corresponding to regular lsapi 'call' and 'redo' methods. .call() takes the same kinds of arguments that .run() does, and returns an AmziTerm as value; .redo() takes no arguments and returns the the next instantiation of a previous call. But in a for-loop, the best method to use is .calls():
for answer in eng.calls('father(X,Y)'):
print "%s is the father of %s"%(answer[2], answer[1])
|
|
|
[ - Top - ] |