source: other-projects/is-sheet-music-encore/trunk/java-gen-corpus/TabRndListGen.java@ 33031

Last change on this file since 33031 was 33031, checked in by cpb16, 5 years ago

Completed numpages checking. Generated makefiles and scripts to streamline process. Need to now fix 'no such file or directory error from the RUN-META.sh file'.

File size: 1.8 KB
Line 
1//NAME:Caleb Bird
2//ID: 1289680
3//??References??
4
5import java.io.BufferedReader;
6import java.io.FileReader;
7import java.io.FileWriter;
8import java.util.*;
9
10public class TabRndListGen {
11 public static void main(String[] args) {
12 try{
13 if (args.length != 3){
14 System.out.println("Usage: TabRndListGen <inputFilename> <outputCount> <outputFilename>");
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;
29 String[] item;
30
31 //Add items to Array
32 while ((line = buf.readLine()) != null) {
33 //Split line by tab
34 item = line.split("\t", -1);
35 //Add first element (ID)
36 list.add(item[0]);
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
Note: See TracBrowser for help on using the repository browser.