错误: 非法的表达式,求救。
以下红字部分出问题,但是感觉语法没有错误,求解,请帮忙修改,或请解释详细一点,我真的很笨,是菜鸟。谢谢!
public Vector<String> extractWord(Vector<String> allRelations) {
Vector<String> allWords = new Vector<String>();
for (String str : allRelations) {
if (str.startsWith("pos")&& !str.contains("punctuation")) {
allWords.add(str.substring(str.indexOf("(")+1, str.indexOf(",")));
}
}
return allWords;
}
public static void main(String [] args){
public class Test { // 361: 错误: 非法的表达式开始
ExtractRelationForWord test=new ExtractRelationForWord();
Vector<String> allRelations=Dictionnaire.readLine("data/testData/1~", "GBK");
Vector<String> allWords=test.extractWord(allRelations);
for(String word: allWords){ // 365: 错误: 非法的类型开始
Vector<String> relations=test.extract(allRelations, word);
Vector<RelationExample> formalization=test.relationFormalization(relations);
WordNode temp=test.extractWordNode(formalization, word);
System.out.print(temp.toString());
System.out.println("************\n");
}
}
}
------解决方案--------------------这个是否是楼主想要的代码段呢
public class Test { // 将class声明在外面
public static void main(String [] args){ // 写main方法
ExtractRelationForWord test=new ExtractRelationForWord();
Vector<String> allRelations=Dictionnaire.readLine("data/testData/1~", "GBK");
Vector<String> allWords=test.extractWord(allRelations);
for(String word: allWords) { // 此时for 循环便不再出错了
Vector<String> relations=test.extract(allRelations, word);
Vector<RelationExample> formalization=test.relationFormalization(relations);
WordNode temp=test.extractWordNode(formalization, word);
System.out.print(temp.toString());
System.out.println("************\n");
}
}
}