[c09aa8]: / scripts / ctsamplemetamap.java

Download this file

66 lines (65 with data), 2.4 kB

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