.txtファイルからウィキペディアのページビュー統計ファイルを読み取るプログラムに取り組んでいます。これまでのところ、次のようにこのファイルを読み取るloadメソッドがあります。
public void loadPVSF(String x) throws FileNotFoundException, IOException {
FileInputStream f = new FileInputStream(x); //obtains bytes from an input file
DataInputStream in = new DataInputStream(f); //reads primitive java types
BufferedReader br = new BufferedReader(new InputStreamReader(in));
while ((temp = br.readLine()) != null) {
tempArray = temp.split("\n"); //adds each line to an array tempArray
for (String st : tempArray) //puts each element of tempArray through String st
{
MainArray = st.split(" "); //adds each string after a " " to MainArray
for (String str : MainArray) {
if(linecounter<5){
linecounter++;
System.out.println(linecounter + ": " + str);
これを実行すると、これは次のコマンドライン出力のサンプルです。
1: commons.m
2: Category:Gracie_Gold
3: 1
4: 7406
1: commons.m
2: Category:Grad_Maribor
3: 1
4: 7324
1: commons.m
2: Category:Grade_II*_listed_houses_in_Cheshire
3: 1
4: 7781
基本的に、4行の各セットは次のとおりです。
1 - Language/Project
2 - Article Title
3 - Number of Page views
4 - Size of the Page (bytes)
これらの各読み込み行を正しく割り当てる方法を知る必要があります。基本的に、最終的に必要なのは、記事のタイトルとそれに対応するビュー数のリストを格納するハッシュテーブルです。これにより、ビュー数が最も多いものを特定できます。
ヒントやアドバイスをいただければ幸いです。
入力.txtファイルのサンプル:
nl Andreas_(apostel)7 103145 nl Andreas_Baader 4 46158 nl Andreas_Bjelland 2 28288 nl Andreas_Burnier 2 11545 nl Andreas_Charles_van_Braam_Houckgeest 1 10373 nl Andreas_Eschbach 1 365 nl Andreas_Grassl 1 365