Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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
Exemplo n.º 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