summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--prolog/engine.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/prolog/engine.py b/prolog/engine.py
index b023c9e..cebadea 100644
--- a/prolog/engine.py
+++ b/prolog/engine.py
@@ -211,6 +211,30 @@ def ask_truth(engine, query, timeout=1):
# no error, query failed
return False
+def ask_truthTO(engine, query, timeout=1):
+ # Returns either True or False
+ # (Runtime) error is False!
+ # Timeout *is* handled: returned as False
+
+ # Run the query.
+ try:
+ reply, output = ask(engine, query, timeout)
+ except socket.timeout as ex:
+ return False
+
+ if 'error' in map(itemgetter(0), output):
+ return False
+ # TODO: Tim, this doesn't really work. It just proceeds and returns as a runtime error.
+ answer, error, more = process_answer(reply)
+ if error:
+ # query caused a runtime error
+ return False
+ elif answer:
+ return True
+ else:
+ # no error, query failed
+ return False
+
# reformats prolog's answer into a neater form
def process_answer(reply):
# When an engine is destroyed, a nested data object has the actual