Пример #1
0
def tokenize_code(code):
    code = PROMPT_REGEX.sub("", code)
    for cmd in bash.parse(str(code)):
        args = cmd[1:]
        cmd = cmd[0]
        yield cmd
        for arg in args:
            yield common.mangle_arg(cmd, arg)
Пример #2
0
def tokenize_code(code):
    code = PROMPT_REGEX.sub("", code)
    for cmd in bash.parse(str(code)):
        args = cmd[1:]
        cmd = cmd[0]
        yield cmd
        for arg in args:
            yield common.mangle_arg(cmd, arg)
Пример #3
0
 def score(self, root_cmd, word):
     if self.type == "seq":
         return sum(part.score(root_cmd, word) for part in self.info)
     elif self.type == "case":
         return max(part.score(root_cmd, word) for part in self.info)
     elif self.type == "empty":
         return 0
     elif self.type == "arg":
         argname = common.mangle_arg(root_cmd, self.info[0])
         return scores.get(word, {}).get(argname, 0) * (1-code_freqs.get(argname, 0))
     elif self.type == "hole":
         return 0
Пример #4
0
 def score(self, root_cmd, word):
     if self.type == "seq":
         return sum(part.score(root_cmd, word) for part in self.info)
     elif self.type == "case":
         return max(part.score(root_cmd, word) for part in self.info)
     elif self.type == "empty":
         return 0
     elif self.type == "arg":
         argname = common.mangle_arg(root_cmd, self.info[0])
         return scores.get(word, {}).get(
             argname, 0) * (1 - code_freqs.get(argname, 0))
     elif self.type == "hole":
         return 0