From 92a0ca0e22cba978ff6738c1eee4797ebde7d0d0 Mon Sep 17 00:00:00 2001 From: ggrieco-tob Date: Tue, 7 May 2019 18:13:32 -0300 Subject: [PATCH] fixed bug in simil info --- utils/similarity/info.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/utils/similarity/info.py b/utils/similarity/info.py index 947d9b40b..76da37d99 100644 --- a/utils/similarity/info.py +++ b/utils/similarity/info.py @@ -1,5 +1,6 @@ import logging import sys +import os.path import traceback from fastText import load_model @@ -11,8 +12,13 @@ logger = logging.getLogger("Slither-simil") def info(args): try: + model = args.model - model = load_model(model) + if os.path.isfile(model): + model = load_model(model) + else: + model = None + filename = args.filename contract = args.contract solc = args.solc @@ -30,14 +36,15 @@ def info(args): irs = encode_contract(filename, solc=solc) if len(irs) == 0: sys.exit(-1) - - x = "-".join([filename,contract,fname]) - y = " ".join(irs[x]) - fvector = model.get_sentence_vector(y) + x = (filename,contract,fname) + y = " ".join(irs[x]) + print("Function {} in contract {} is encoded as:".format(fname, contract)) print(y) - print(fvector) + if model is not None: + fvector = model.get_sentence_vector(y) + print(fvector) except Exception: logger.error('Error in %s' % args.filename)