fixed bug in simil info

pull/202/head
ggrieco-tob 6 years ago
parent 0158705616
commit 92a0ca0e22
  1. 15
      utils/similarity/info.py

@ -1,5 +1,6 @@
import logging import logging
import sys import sys
import os.path
import traceback import traceback
from fastText import load_model from fastText import load_model
@ -11,8 +12,13 @@ logger = logging.getLogger("Slither-simil")
def info(args): def info(args):
try: try:
model = args.model model = args.model
model = load_model(model) if os.path.isfile(model):
model = load_model(model)
else:
model = None
filename = args.filename filename = args.filename
contract = args.contract contract = args.contract
solc = args.solc solc = args.solc
@ -31,13 +37,14 @@ def info(args):
if len(irs) == 0: if len(irs) == 0:
sys.exit(-1) sys.exit(-1)
x = "-".join([filename,contract,fname]) x = (filename,contract,fname)
y = " ".join(irs[x]) y = " ".join(irs[x])
fvector = model.get_sentence_vector(y)
print("Function {} in contract {} is encoded as:".format(fname, contract)) print("Function {} in contract {} is encoded as:".format(fname, contract))
print(y) print(y)
print(fvector) if model is not None:
fvector = model.get_sentence_vector(y)
print(fvector)
except Exception: except Exception:
logger.error('Error in %s' % args.filename) logger.error('Error in %s' % args.filename)

Loading…
Cancel
Save