- Timestamp:
- 2019-05-02T14:51:03+12:00 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
other-projects/is-sheet-music-encore/trunk/java-gen-corpus/TabRndListGen.java
r33031 r33044 6 6 import java.io.FileReader; 7 7 import java.io.FileWriter; 8 import java.io.*; 8 9 import java.util.*; 9 10 … … 25 26 26 27 ArrayList<String> list = new ArrayList<String>(); 27 ArrayList<String> subList;28 28 29 String line = null; 29 30 String[] item; … … 38 39 //randomize list 39 40 Collections.shuffle(list); 40 41 //Take <outputCount> 42 subList = new ArrayList<String>(list.subList(0,outputCount)); 41 42 int countMatchingCrit = 0; 43 int j = 0; 44 ArrayList<String> subList = new ArrayList<String>(); 45 //Download meta record, check if numpages >=10 46 while(countMatchingCrit < outputCount){ 47 System.out.println("Processing item: " + j); 48 String idCurr = list.get(j); 49 //run download script 50 String cmd = "./download_metadata_temp.sh " + idCurr; 51 Process p = Runtime.getRuntime().exec(cmd); 52 /*BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream())); 53 while(br.ready()) 54 { 55 System.out.println(br.readLine()); 56 }*/ 57 p.waitFor(); 58 int exitStatus = p.exitValue(); 59 if(exitStatus == 0){ 60 //Extract numpages 61 int numpages = getNumPages(idCurr); 62 if(numpages >= 10){ 63 System.out.println("Successful items: " + countMatchingCrit); 64 countMatchingCrit++; 65 subList.add(idCurr); 66 } 67 } 68 else{ 69 System.err.println("failed to run:" + cmd); 70 System.exit(exitStatus); 71 } 72 j++; 73 if(j >= list.size()){break;} 74 } 75 43 76 44 77 //Write these to new file … … 54 87 } 55 88 } 89 private static int getNumPages(String id){ 90 String numpages = null; 91 try{ 92 //Variables 93 String inputFilename = "metadata_temp.xml"; 94 FileReader fileReader = new FileReader(inputFilename); 95 BufferedReader buf = new BufferedReader(fileReader); 96 String line = null; 97 String[] item; 98 99 //Splits into each record 100 while ((line = buf.readLine()) != null) { 101 /* 102 if(line.contains("<id>")){ 103 //Isoclate and store the id from the line 104 idLine = line.substring(line.indexOf(">")+1, line.indexOf("</")); 105 id = idLine.substring(idLine.lastIndexOf("meta/")+5); 106 107 } 108 */ 109 if(line.contains("<htd:numpages>")){ 110 //Iscolate and store the page number 111 numpages = line.substring(line.indexOf(">")+1, line.lastIndexOf("<")); 112 113 } 114 } 115 buf.close(); 116 //Check if there are more than 10 pages 117 118 }catch(Exception e){ 119 e.printStackTrace(); 120 } 121 return Integer.parseInt(numpages); 122 } 56 123 } 57 124 // Returns 42474 58 125 59 126 //REFERNECES 127 //https://stackoverflow.com/questions/12892665/how-to-capture-the-exit-status-of-a-shell-command-in-java 60 128 //https://www.javatpoint.com/java-filewriter-class 61 129 //https://docs.oracle.com/javase/8/docs/api/index.html?java/io/FileWriter.html 62 130 //https://www.geeksforgeeks.org/randomly-select-items-from-a-list-in-java/ 63 131 //https://codereview.stackexchange.com/questions/146551/picking-10-distinct-words-randomly-from-list-of-unique-words 132 //http://www.linuxforums.org/forum/programming-scripting/65117-c-c-system-function-analog-java.html 64 133 65 134 //USE RUN-LIST.txt (modify file it reads using $1 (terminal entry variable (filename))
Note:
See TracChangeset
for help on using the changeset viewer.