[33007] | 1 | //NAME:Caleb Bird
|
---|
| 2 | //ID: 1289680
|
---|
| 3 | //??References??
|
---|
| 4 |
|
---|
| 5 | import java.io.BufferedReader;
|
---|
| 6 | import java.io.FileReader;
|
---|
| 7 | import java.io.FileWriter;
|
---|
| 8 | import java.util.*;
|
---|
| 9 |
|
---|
| 10 | public class TabRndListGen {
|
---|
| 11 | public static void main(String[] args) {
|
---|
| 12 | try{
|
---|
| 13 | if (args.length != 3){
|
---|
[33031] | 14 | System.out.println("Usage: TabRndListGen <inputFilename> <outputCount> <outputFilename>");
|
---|
[33007] | 15 | }
|
---|
| 16 | else{
|
---|
| 17 | String inputFilename = args[0];
|
---|
| 18 | int outputCount = Integer.parseInt(args[1]);
|
---|
| 19 | String outputFilename = args[2];
|
---|
| 20 |
|
---|
| 21 | BufferedReader buf = new BufferedReader(new FileReader(inputFilename));
|
---|
| 22 | FileWriter fw = new FileWriter(outputFilename);
|
---|
| 23 | //FileWriter fw = new FileWriter("hathiRndIDList.txt");
|
---|
| 24 | //BufferedReader buf = new BufferedReader(new FileReader("hathiDocIDList.txt"));
|
---|
| 25 |
|
---|
| 26 | ArrayList<String> list = new ArrayList<String>();
|
---|
| 27 | ArrayList<String> subList;
|
---|
| 28 | String line = null;
|
---|
[33031] | 29 | String[] item;
|
---|
[33007] | 30 |
|
---|
| 31 | //Add items to Array
|
---|
| 32 | while ((line = buf.readLine()) != null) {
|
---|
[33031] | 33 | //Split line by tab
|
---|
| 34 | item = line.split("\t", -1);
|
---|
| 35 | //Add first element (ID)
|
---|
| 36 | list.add(item[0]);
|
---|
[33007] | 37 | }
|
---|
| 38 | //randomize list
|
---|
| 39 | Collections.shuffle(list);
|
---|
| 40 |
|
---|
| 41 | //Take <outputCount>
|
---|
| 42 | subList = new ArrayList<String>(list.subList(0,outputCount));
|
---|
| 43 |
|
---|
| 44 | //Write these to new file
|
---|
| 45 | for(int i =0; i < subList.size(); i++){
|
---|
| 46 | fw.write(subList.get(i) + '\n');
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | buf.close();
|
---|
| 50 | fw.close();
|
---|
| 51 | }
|
---|
| 52 | }catch(Exception e){
|
---|
| 53 | e.printStackTrace();
|
---|
| 54 | }
|
---|
| 55 | }
|
---|
| 56 | }
|
---|
| 57 | // Returns 42474
|
---|
| 58 |
|
---|
| 59 | //REFERNECES
|
---|
| 60 | //https://www.javatpoint.com/java-filewriter-class
|
---|
| 61 | //https://docs.oracle.com/javase/8/docs/api/index.html?java/io/FileWriter.html
|
---|
| 62 | //https://www.geeksforgeeks.org/randomly-select-items-from-a-list-in-java/
|
---|
| 63 | //https://codereview.stackexchange.com/questions/146551/picking-10-distinct-words-randomly-from-list-of-unique-words
|
---|
| 64 |
|
---|
| 65 | //USE RUN-LIST.txt (modify file it reads using $1 (terminal entry variable (filename))
|
---|
| 66 |
|
---|