我想結合這兩種方法在我的文檔分析器frequencyCounter和parseFiles中只是出現了一些錯誤代碼。在Java代碼中將Java中的兩種方法結合在一起
我希望所有的frequencyCounter應該是一個函數,應該從parseFiles內執行,相關信息不用擔心文件的內容應該傳遞給doSomething,以便它知道要打印什麼。
現在我只是保持瞭如何將這兩種方法放在一起搞亂了,請給一些建議
這是我的主類:
public class Yolo {
public static void frodo() throws Exception {
int n; // number of keywords
Scanner sc = new Scanner(System.in);
System.out.println("number of keywords : ");
n = sc.nextInt();
for (int j = 0; j <= n; j++) {
Scanner scan = new Scanner(System.in);
System.out.println("give the testword : ");
String testWord = scan.next();
System.out.println(testWord);
File document = new File("path//to//doc1.txt");
boolean check = true;
try {
FileInputStream fstream = new FileInputStream(document);
BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
String strLine;
strLine = br.readLine();
// Read File Line By Line
int count = 0;
while ((strLine = br.readLine()) != null) {
// check to see whether testWord occurs at least once in the
// line of text
check = strLine.toLowerCase().contains(testWord.toLowerCase());
if (check) {
// get the line
String[] lineWords = strLine.split("\\s+");
// System.out.println(strLine);
count++;
}
}
System.out.println(testWord + "frequency: " + count);
br.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
你的CosineSimilarity()和TfIdf()在哪裏? – Nuwanda