[31011] | 1 | package org.hathitrust.extractedfeatures;
|
---|
| 2 |
|
---|
| 3 | import java.util.ArrayList;
|
---|
| 4 | import java.util.Iterator;
|
---|
| 5 | import org.apache.spark.api.java.function.FlatMapFunction;
|
---|
| 6 | import org.apache.spark.api.java.function.VoidFunction;
|
---|
| 7 | import org.apache.spark.util.DoubleAccumulator;
|
---|
| 8 | import org.json.JSONArray;
|
---|
| 9 | import org.json.JSONObject;
|
---|
| 10 |
|
---|
| 11 | /*
|
---|
| 12 | class PagedJSON implements Function<String, Boolean> {
|
---|
| 13 |
|
---|
| 14 | private static final long serialVersionUID = 1L;
|
---|
| 15 |
|
---|
| 16 | public Boolean call(String s) { return s.contains("a"); }
|
---|
| 17 | }
|
---|
| 18 | */
|
---|
| 19 |
|
---|
| 20 |
|
---|
| 21 | class __PerPageJSONForeach implements VoidFunction<JSONObject>
|
---|
| 22 | //public class PagedJSON implements VoidFunction<String>
|
---|
| 23 | {
|
---|
| 24 | private static final long serialVersionUID = 1L;
|
---|
| 25 |
|
---|
| 26 | protected String _input_dir;
|
---|
| 27 | protected String _solr_url;
|
---|
| 28 | protected String _output_dir;
|
---|
| 29 | protected int _verbosity;
|
---|
| 30 |
|
---|
| 31 | protected DoubleAccumulator _progress_accum;
|
---|
| 32 | protected double _progress_step;
|
---|
| 33 |
|
---|
| 34 |
|
---|
| 35 | public __PerPageJSONForeach(String input_dir, String solr_url, String output_dir, int verbosity,
|
---|
| 36 | DoubleAccumulator progress_accum, double progress_step)
|
---|
| 37 | {
|
---|
| 38 | _input_dir = input_dir;
|
---|
| 39 | _solr_url = solr_url;
|
---|
| 40 | _output_dir = output_dir;
|
---|
| 41 | _verbosity = verbosity;
|
---|
| 42 |
|
---|
| 43 | _progress_accum = progress_accum;
|
---|
| 44 | _progress_step = progress_step;
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | public void call(JSONObject solr_add_doc_json)
|
---|
| 48 | {
|
---|
| 49 | String output_json_bz2 = solr_add_doc_json.getString("filename_json_bz2");
|
---|
| 50 | solr_add_doc_json.remove("filename_json_bz2");
|
---|
| 51 |
|
---|
| 52 | boolean random_test = (Math.random()>0.999); // every 1000
|
---|
| 53 |
|
---|
| 54 | if ((_verbosity >=2) && (random_test)) {
|
---|
| 55 | System.out.println("==================");
|
---|
| 56 | System.out.println("Sample output Solr add JSON [random test 1/1000]: " + solr_add_doc_json.toString());
|
---|
| 57 | System.out.println("==================");
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 |
|
---|
| 61 | if (_solr_url != null) {
|
---|
| 62 | if ((_verbosity >=2) && (random_test)) {
|
---|
| 63 | System.out.println("==================");
|
---|
| 64 | System.out.println("Posting to: " + _solr_url);
|
---|
| 65 | System.out.println("==================");
|
---|
| 66 | }
|
---|
| 67 | SolrDocJSON.postSolrDoc(_solr_url, solr_add_doc_json);
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | if (_output_dir != null) {
|
---|
| 71 | if ((_verbosity >=2) && (random_test)) {
|
---|
| 72 | System.out.println("==================");
|
---|
| 73 | System.out.println("Saving to: " + _output_dir);
|
---|
| 74 | System.out.println("==================");
|
---|
| 75 | }
|
---|
| 76 | SolrDocJSON.saveSolrDoc(solr_add_doc_json, _output_dir + "/" + output_json_bz2);
|
---|
| 77 | }
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | }
|
---|
| 81 |
|
---|