def _get_sapt_data(engine): cmd = [ 'build/bin/sapt_dump_index', '-m', 'engines/%s/models/decoder/sapt/' % engine ] process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=MMT_HOME) prefixes = 0 target_words = 0 while True: line = process.stdout.readline() if line != '': if line.startswith('SOURCE'): prefixes += int(line.split()[6]) elif line.startswith('TARGET'): target_words += int(line.split()[4]) else: break returncode = process.wait() if returncode != 0: raise ShellError(' '.join(cmd), returncode, process.stderr.read()) return prefixes, target_words
def _get_ngrams(engine): cmd = [ 'build/bin/dump_alm', '-m', 'engines/%s/models/decoder/lm/foreground.alm/' % engine ] process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=MMT_HOME) ngrams = 0 while True: line = process.stdout.readline() if line != '': if line.startswith('domain'): ngrams += int(line.split()[5]) else: break returncode = process.wait() if returncode != 0: raise ShellError(' '.join(cmd), returncode, process.stderr.read()) return ngrams
def _exe(cmd, stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE): process = subprocess.Popen(cmd, stdin=stdin, stdout=stdout, stderr=stderr, shell=True, cwd=MMT_HOME) returncode = process.wait() if returncode != 0: raise ShellError(cmd, returncode, process.stdout.read() + '\n' + process.stderr.read())