[英]Executing java program by command line argument
I am working on stanford code nlp package to get sentiment result. 我正在研究斯坦福代码nlp包以获取情感结果。
In execution I need to give the text file name as a input. 在执行中,我需要提供文本文件名作为输入。
java -cp stanford-corenlp-3.3.0.jar;stanford-corenlp-3.3.0-models.jar;xom.jar;joda-time.jar -Xmx600m edu.stanford.nlp.pipeline.StanfordCoreNLP -annotators tokenize,ssplit,pos,lemma,parse -file input.txt
input.txt contains some text. input.txt包含一些文本。
Can some one tell me here how can I pass string text directly rather giving a file name input.txt
? 有人可以在这里告诉我如何直接传递字符串文本而不是给文件名
input.txt
吗?
You would need to modify your main program in such a way that it reads from arguments. 您需要以一种从参数读取的方式修改主程序。
eg: 例如:
public static void main(String args[]){
// here args[] will contain you input strings
//check null for args
//args[0] --> -annotators
//args[1] --> values of -annotators
//args[2] --> /file or -inputs
//args[3] to args[length] --> you input text
for(int i=3;i<args.length;i++){
System.out.println(args[i]);
}
And then your command line appears as 然后您的命令行显示为
java -cp stanford-corenlp-3.3.0.jar;stanford-corenlp-3.3.0-models.jar;xom.jar;joda-time.jar -Xmx600m edu.stanford.nlp.pipeline.StanfordCoreNLP -annotators tokenize,ssplit,pos,lemma,parse -inputs this is my input text
java -cp stanford-corenlp-3.3.0.jar; stanford-corenlp-3.3.0-models.jar; xom.jar; joda-time.jar -Xmx600m edu.stanford.nlp.pipeline.StanfordCoreNLP -annotators标记化,分割,pos,引理,解析-inputs这是我的输入文字
Note: you would need to provide validations 注意:您需要提供验证
Warning: I haven't tried this ... 警告:我还没有尝试过...
If you run StanfordCoreNLP with neither -file
or -filelist
arguments, it runs as a "shell", reading input from stdin until it sees a q
. 如果您不使用
-file
或-filelist
参数运行StanfordCoreNLP,则它将作为“外壳”运行,从stdin读取输入,直到看到q
为止。 So you might be able to do this: 因此,您可以执行以下操作:
$ ( echo "text to be parsed" ; echo q ) | \
java -cp ... edu.stanford.nlp.pipeline.StanfordCoreNLP ...
But IMO it is cleaner if you send the text to a file and then use the application as it was designed to be used; 但是,如果将文本发送到文件中,然后按照设计使用的方式使用该应用程序,则IMO更加干净。 eg
例如
$ echo "text to be parsed" > /tmp/input
$ java -cp ... edu.stanford.nlp.pipeline.StanfordCoreNLP ... -file /tmp/input
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.