-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcombine.java
More file actions
188 lines (134 loc) · 4.3 KB
/
Copy pathcombine.java
File metadata and controls
188 lines (134 loc) · 4.3 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
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/**
*
*/
package analyzer;
import java.awt.List;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashSet;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.LinkedList;
import java.util.Map;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map.Entry;
import java.util.Set;
public class combine {
Map<String, Integer> dictionary = new HashMap<String, Integer>();
Map<String, Integer> sortedMap;
public void readcsv(String csvFile)
{
BufferedReader br = null;
String line = "";
String cvsSplitBy = ",";
try {
br = new BufferedReader(new FileReader(csvFile));
while ((line = br.readLine()) != null) {
// use comma as separator
String[] word = line.split(cvsSplitBy);
System.out.println(word[0]);
if(dictionary.containsKey(word[0])) {
Integer val = (Integer) dictionary.get(word[0]);
dictionary.put(word[0], val + 1);
}
else
{
if(word[0]!="" || word[0]!=null)
dictionary.put(word[0], Integer.parseInt(word[1]));
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
//System.out.println("Done"+smart_system_stop_wordlist.size());
}
private void generateCsvFile(String sFileName)
{
try
{
FileWriter writer = new FileWriter(sFileName+".csv");
//FileWriter writer_log = new FileWriter(sFileName+"log.csv");
/* if(this.gram == 1)
writer.append("Unigram");
if(this.gram == 2)
writer.append("Bigram");
writer.append(',');
writer.append("Word Count");
writer.append('\n');
*/
int x= 1;
for (Map.Entry<String, Integer> entry : sortedMap.entrySet()) {
writer.append(entry.getKey()+","+entry.getValue()+"\n");
//writer_log.append(Math.log(x)+","+Math.log(entry.getValue())+"\n");
//x++;
}
//generate whatever data you want
writer.flush();
// writer_log.flush();
writer.close();
// writer_log.close();
}
catch(IOException e)
{
e.printStackTrace();
}
}
public void sortByComparator() {
// Convert Map to List
ArrayList<Map.Entry<String, Integer>> list = new ArrayList<Map.Entry<String, Integer>>(dictionary.entrySet());
// Sort list with comparator, to compare the Map values
Collections.sort(list, new Comparator<Map.Entry<String, Integer>>() {
public int compare(Map.Entry<String, Integer> o1,
Map.Entry<String, Integer> o2) {
return (o2.getValue()).compareTo(o1.getValue());
}
});
// Convert sorted map back to a Map
sortedMap = new LinkedHashMap<String, Integer>();
for (Iterator<Map.Entry<String, Integer>> it = list.iterator(); it.hasNext();) {
Map.Entry<String, Integer> entry = it.next();
sortedMap.put(entry.getKey(), entry.getValue());
}
}
public static void main(String[] args) {
String [] forum_name = new String [4];
forum_name[2]="Bigram_eHealth";
forum_name[3]="Bigram_healthboards";
forum_name[0]="Bigram_MedHelp";
forum_name[1]="Bigram_WebMD";
combine com = new combine();
for(int i=0;i<4;i++)
{
String filename = "D:/nahid/Medforum/data/json/eHealth/summarized/summarized/"+forum_name[i]+".csv";
com.readcsv(filename);
}
com.sortByComparator();
com.generateCsvFile("D:/nahid/Medforum/data/json/eHealth/summarized/summarized/combine");
//analyzer.LoadJson("D:/nahid/Medforum/data/json/eHealth/Part2/eHealth/Schizophrenia/ka5am-T142.json");
//analyzer.generateFrequency_for_smart_word_list();
//DocAnalyzer analyzer_bigram = new DocAnalyzer(2);
//analyzer_bigram.LoadDirectory("./data/json/eHealth/Panic_Attack/", ".json");
}
}