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