Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
#!/usr/bin/env python3 # -*- coding: utf-8 -*-
Handling MALLET in Python *************************
Functions and classes of this module are for **handling `MALLET <http://mallet.cs.umass.edu/topics.php>`_ \ in Python**.
Contents ******** * :func:`call_commandline()` * :class:`Mallet` * :func:`call_mallet()` * :func:`import_corpus()` * :func:`train_topics()`
"""
format='%(levelname)s %(name)s: %(message)s')
return [line.decode('utf-8').replace('\n', '') for line in stdout]
if stdin == 'pipe': stdin = PIPE if stdout == 'pipe': stdout = PIPE if stderr == 'pipe': stderr = PIPE
cmd = [str(arg) for arg in cmd] log.info("Calling the command-line with {} ...".format(' '.join(cmd))) log.debug("stdin = {}".format(stdin)) log.debug("stdout = {}".format(stdout)) log.debug("stderr = {}".format(stderr))
p = Popen(cmd, stdin=stdin, stdout=stdout, stderr=stderr) decoded_stderr = _decode_stdout(p.stderr)
if communicate: log.info("Check mallet.log in {} for logging.".format(os.getcwd())) with open('mallet.log', 'w', encoding='utf-8') as file: else: elif p.returncode != 0: else: log.debug(decoded_stdout)
if not re.search(r'\s', str(string)): return True else:
"Either place the executable into the $PATH or call " "{1}(executable='/path/to/mallet')").format(executable, self.__class__.__name__)) if temp_output is None: prefix = ''.join([random.choice(string.ascii_letters + string.digits) for n in range(5)]) temp_output = os.path.join(tempfile.gettempdir(), prefix)
if not all(_check_whitespace(arg) for arg in args): raise ValueError("Whitespaces are not allowed in {}".format(args))
|