2文を含むファイルを読み込んで比較し、0と1の間の数値を返す必要があります。文がまったく同じ場合は、真となるように1を返します。それらが完全に反対の場合は、falseの場合は0を返します。文が似ているが、単語が類義語または近いものに変更された場合は.25または.75を返します。読み込みファイルからの文章の比較 - Java
______________________________________ Text: Sample Text 1: It was a dark and stormy night. I was all alone sitting on a red chair. I was not completely alone as I had three cats. Text 20: It was a murky and stormy night. I was all alone sitting on a crimson chair. I was not completely alone as I had three felines // Should score high point but not 1 Text 21: It was a murky and tempestuous night. I was all alone sitting on a crimson cathedra. I was not completely alone as I had three felines // Should score lower than text20 Text 22: I was all alone sitting on a crimson cathedra. I was not completely alone as I had three felines. It was a murky and tempestuous night. // Should score lower than text21 but NOT 0 Text 24: It was a dark and stormy night. I was not alone. I was not sitting on a red chair. I had three cats. // Should score a 0! ________________________________________________
は、私は、ファイルリーダーを持っているが、私はそれらを比較できるように各行を格納するための最良の方法を確認していない:テキストファイルは次のようにフォーマットされます。今のところ私はファイルを読み込み、スクリーンに印刷しています。これらを保管して比較して、自分の希望する番号を取得する最良の方法は何ですか?
import java.io.*;
public class implement
{
public static void main(String[] args)
{
try
{
FileInputStream fstream = new FileInputStream("textfile.txt");
DataInputStream in = new DataInputStream (fstream);
BufferedReader br = new BufferedReader (new InputStreamReader(in));
String strLine;
while ((strLine = br.readLine()) != null)
{
System.out.println (strLine);
}
in.close();
}
catch (Exception e)
{
System.err.println("Error: " + e.getMessage());
}
}
}
これらは完全に2つの異なるものです。あなたが求めていることを具体的に記述してください。(1)ファイルからデータを保存する方法? ** OR **(2)2つの文字列を比較して、そのスコアがどのようなものでなければならないのですか?この場合、私たちはあなたの最初の考えとあなたがすでに試したことについての説明を聞くべきであり、それはなぜ失敗するのですか? – amit
また、主に2つの理由でクラス 'implement'を命名しないでください:(1)意味のある名前をつけて、それが何をするかを記述します。 (2)javaの規約では、クラス名は大文字で始まり、 'implement'は小文字で始まります。\ – amit
各行を文字列として保存するにはどうすればよいでしょうか?== – mrjeck2