-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
01d193b
commit 2761f88
Showing
2 changed files
with
1,379 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Oops, something went wrong.