-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMRCONSODictionaryPreparer.java
147 lines (130 loc) · 4.63 KB
/
MRCONSODictionaryPreparer.java
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
/**
* The MRCONSODictionaryPreparer program implements an
* application that constructs a list of records that each
* include the name of a concept, a CUI, a TUI, and the
* semantic type.
*
* @author Kalpana Raja and Troy Cao
*
*/
public class MRCONSODictionaryPreparer {
public static void main(String[] args) throws IOException {
long startTime = System.nanoTime();
String arg1 = args[0]; //input -- mrsty.cuituiGroup2017AB.txt
String arg2 = args[1]; //input -- semgroup_tui2013.txt
String arg3 = args[2]; //input -- mrconso.preferredVocabularies2017AB.txt
String arg4 = args[3]; //output -- umls.metathesaurus.vocabulary2017AB
String arg5 = args[4]; //output -- missedVocabulary2017AB.txt
BufferedReader in1 = new BufferedReader(new FileReader(arg1));
ArrayList<String> mrsemType = new ArrayList<String>();
while(in1.ready()){
String line = in1.readLine();
mrsemType.add(line);
}
in1.close();
BufferedReader in2 = new BufferedReader(new FileReader(arg2));
ArrayList<String> semgrp = new ArrayList<String>();
while(in2.ready()){
String line = in2.readLine();
semgrp.add(line);
}
in2.close();
BufferedReader in = new BufferedReader(new FileReader(arg3));
PrintWriter pwr = new PrintWriter(arg4);
PrintWriter pwr1 = new PrintWriter(arg5);
HashSet<String> terms = new HashSet<String>();
HashMap<String,String> norms = new HashMap<String,String>();
int count=0, count1=0;
String cui="", cui_tui="", semGroup="";
while(in.ready()){
String line = in.readLine();
String[] splits=line.split("\\|");
String term = splits[14];
cui = splits[0];
//remove ending semantic tag such as (disorder) or [Ambiguity] for better matching
if(term.endsWith(")")&&term.matches(".+\\s+\\(\\S+\\)")) term=term.substring(0, term.indexOf("("));
else if(term.endsWith("]")&&term.matches(".+\\s+\\[\\S+\\]")) term=term.substring(0, term.indexOf("["));
if(term.startsWith("\\(") && term.endsWith("\\]")) continue;
else if(term.startsWith("\\[") && term.endsWith("\\]")) continue;
else {
//normalized tokens
String norm = term.toLowerCase();
if(norm.contains(" ")) norm = norm.replaceAll(" ", "\t");
if(norm.contains(",")) norm = norm.replaceAll(",", " ");
if(norm.contains("-")) norm = norm.replaceAll("-", " ");
if(norm.contains("\\(")) norm = norm.replaceAll("\\(", "");
if(norm.contains("\\)")) norm = norm.replaceAll("\\)", "");
//get TUI
for(String mr : mrsemType) {
if(mr.startsWith(cui)) {
cui_tui = mr;
break;
}
}
//get sem group
ArrayList<String> cuiTuiList=null;
if(cui_tui.contains(";")) {
String[] arrcui_tui = cui_tui.split(";");
cuiTuiList = new ArrayList<String>(Arrays.asList(arrcui_tui));
}
if(!cui_tui.contains(";")){
cuiTuiList = new ArrayList<String>();
cuiTuiList.add(cui_tui);
}
semGroup="";
for(String eachCuiTui : cuiTuiList) {
String[] arrCuiTui = eachCuiTui.split("_");
if(arrCuiTui.length>1) {
String tui = arrCuiTui[1];
for(String se : semgrp) {
if(se.contains("|"+tui+"|")) {
String[] arrSe = se.split("\\|");
if(semGroup.isEmpty()) {
semGroup = arrSe[0];
}
else if (!semGroup.contains(arrSe[0])){
semGroup = semGroup.concat(";").concat(arrSe[0]);
}
}
}
}
else {
pwr1.println("CUI_TUI_List"+cuiTuiList);
}
}
term = term.trim();
//System.out.println(norm+"|"+term+"||"+semGroup+"|"+cui_tui);
if(!norm.isEmpty() && !term.isEmpty() && !semGroup.isEmpty() && !cui_tui.isEmpty()) {
pwr.println(norm+"|"+term+"||"+semGroup+"|"+cui_tui);
//System.out.println(norm+"|"+term+"||"+semGroup+"|"+cui_tui);
}
else {
pwr1.println(norm+"|"+term+"||"+semGroup+"|"+cui_tui);
}
norm = term = semGroup = cui_tui = "";
count++;
//if(count==100) break;
if(count%1000==0) System.out.println(count);
//count1++;
//if(count1==50) break;
}
}
in.close();
pwr.close();
pwr1.close();
System.out.println("Total number of records: "+count);
long endTime = System.nanoTime();
long duration = endTime - startTime;
System.out.println("Process time: "+duration);
}
}