-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTask.java
More file actions
219 lines (182 loc) · 10.1 KB
/
Copy pathTask.java
File metadata and controls
219 lines (182 loc) · 10.1 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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
import java.io.BufferedReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.io.FileReader;
public class Task {
// create 8 arraylists to store the expected values for each keys (example-TIE
// for neckline, it will be stored in listneckline)
static ArrayList<String> listdesign = new ArrayList<String>();
static ArrayList<String> listlength = new ArrayList<String>();
static ArrayList<String> listmaterial = new ArrayList<String>();
static ArrayList<String> listneckline = new ArrayList<String>();
static ArrayList<String> listoccassion = new ArrayList<String>();
static ArrayList<String> listshape = new ArrayList<String>();
static ArrayList<String> listsleeve = new ArrayList<String>();
static ArrayList<String> listweather = new ArrayList<String>();
public static void main(String[] args) {
String line = "";
String splitBy = ","; // to split the array of string we get from the csv file
try {
BufferedReader br = new BufferedReader(new FileReader("pair.csv"));
while ((line = br.readLine()) != null) { // read until the end of the file
String[] employee = line.split(splitBy);
if (employee[0].toString().equals("DESIGN")) {// if the element of the array is DESIGN, then store the
// element in the listdesign
listdesign.add(employee[1].toLowerCase());
} else if (employee[0].toString().equals("LENGTH")) {// if the element of the array is LENGTH, then
// store the element in the listlength
listlength.add(employee[1].toLowerCase());
} else if (employee[0].toString().equals("MATERIAL")) {
listmaterial.add(employee[1].toLowerCase());
} else if (employee[0].toString().equals("NECKLINE")) {
listneckline.add(employee[1].toLowerCase());
} else if (employee[0].toString().equals("OCCASION")) {
listoccassion.add(employee[1].toLowerCase());
} else if (employee[0].toString().equals("SHAPE")) {
listshape.add(employee[1].toLowerCase());
} else if (employee[0].toString().equals("SLEEVE")) {
listsleeve.add(employee[1].toLowerCase());
} else if (employee[0].toString().equals("WEATHER")) {
listweather.add(employee[1].toLowerCase());
}
}
} catch (IOException e) {// catch any io exception
e.printStackTrace();
}
// hashmap for mainting the count of each key
HashMap<String, Integer> design = new HashMap<>();
HashMap<String, Integer> length = new HashMap<>();
HashMap<String, Integer> material = new HashMap<>();
HashMap<String, Integer> neckline = new HashMap<>();
HashMap<String, Integer> occasion = new HashMap<>();
HashMap<String, Integer> shape = new HashMap<>();
HashMap<String, Integer> sleeve = new HashMap<>();
HashMap<String, Integer> weather = new HashMap<>();
try {
BufferedReader br = new BufferedReader(new FileReader("product2.csv"));// reading from the file product2.csv
int key = 6;
while ((line = br.readLine()) != null) {
ArrayList<String> smalllistdesign = new ArrayList<String>();
ArrayList<String> smalllistlength = new ArrayList<String>();
ArrayList<String> smalllistmaterial = new ArrayList<String>();
ArrayList<String> smalllistneckline = new ArrayList<String>();
ArrayList<String> smalllistoccassion = new ArrayList<String>();
ArrayList<String> smalllistshape = new ArrayList<String>();
ArrayList<String> smalllistsleeve = new ArrayList<String>();
ArrayList<String> smalllistweather = new ArrayList<String>();
String[] employee = line.split(" ");
for (int i = 0; i < employee.length; i++) {
if (listdesign.contains(employee[i])) {// checking if the element of the array is in the listdesign
smalllistdesign.add(employee[i]);
if (design.containsKey(employee[i])) { // if the key is already present in the hashmap, then
// increment the count else add the key and set the count
// as one
design.put(employee[i], design.get(employee[i]) + 1);
} else {
design.put(employee[i], 1);
}
}
if (listlength.contains(employee[i])) {
smalllistlength.add(employee[i]);
if (length.containsKey(employee[i])) {
length.put(employee[i], length.get(employee[i]) + 1);
} else {
length.put(employee[i], 1);
}
}
if (listmaterial.contains(employee[i])) {
smalllistmaterial.add(employee[i]);
if (material.containsKey(employee[i])) {
material.put(employee[i], material.get(employee[i]) + 1);
} else {
material.put(employee[i], 1);
}
}
if (listneckline.contains(employee[i])) {
smalllistneckline.add(employee[i]);
if (neckline.containsKey(employee[i])) {
neckline.put(employee[i], neckline.get(employee[i]) + 1);
} else {
neckline.put(employee[i], 1);
}
}
if (listoccassion.contains(employee[i])) {
smalllistoccassion.add(employee[i]);
if (occasion.containsKey(employee[i])) {
occasion.put(employee[i], occasion.get(employee[i]) + 1);
} else {
occasion.put(employee[i], 1);
}
}
if (listshape.contains(employee[i])) {
smalllistshape.add(employee[i]);
if (shape.containsKey(employee[i])) {
shape.put(employee[i], shape.get(employee[i]) + 1);
} else {
shape.put(employee[i], 1);
}
}
if (listsleeve.contains(employee[i])) {
smalllistsleeve.add(employee[i]);
if (sleeve.containsKey(employee[i])) {
sleeve.put(employee[i], sleeve.get(employee[i]) + 1);
} else {
sleeve.put(employee[i], 1);
}
}
if (listweather.contains(employee[i].toString())) {
smalllistweather.add(employee[i]);
if (weather.containsKey(employee[i])) {
weather.put(employee[i], weather.get(employee[i]) + 1);
} else {
weather.put(employee[i], 1);
}
}
}
// printing the tags of each product description
for (int i = 0; i < smalllistdesign.size(); i++) {
System.out.println(key + " " + "DESIGN- " + smalllistdesign.get(i));
}
for (int i = 0; i < smalllistlength.size(); i++) {
System.out.println(key + " " + "LENGTH- " + smalllistlength.get(i));
}
for (int i = 0; i < smalllistmaterial.size(); i++) {
System.out.println(key + " " + "MATERIAL- " + smalllistmaterial.get(i));
}
for (int i = 0; i < smalllistneckline.size(); i++) {
System.out.println(key + " " + "NECKLINE- " + smalllistneckline.get(i));
}
for (int i = 0; i < smalllistoccassion.size(); i++) {
System.out.println(key + " " + "OCCASION- " + smalllistoccassion.get(i));
}
for (int i = 0; i < smalllistshape.size(); i++) {
System.out.println(key + " " + "SHAPE- " + smalllistshape.get(i));
}
for (int i = 0; i < smalllistsleeve.size(); i++) {
System.out.println(key + " " + "SLEEVE- " + smalllistsleeve.get(i));
}
for (int i = 0; i < smalllistweather.size(); i++) {
System.out.println(key + " " + "WEATHER- " + smalllistweather.get(i));
}
;
++key;
System.out.println();
}
} catch (IOException e) {
e.printStackTrace();
}
// bonus task
// summary report of all the data that have been extracted
// count of how many products does each tag contain
design.forEach((k, v) -> System.out.println(k + " appeared " + v + " times"));
length.forEach((k, v) -> System.out.println(k + " appeared " + v + " times"));
material.forEach((k, v) -> System.out.println(k + " appeared " + v + " times"));
neckline.forEach((k, v) -> System.out.println(k + " appeared " + v + " times"));
occasion.forEach((k, v) -> System.out.println(k + " appeared " + v + " times"));
shape.forEach((k, v) -> System.out.println(k + " appeared " + v + " times"));
sleeve.forEach((k, v) -> System.out.println(k + " appeared " + v + " times"));
weather.forEach((k, v) -> System.out.println(k + " appeared " + v + " times"));
}
}