[英]running time error when trying to implent a keyword frequency counter in my parser java
I want to implement my input reading method into my main class, I want use my code to parse. 我想将输入阅读方法实现到我的主类中,我想使用我的代码进行解析。 It's been fixed now. 现在已经修复。 thanks. 谢谢。 String x; 字符串x; int count = -1;= while (str.hasMoreTokens()) { count++; int count = -1; = while(str.hasMoreTokens()){count ++; x = str.nextToken(); x = str.nextToken(); word[count] = x; 字[count] = x; System.out.println(count + ": " + word[count]); System.out.println(count +“:” + word [count]);
}
System.out.println("---Frequency---");
// create unique words
for (int i = 0; i < 7; i++) {
if ((!Arrays.asList(unique).contains(word[i]))) {
unique[i] = word[i];
}
}
// measuring frequency
int[] measure = new int[10];
for (int a = 0; a < 7; a++) {
if (Arrays.asList(unique).contains(word[a])) {
measure[a] += 1;
System.out.println(unique[a] + " : " + measure[a]);
}
}
}
}
private List<String[]> termsDocsArray = new ArrayList<String[]>();
private List<String> allTerms = new ArrayList<String>(); //to hold all terms
private List<double[]> tfidfDocsVector = new ArrayList<double[]>();
/**
To start with your code 从代码开始
String text = "Professor, engineering, data, mining, research";
StringTokenizer str = new StringTokenizer(text);
String word[] = new String[10];
String unique[] = new String[10];
String x;
int count = -1;
while (str.hasMoreTokens()) {
count++;
x = str.nextToken();
word[count] = x;
System.out.println(count + ": " + word[count]);
}
System.out.println("---Frequency---");
// create unique words
for (int i = 0; i < 7; i++) {
if ((!Arrays.asList(unique).contains(word[i]))) {
unique[i] = word[i];
}
}
// measuring frequency
int[] measure = new int[10];
for (int a = 0; a < 7; a++) {
if (Arrays.asList(unique).contains(word[a])) {
measure[a] += 1;
System.out.println(unique[a] + " : " + measure[a]);
}
}
should be in it's own method like . 应该在自己的方法中,例如。
private void doSomething(){
//This variable will hold all terms of each document in an array.
String text = "Professor, engineering, data, mining, research";
StringTokenizer str = new StringTokenizer(text);
String word[] = new String[10];
String unique[] = new String[10];
String x;
int count = -1;
while (str.hasMoreTokens()) {
count++;
x = str.nextToken();
word[count] = x;
System.out.println(count + ": " + word[count]);
}
System.out.println("---Frequency---");
// create unique words
for (int i = 0; i < 7; i++) {
if ((!Arrays.asList(unique).contains(word[i]))) {
unique[i] = word[i];
}
}
// measuring frequency
int[] measure = new int[10];
for (int a = 0; a < 7; a++) {
if (Arrays.asList(unique).contains(word[a])) {
measure[a] += 1;
System.out.println(unique[a] + " : " + measure[a]);
}
}
}
Secondly in ur given code u have written like 其次,在给定的代码中,您写的像
int count = -1;=
which accounts to this error Syntax error on token "=", { expected.It should be 导致此错误的原因令牌“ =“,{预期的语法错误。应该是
int count = -1;
And since all your code is simply written in class without any method so it is giving you the error saying { expected. 而且由于您所有的代码都是简单地在类中编写的,没有任何方法,因此它会给您错误提示{预期。
Please make sure you have copied the code correctly. 请确保您已正确复制代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.