Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
lichenliang-whu authored Aug 1, 2017
1 parent 01d193b commit 2761f88
Show file tree
Hide file tree
Showing 2 changed files with 1,379 additions and 0 deletions.
56 changes: 56 additions & 0 deletions src/Document.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package PDMM_GPU_LCL;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Document {

public String [] words;
public int id;
public String category;


public Document(int docid, String category, String [] words){
this.id = docid;
this.category = category;
this.words = words;
}

public static ArrayList<Document> LoadCorpus(String filename){
try{
FileInputStream fis = new FileInputStream(filename);
InputStreamReader isr = new InputStreamReader(fis, "UTF-8");
BufferedReader reader = new BufferedReader(isr);
String line;
ArrayList<Document> doc_list = new ArrayList();
while((line = reader.readLine()) != null){
line = line.trim();
String[] items = line.split("\t");
int docid = Integer.parseInt(items[0]);
String[] others = items[1].split("\\|");
String category = others[0];
String words_str = others[1].trim();
String[] words = words_str.split("\\s");
Document doc = new Document(docid, category, words);
doc_list.add(doc);
}
return doc_list;
}
catch (Exception e){
System.out.println("Error while reading other file:" + e.getMessage());
e.printStackTrace();
// return false;
}
return null;

}

public static void main(String[] args) {
// TODO 自动生成的方法存根
String [] sarray = {"科技","专科","西安","大学"};
Document doc = new Document(1, "院校信息", sarray);
System.out.println(doc.id);
}
}
Loading

0 comments on commit 2761f88

Please sign in to comment.