@classmethod
    def execute(cls, fst_model, input, is_file=False, nbest=None):
        logger = logging.getLogger(__name__)

        cmd = ['phonetisaurus-g2p',
               '--model=%s' % fst_model,
               '--input=%s' % input,
               '--words']

        if is_file:
            cmd.append('--isfile')

        if nbest is not None:
            cmd.extend(['--nbest=%d' % nbest])

        cmd = [str(x) for x in cmd]
        try:
            # FIXME: We can't just use subprocess.call and redirect stdout
            # and stderr, because it looks like Phonetisaurus can't open
            # an already opened file descriptor a second time. This is why
            # we have to use this somehow hacky subprocess.Popen approach.
            proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
                                    stderr=subprocess.PIPE)
            stdoutdata, stderrdata = proc.communicate()
        except __HOLE__:
            logger.error("Error occured while executing command '%s'",
                         ' '.join(cmd), exc_info=True)
            raise

        if stderrdata:
            for line in stderrdata.splitlines():
                message = line.strip()
                if message:
                    logger.debug(message)

        if proc.returncode != 0:
            logger.error("Command '%s' return with exit status %d",
                         ' '.join(cmd), proc.returncode)
            raise OSError("Command execution failed")

        result = {}
        if stdoutdata is not None:
            for word, precision, pronounc in cls.PATTERN.findall(stdoutdata):
                if word not in result:
                    result[word] = []
                result[word].append(pronounc)
        return result
dataset/ETHPy150Open jasperproject/jasper-client/client/g2p.py/PhonetisaurusG2P.execute