Python子进程调用预编译的Java

阿图里·比约克(ArtturiBjörk)

这可以从Windows命令行运行:

c:\mallet\bin\mallet run

我试过了

subprocess.call(['c:\mallet\bin\mallet', 'run'])

并得到一个错误

WindowsError: [Error 2] The system cannot find the file specified

我已经尝试过

subprocess.call(['c:/mallet/bin/mallet', 'run'])

并得到错误

WindowsError: [Error 193] %1 is not a valid Win32 application

我必须传递给subprocess.call()什么?

为了完整起见,我想传递的完整命令是:

bin\mallet run cc.mallet.topics.tui.DMRLoader texts.txt features.txt instance.mallet

我模糊的想法是,这是一个我已经以某种方式调用的预编译的Java类,但是我真的不明白我在这里做什么。

这是文件夹中的两个槌文件bin

mallet.bat

@echo off

rem This batch file serves as a wrapper for several
rem  MALLET command line tools.

if not "%MALLET_HOME%" == "" goto gotMalletHome

echo MALLET requires an environment variable MALLET_HOME.
goto :eof

:gotMalletHome

set MALLET_CLASSPATH=%MALLET_HOME%\class;%MALLET_HOME%\lib\mallet-deps.jar
set MALLET_MEMORY=1G
set MALLET_ENCODING=UTF-8

set CMD=%1
shift

set CLASS=
if "%CMD%"=="import-dir" set CLASS=cc.mallet.classify.tui.Text2Vectors
if "%CMD%"=="import-file" set CLASS=cc.mallet.classify.tui.Csv2Vectors
if "%CMD%"=="import-smvlight" set CLASS=cc.mallet.classify.tui.SvmLight2Vectors
if "%CMD%"=="train-classifier" set CLASS=cc.mallet.classify.tui.Vectors2Classify
if "%CMD%"=="train-topics" set CLASS=cc.mallet.topics.tui.Vectors2Topics
if "%CMD%"=="infer-topics" set CLASS=cc.mallet.topics.tui.InferTopics
if "%CMD%"=="estimate-topics" set CLASS=cc.mallet.topics.tui.EstimateTopics
if "%CMD%"=="hlda" set CLASS=cc.mallet.topics.tui.HierarchicalLDATUI
if "%CMD%"=="prune" set CLASS=cc.mallet.classify.tui.Vectors2Vectors
if "%CMD%"=="split" set CLASS=cc.mallet.classify.tui.Vectors2Vectors
if "%CMD%"=="bulk-load" set CLASS=cc.mallet.util.BulkLoader
if "%CMD%"=="run" set CLASS=%1 & shift

if not "%CLASS%" == "" goto gotClass

echo Mallet 2.0 commands: 
echo   import-dir        load the contents of a directory into mallet instances (one per file)
echo   import-file       load a single file into mallet instances (one per line)
echo   import-svmlight   load a single SVMLight format data file into mallet instances (one per line)
echo   train-classifier  train a classifier from Mallet data files
echo   train-topics      train a topic model from Mallet data files
echo   infer-topics      use a trained topic model to infer topics for new documents
echo   estimate-topics   estimate the probability of new documents given a trained model
echo   hlda              train a topic model using Hierarchical LDA
echo   prune             remove features based on frequency or information gain
echo   split             divide data into testing, training, and validation portions
echo Include --help with any option for more information


goto :eof

:gotClass

set MALLET_ARGS=

:getArg

if "%1"=="" goto run
set MALLET_ARGS=%MALLET_ARGS% %1
shift
goto getArg

:run

java -Xmx%MALLET_MEMORY% -ea -Dfile.encoding=%MALLET_ENCODING% -classpath %MALLET_CLASSPATH% %CLASS% %MALLET_ARGS%

:eof

mallet

#!/bin/bash


malletdir=`dirname $0`
malletdir=`dirname $malletdir`

cp=$malletdir/class:$malletdir/lib/mallet-deps.jar:$CLASSPATH
#echo $cp

MEMORY=1g

JAVA_COMMAND="java -Xmx$MEMORY -ea -Djava.awt.headless=true -Dfile.encoding=UTF-8 -server -classpath $cp"

CMD=$1
shift

help()
{
cat <<EOF
Mallet 2.0 commands: 

  import-dir         load the contents of a directory into mallet instances (one per file)
  import-file        load a single file into mallet instances (one per line)
  import-svmlight    load SVMLight format data files into Mallet instances
  train-classifier   train a classifier from Mallet data files
  classify-dir       classify data from a single file with a saved classifier
  classify-file      classify the contents of a directory with a saved classifier
  classify-svmlight  classify data from a single file in SVMLight format
  train-topics       train a topic model from Mallet data files
  infer-topics       use a trained topic model to infer topics for new documents
  evaluate-topics    estimate the probability of new documents under a trained model
  hlda               train a topic model using Hierarchical LDA
  prune              remove features based on frequency or information gain
  split              divide data into testing, training, and validation portions

Include --help with any option for more information
EOF
}

CLASS=

case $CMD in
    import-dir) CLASS=cc.mallet.classify.tui.Text2Vectors;;
    import-file) CLASS=cc.mallet.classify.tui.Csv2Vectors;;
        import-svmlight) CLASS=cc.mallet.classify.tui.SvmLight2Vectors;;
    train-classifier) CLASS=cc.mallet.classify.tui.Vectors2Classify;;
        classify-dir) CLASS=cc.mallet.classify.tui.Text2Classify;;
        classify-file) CLASS=cc.mallet.classify.tui.Csv2Classify;;
        classify-svmlight) CLASS=cc.mallet.classify.tui.SvmLight2Classify;;
    train-topics) CLASS=cc.mallet.topics.tui.Vectors2Topics;;
    infer-topics) CLASS=cc.mallet.topics.tui.InferTopics;;
    evaluate-topics) CLASS=cc.mallet.topics.tui.EvaluateTopics;;
    hlda) CLASS=cc.mallet.topics.tui.HierarchicalLDATUI;;
    prune) CLASS=cc.mallet.classify.tui.Vectors2Vectors;;
    split) CLASS=cc.mallet.classify.tui.Vectors2Vectors;;
    bulk-load) CLASS=cc.mallet.util.BulkLoader;;
    run) CLASS=$1; shift;;
    *) echo "Unrecognized command: $CMD"; help; exit 1;;
esac

$JAVA_COMMAND $CLASS $*
西尔万·勒鲁(Sylvain Leroux)

当调用程序不带扩展名,Windows外壳程序会尝试几种标准的扩展名(.BAT.EXE,...),以你试图调用该文件。

如果要在没有外壳的情况下执行程序来执行该查找阶段,则需要传递要执行的批处理的全名-包括。.BAT扩展:

subprocess.call(['c:/mallet/bin/mallet.bat', 'run'])

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

python子进程错误调用java类

来自分类Dev

Python子进程调用挂起?

来自分类Dev

Python子进程调用挂起?

来自分类Dev

带有变量的Python子进程调用

来自分类Dev

Python子进程无法调用“ ssh”

来自分类Dev

调用Python脚本作为子进程

来自分类Dev

带有变量的Python子进程调用

来自分类Dev

python子进程对irfanview的调用失败

来自分类Dev

直到调用进程完成,Python子进程才会运行

来自分类Dev

我可以预编译python脚本吗?

来自分类Dev

编译失败:子进程失败

来自分类Dev

从另一个文件调用预编译模块

来自分类Dev

Python:shell = False的子进程调用不起作用

来自分类Dev

Mac OSX中的Python ctags子进程调用

来自分类Dev

调用子进程后,Python脚本未继续

来自分类Dev

子进程调用Python中的更多<运算符

来自分类Dev

Python:使用子进程调用ffmpeg命令行

来自分类Dev

从Django子进程调用python,找不到mysql错误

来自分类Dev

是否可以使用python子进程调用登录shell?

来自分类Dev

Python子进程调用不起作用

来自分类Dev

通过Python子进程调用打开程序时的警告

来自分类Dev

调用子进程后,Python脚本未继续

来自分类Dev

使用子进程调用带有参数的python脚本

来自分类Dev

从 Python 子进程调用 perl 脚本中的 GetOptions

来自分类Dev

linux os 中的 Python 子进程调用未按预期工作

来自分类Dev

从python的子进程连续调用shell命令并解析输出

来自分类Dev

在for循环中使用变量调用Python子进程

来自分类Dev

通过 crontab 调用 Python 子进程不起作用

来自分类Dev

python子进程-分离进程