Diff of /scripts/metamappdr.java [000000] .. [c09aa8]

Switch to unified view

a b/scripts/metamappdr.java
1
import java.util.*;
2
import java.io.*;
3
import gov.nih.nlm.nls.skr.*;
4
public class metamappdr {
5
  static GenericObject gj = new GenericObject();
6
  public static void main(String[] args) throws Exception {
7
    Scanner in = new Scanner(new File("cleaned_pdr_data.csv"));
8
    PrintWriter out = new PrintWriter(new File("outputpdr.csv"));
9
    while (in.hasNext()) {
10
      String line = in.nextLine();
11
      boolean inQuotes = false;
12
      boolean inApos = false;
13
      ArrayList<String> terms = new ArrayList<String>();
14
      String term = "";
15
      for (int i = 0; i < line.length(); i++) {
16
        if (line.charAt(i) != ',' || inQuotes) {
17
          if (line.charAt(i) == '\"') inQuotes = !inQuotes;
18
          else term = term + line.charAt(i);
19
        }
20
        else {
21
          if (!inQuotes) {terms.add(term); term = "";}
22
        }
23
      }
24
      terms.add(term);
25
      out.print(terms.get(0) + "," + terms.get(1) + "," + terms.get(2) + ",\"[");
26
      ArrayList<String> indications = new ArrayList<String>();
27
      String indication = "";
28
      for (int i = 1; i < terms.get(3).length()-1; i++) {
29
        if (terms.get(3).charAt(i) != ',' || inApos) {
30
          if (terms.get(3).charAt(i) == '\'') inApos = !inApos;
31
          else indication = indication + terms.get(3).charAt(i);
32
        }
33
        else {
34
          if (!inApos) {indications.add(indication); indication = "";}
35
        }
36
      }
37
      indications.add(indication);
38
      for (String ind : indications) {
39
        PrintWriter tmp = new PrintWriter(new File("input.txt"));
40
        tmp.print(ind);
41
        tmp.close();
42
        out.print('\'' + getMetamap() + "\',");
43
      }
44
      out.print("]\",\"[");
45
      inApos = false;
46
      ArrayList<String> contrainds = new ArrayList<String>();
47
      String contraind = "";
48
      for (int i = 1; i < terms.get(4).length()-1; i++) {
49
        if (terms.get(4).charAt(i) != ',' || inApos) {
50
          if (terms.get(4).charAt(i) == '\'') inApos = !inApos;
51
          else contraind = contraind + terms.get(4).charAt(i);
52
        }
53
        else {
54
          if (!inApos) {contrainds.add(contraind); contraind = "";}
55
        }
56
      }
57
      contrainds.add(contraind);
58
      for (int i = 0; i < contrainds.size(); i++) {
59
        PrintWriter tmp = new PrintWriter(new File("input.txt"));
60
        tmp.print(contrainds.get(i));
61
        tmp.close();
62
        out.print('\'' + getMetamap() + "\'");
63
        if (i < contrainds.size() - 1) out.print(",");
64
      }
65
      out.print("]\"");
66
      out.println();
67
    }
68
    in.close();
69
    out.close();
70
  }
71
  static String getMetamap() {
72
    gj.setField("Email_Address", "neilmalur@hotmail.com");
73
    gj.setFileField("UpLoad_File", "./input.txt");
74
    //gj.setField("APIText", input);
75
    //gj.setField("Batch_Command", "MTI -opt1L_DCMS -E");
76
    gj.setField("Batch_Command", "metamap -pcI");
77
    gj.setField("BatchNotes", "SKR Web API test");
78
    gj.setField("SilentEmail", true);
79
    return gj.handleSubmission();
80
  }
81
}