Skip to content

Commit

Permalink
praiseinference ported to python3
Browse files Browse the repository at this point in the history
  • Loading branch information
paolomorettin committed Mar 4, 2019
1 parent a80f739 commit 4d156bc
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions wmipa/praiseinference.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from time import sleep
from fractions import Fraction
from pysmt.typing import REAL, BOOL
import sys
import wmipa.praiselang as pl
from wmipa.wmiexception import WMIRuntimeException, WMIParsingError,\
WMITimeoutException
Expand Down Expand Up @@ -83,7 +84,10 @@ def compute_normalized_probability(self, query, evidence=None):
if task.poll() != None:
out, err = task.communicate()

if err != '':
err = err.decode(sys.stdout.encoding)
out = out.decode(sys.stdout.encoding)

if len(err) > 0:
msg = "PRAiSE error: {}"
raise WMIRuntimeException(msg.format(err))

Expand All @@ -109,6 +113,7 @@ def _get_definitions(variables):
def _parse_result(praise_out):
for line in praise_out.split("\n"):
line = line.strip()
print("LINE:", line)
if line.startswith("Result"):
result_str = line.partition(": ")[-1].strip()
try :
Expand All @@ -131,7 +136,7 @@ def convert_formula(formula, variables):
# an entry to the variables dictionary with the corresponding type
var_name = formula.symbol_name()
var_type = formula.get_type()
if not variables.has_key(var_name):
if var_name not in variables:
variables[var_name] = var_type
return var_name

Expand Down

0 comments on commit 4d156bc

Please sign in to comment.