From e0d77a118281df581ee57d73ec57af17b9694c56 Mon Sep 17 00:00:00 2001 From: Gijs Date: Wed, 22 Jun 2022 16:55:10 +0200 Subject: [PATCH] Upated tree encoder. --- commenting_code_model/encode_model.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/commenting_code_model/encode_model.py b/commenting_code_model/encode_model.py index 0ea80e4..957cf15 100644 --- a/commenting_code_model/encode_model.py +++ b/commenting_code_model/encode_model.py @@ -19,14 +19,17 @@ def encode_branch(branch): def encode_tree(tree): lines = [ - "print(\"Considering feature {index}, is it smaller than {threshold}?\");".format(index=tree['index'], threshold=tree['value']), - "// timeout code", + "(clearScreen)();", + "(printLine)(\"Considering feature {index}, is it smaller than {threshold}?\");".format(index=tree['index'], threshold=tree['value']), + "(delay)(1500);", "if (r[{index}] < {threshold}) {{".format(index=tree['index'], threshold=tree['value']), - indent_line("print(\"Yes\");"), + indent_line("(printLine)(\"Yes\");"), + indent_line("(delay)(1500);"), *encode_branch(tree['left']), "}", "else {", - indent_line("print(\"No\");"), + indent_line("(printLine)(\"No\");"), + indent_line("(delay)(1500);"), *encode_branch(tree['right']), "}" ] @@ -48,7 +51,7 @@ def make_classifier (tree): "{", "public:", *map(indent_line, [ - "char* predict(float *r)", + "char* predict(float *r, void (*printLine)(char *), void (*clearScreen)(), void (*delay)(int))", "{", *encode_tree(tree), "}",