I've installed syntaxnet and am able to run the parser with the provided demo script. Ideally, I would like to run it directly from python. The only code I found was this:
import subprocess
import os
os.chdir(r"../models/syntaxnet")
subprocess.call([
"echo 'Bob brought the pizza to Alice.' | syntaxnet/demo.sh"
], shell = True)
which is a complete disaster - inefficient and over-complex (calling python from python should be done with python).
How can I call the python APIs directly, without going through shell scripts, standard I/O, etc?
EDIT - Why isn't this as easy as opening syntaxnet/demo.sh and reading it?
This shell script calls two python scripts (parser_eval and conll2tree) which are written as python scripts and can't be imported into a python module without causing multiple errors. A closer look yields additional script-like layers and native code. These upper layers need to be refactored in order to run the whole thing in a python context. Hasn't anyone forked syntaxnet with such a modification or intend to do so?
All in all it doesn't look like it would be a problem to refactor the two scripts demo.sh runs (https://github.com/tensorflow/models/blob/master/syntaxnet/syntaxnet/parser_eval.py and https://github.com/tensorflow/models/blob/master/syntaxnet/syntaxnet/conll2tree.py) into a Python module that exposes a Python API you can call.
Both scripts use Tensorflow's tf.app.flags API (described here in this SO question: What's the purpose of tf.app.flags in TensorFlow?), so those would have to be refactored out to regular arguments, as
tf.app.flagsis a process-level singleton.So yeah, you'd just have to do the work to make these callable as a Python API :)