diff options
author | Aleksander Sadikov <aleksander.sadikov@fri.uni-lj.si> | 2016-02-29 20:56:12 +0100 |
---|---|---|
committer | Aleksander Sadikov <aleksander.sadikov@fri.uni-lj.si> | 2016-02-29 20:56:12 +0100 |
commit | 500dae272daabdb5e9272d3e54111aea5e109c3b (patch) | |
tree | 491c5b85390894415d897e6c509daff60f8a2512 | |
parent | 8bd1bb649e4b66ad9f07ab0f04649d4ce7cdd615 (diff) |
Improved hints for ancestor/2. "Timeout results as False" ask_truthTO() function added.
-rw-r--r-- | prolog/engine.py | 24 |
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 |