-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestFeatureSelection.java
More file actions
124 lines (93 loc) · 4.06 KB
/
TestFeatureSelection.java
File metadata and controls
124 lines (93 loc) · 4.06 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
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.Map.Entry;
public class TestFeatureSelection {
private static void loadMap(Map<String, Double> hashMap, String fileName) throws FileNotFoundException, IOException {
// TODO Auto-generated method stub
Properties properties = new Properties();
properties.load(new FileInputStream(fileName));
for (String key : properties.stringPropertyNames()) {
hashMap.put(key, Double.parseDouble(properties.get(key).toString()));
}
}
private static void loadToMap(Map<String, Integer> hashMap, String fileName) throws FileNotFoundException, IOException {
// TODO Auto-generated method stub
Properties properties = new Properties();
properties.load(new FileInputStream(fileName));
for (String key : properties.stringPropertyNames()) {
hashMap.put(key, Integer.parseInt(properties.get(key).toString()));
}
}
private static void saveMapToFile(HashMap<String, Integer> posCounts, String fileName) throws FileNotFoundException, IOException {
// TODO Auto-generated method stub
Properties properties = new Properties();
for (Map.Entry<String,Integer> entry : posCounts.entrySet()) {
properties.put(entry.getKey(), entry.getValue().toString());
}
properties.store(new FileOutputStream(fileName), null);
}
public static void CreateFeaturedSet_limit(int limit) throws FileNotFoundException, IOException
{
HashMap<String, Integer> posCounts = new HashMap<String, Integer>();
HashMap<String, Integer> negCounts = new HashMap<String, Integer>();
HashMap<String, Double> FeaturedSet = new HashMap<String, Double>();
//Loadin in Pos Map
String fileName = "posMap.properties";
TestFeatureSelection.loadToMap(posCounts, fileName);
//Loading in Neg Map
fileName = "negMap.properties";
TestFeatureSelection.loadToMap(negCounts, fileName);
//Loading FeaturedSet
fileName = "FeaturedSet.properties";
TestFeatureSelection.loadMap(FeaturedSet, fileName);
/*
* Now sort featured set on mi_val(value) in desecending order
*/
Set<Entry<String, Double>> set = FeaturedSet.entrySet();
List<Entry<String, Double>> list = new ArrayList<Entry<String, Double>>(set);
Collections.sort( list, new Comparator<Map.Entry<String, Double>>()
{
public int compare( Map.Entry<String, Double> o1, Map.Entry<String, Double> o2 )
{
return (o2.getValue()).compareTo( o1.getValue() );
}
} );
String filePath="C:\\Users\\waheguruji\\javaprograms\\Sentiment Test\\FeaturedSet\\posFeatuedMap.properties";
TestFeatureSelection.CreateFinalSet(limit, posCounts, FeaturedSet, filePath);
filePath="C:\\Users\\waheguruji\\javaprograms\\Sentiment Test\\FeaturedSet\\negFeatuedMap.properties";
TestFeatureSelection.CreateFinalSet(limit, negCounts, FeaturedSet, filePath);
}
public static void CreateFinalSet(int limit,HashMap<String, Integer> posCounts,HashMap<String, Double> FeaturedSet,String filePath) throws FileNotFoundException, IOException
{
HashMap<String, Integer> posFeatured = new HashMap<String, Integer>();
HashMap<String, Integer> negFeatured = new HashMap<String, Integer>();
int i=0;
int val=0;
for (String key : FeaturedSet.keySet()) {
i++;
if(i<=limit)
{
if(posCounts.get(key)!=null)
{
val=posCounts.get(key);
posFeatured.put(key, val);
}
}
else
{
break;
}
}
TestFeatureSelection.saveMapToFile(posCounts, filePath);
}
}