我有一个 java 代码,其中 parse 方法将一个数组返回给 main 方法。这个数组被传递给 Parsedanalysis 类的 OutputFilter 方法。但是 OutputFilter 方法无法使用这个数组。当我尝试打印出 myArray[] 时,它可以工作。但没有其他工作输出只是显示构建成功。我不明白。您能否提供一个解决方案。
提前致谢。
public class Parser {
public static void main(String args[]) throws IOException, InterruptedException
{
String[] parseOutput;
parseOutput = parse();
Parsedanalysis p =new Parsedanalysis();
p.OutputFilter(parseOutput);
System.out.println("Output returned array"); //Output Verification//
for(int i=0;i<parseOutput.length;i++)
{ System.out.println(parseOutput[i]);
}
}
public synchronized static String[] parse() throws IOException, InterruptedException
{
{
String[] output = new String[20];
int i=0;
String command = "cmd /k cd C:\\Program Files\\stanford-parser-2012-11-12 & "
+ "set CLASSPATH=.;stanford-parser.jar;stanford-parser-2.0.4-models.jar & "
+ "java -mx100m edu.stanford.nlp.parser.lexparser.LexicalizedParser edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz data/testsent.txt"; //without typed dependencies
Process pr = Runtime.getRuntime().exec(command);
BufferedReader reader=new BufferedReader(new InputStreamReader(pr.getInputStream()));
String line = reader.readLine();
System.out.println("Output array");
for(i=0;!(line=reader.readLine()).isEmpty() && i<20;i++)
{
output[i]=line;
System.out.println("Position"+i+output[i]);
}
// System.out.println("stopped");
reader.close();
return(output);
}
public class Parsedanalysis {
static int start = 0;
static int end;
static String[] POS,SUB,array;
/**
*
* @param myArray
* @throws IOException
* @throws InterruptedException
*/
public synchronized void OutputFilter(String[] myArray) throws IOException, InterruptedException
{
int l=0;
try{
System.out.println("Parsedanalysis Recieves..");
for(int k=0;k<myArray.length;k++)
{
//System.arraycopy(myArray, 0, array, 0, myArray.length); /*doesn't work beyond this point*/
System.out.println(myArray[k]);
//array[k] = myArray[k];
}
for(int i=0;i<myArray.length;i++)
{
if(myArray[i].contains("(") && myArray[i].contains(")") )
{
System.arraycopy(myArray, i, SUB, l, 1);
//SUB[l]=myArray[i];
l++;
}
System.out.println(SUB[l]);
}