forked from M-Labs/artiq
1
0
Fork 0

compiler.embedding: avoid showing wildly incorrect suggestions.

This commit is contained in:
whitequark 2015-11-24 17:50:46 +08:00
parent 14993e89e2
commit d14ad6727a
1 changed files with 2 additions and 2 deletions

View File

@ -11,7 +11,7 @@ from collections import OrderedDict, defaultdict
from pythonparser import ast, algorithm, source, diagnostic, parse_buffer from pythonparser import ast, algorithm, source, diagnostic, parse_buffer
from pythonparser import lexer as source_lexer, parser as source_parser from pythonparser import lexer as source_lexer, parser as source_parser
from Levenshtein import jaro_winkler from Levenshtein import ratio as similarity, jaro_winkler
from ..language import core as language_core from ..language import core as language_core
from . import types, builtins, asttyped, prelude from . import types, builtins, asttyped, prelude
@ -211,7 +211,7 @@ class ASTSynthesizer:
def suggest_identifier(id, names): def suggest_identifier(id, names):
sorted_names = sorted(names, key=lambda other: jaro_winkler(id, other), reverse=True) sorted_names = sorted(names, key=lambda other: jaro_winkler(id, other), reverse=True)
if len(sorted_names) > 0: if len(sorted_names) > 0:
if jaro_winkler(id, sorted_names[0]) > 0.0: if jaro_winkler(id, sorted_names[0]) > 0.0 and similarity(id, sorted_names[0]) > 0.5:
return sorted_names[0] return sorted_names[0]
class StitchingASTTypedRewriter(ASTTypedRewriter): class StitchingASTTypedRewriter(ASTTypedRewriter):