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 PagedJSONForeach extends BasePerJSON implements VoidFunction<JSONObject>
|
---|
22 | //public class PagedJSON implements VoidFunction<String>
|
---|
23 | {
|
---|
24 | private static final long serialVersionUID = 1L;
|
---|
25 |
|
---|
26 | public PagedJSONForeach(String input_dir, String solr_url, String output_dir, int verbosity,
|
---|
27 | DoubleAccumulator progress_accum, double progress_step)
|
---|
28 | {
|
---|
29 | super(input_dir,solr_url,output_dir,verbosity,progress_accum,progress_step);
|
---|
30 | }
|
---|
31 |
|
---|
32 |
|
---|
33 | public void call(JSONObject solr_add_doc_json)
|
---|
34 | {
|
---|
35 | String output_json_bz2 = solr_add_doc_json.getString("filename_json_bz2");
|
---|
36 | solr_add_doc_json.remove("filename_json_bz2");
|
---|
37 |
|
---|
38 | boolean random_test = (Math.random()>0.999); // every 1000
|
---|
39 |
|
---|
40 | if ((_verbosity >=2) && (random_test)) {
|
---|
41 | System.out.println("==================");
|
---|
42 | System.out.println("Sample output Solr add JSON [random test 1/1000]: " + solr_add_doc_json.toString());
|
---|
43 | System.out.println("==================");
|
---|
44 | }
|
---|
45 |
|
---|
46 |
|
---|
47 | if (_solr_url != null) {
|
---|
48 | if ((_verbosity >=2) && (random_test)) {
|
---|
49 | System.out.println("==================");
|
---|
50 | System.out.println("Posting to: " + _solr_url);
|
---|
51 | System.out.println("==================");
|
---|
52 | }
|
---|
53 | JSONSolrTransform.postSolrDoc(_solr_url, solr_add_doc_json);
|
---|
54 | }
|
---|
55 |
|
---|
56 | if (_output_dir != null) {
|
---|
57 | if ((_verbosity >=2) && (random_test)) {
|
---|
58 | System.out.println("==================");
|
---|
59 | System.out.println("Saving to: " + _output_dir);
|
---|
60 | System.out.println("==================");
|
---|
61 | }
|
---|
62 | JSONSolrTransform.saveSolrDoc(solr_add_doc_json, _output_dir + "/" + output_json_bz2);
|
---|
63 | }
|
---|
64 | }
|
---|
65 |
|
---|
66 | }
|
---|
67 |
|
---|