| 1678 |
rajveer |
1 |
package in.shop2020.util;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.metamodel.core.Bullet;
|
|
|
4 |
import in.shop2020.metamodel.core.Entity;
|
|
|
5 |
import in.shop2020.metamodel.core.Feature;
|
| 4229 |
rajveer |
6 |
import in.shop2020.metamodel.core.Media;
|
| 1678 |
rajveer |
7 |
import in.shop2020.metamodel.core.Slide;
|
|
|
8 |
import in.shop2020.metamodel.definitions.Catalog;
|
| 1917 |
rajveer |
9 |
import in.shop2020.metamodel.definitions.DefinitionsContainer;
|
|
|
10 |
import in.shop2020.metamodel.definitions.FeatureDefinition;
|
|
|
11 |
import in.shop2020.metamodel.definitions.SlideDefinition;
|
|
|
12 |
import in.shop2020.metamodel.definitions.SlideFeatureDefinition;
|
| 1678 |
rajveer |
13 |
import in.shop2020.metamodel.util.CreationUtils;
|
|
|
14 |
import in.shop2020.metamodel.util.ExpandedBullet;
|
| 4218 |
rajveer |
15 |
import in.shop2020.metamodel.util.ExpandedEntity;
|
| 1678 |
rajveer |
16 |
import in.shop2020.metamodel.util.ExpandedFeature;
|
| 4229 |
rajveer |
17 |
import in.shop2020.model.v1.catalog.Item;
|
|
|
18 |
import in.shop2020.thrift.clients.CatalogClient;
|
| 4218 |
rajveer |
19 |
import in.shop2020.ui.util.NewVUI;
|
| 1678 |
rajveer |
20 |
|
|
|
21 |
|
|
|
22 |
import java.io.File;
|
|
|
23 |
import java.io.FileWriter;
|
|
|
24 |
import java.util.ArrayList;
|
|
|
25 |
import java.util.HashMap;
|
|
|
26 |
import java.util.List;
|
|
|
27 |
import java.util.Map;
|
|
|
28 |
|
| 4229 |
rajveer |
29 |
import org.apache.commons.lang.StringUtils;
|
|
|
30 |
import org.apache.thrift.transport.TTransportException;
|
|
|
31 |
|
| 1678 |
rajveer |
32 |
public class FeatureValueExtractor {
|
|
|
33 |
List<Long> featureIds = new ArrayList<Long>();
|
| 4229 |
rajveer |
34 |
Map<Long, List<String>> imageLabels = new HashMap<Long, List<String>>();
|
|
|
35 |
StringBuffer imageNames = new StringBuffer();
|
|
|
36 |
static CatalogClient cl;
|
| 1678 |
rajveer |
37 |
|
| 4229 |
rajveer |
38 |
static {
|
|
|
39 |
try {
|
|
|
40 |
cl = new CatalogClient();
|
|
|
41 |
} catch (TTransportException e) {
|
|
|
42 |
// TODO Auto-generated catch block
|
|
|
43 |
e.printStackTrace();
|
|
|
44 |
}
|
|
|
45 |
}
|
|
|
46 |
|
| 1678 |
rajveer |
47 |
public Map<Long, String> extractFeatureValuesForEntity(Entity entity) throws Exception{
|
|
|
48 |
Map<Long, String> featureIdValuesMap = new HashMap<Long, String>();
|
|
|
49 |
|
|
|
50 |
for(Slide slide: entity.getSlides()){
|
|
|
51 |
if(slide.hasChildrenSlides()){
|
|
|
52 |
for(Slide sl: slide.getChildrenSlides()){
|
|
|
53 |
if(sl.getFeatures()!=null){
|
|
|
54 |
slide.getFeatures().addAll(sl.getFeatures());
|
|
|
55 |
}
|
|
|
56 |
if(sl.hasChildrenSlides()){
|
|
|
57 |
for(Slide sl2: sl.getChildrenSlides()){
|
|
|
58 |
if(sl2.getFeatures()!=null){
|
|
|
59 |
slide.getFeatures().addAll(sl2.getFeatures());
|
|
|
60 |
}
|
|
|
61 |
}
|
|
|
62 |
}
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
}
|
| 4218 |
rajveer |
66 |
if(slide.getFeatures() == null){
|
|
|
67 |
continue;
|
|
|
68 |
}
|
| 1678 |
rajveer |
69 |
for(Feature feature: slide.getFeatures()){
|
|
|
70 |
if(featureIds.contains(feature.getFeatureDefinitionID())){
|
|
|
71 |
String value = "";
|
|
|
72 |
ExpandedFeature expFeature = new ExpandedFeature(feature);
|
|
|
73 |
if(expFeature.getExpandedBullets()!=null){
|
|
|
74 |
int count = 0;
|
|
|
75 |
for(ExpandedBullet expBullet: expFeature.getExpandedBullets()){
|
|
|
76 |
if(count==0){
|
|
|
77 |
value = value + expBullet.displayText();
|
|
|
78 |
}else{
|
|
|
79 |
value = value + " -- " + expBullet.displayText();
|
|
|
80 |
}
|
|
|
81 |
count++;
|
|
|
82 |
}
|
|
|
83 |
}
|
|
|
84 |
featureIdValuesMap.put(feature.getFeatureDefinitionID(), value);
|
|
|
85 |
}
|
|
|
86 |
}
|
|
|
87 |
}
|
|
|
88 |
return featureIdValuesMap;
|
|
|
89 |
}
|
|
|
90 |
|
|
|
91 |
public StringBuffer printFeatureValues() throws Exception{
|
|
|
92 |
StringBuffer featureValuesString = new StringBuffer();
|
|
|
93 |
featureValuesString.append("Category Name" + "\t");
|
|
|
94 |
featureValuesString.append("Entity Name" + "\t");
|
|
|
95 |
featureValuesString.append("EntityID" + "\t");
|
| 4218 |
rajveer |
96 |
featureValuesString.append("ImageURL" + "\t");
|
| 1678 |
rajveer |
97 |
|
|
|
98 |
for(Long featureId : featureIds){
|
|
|
99 |
featureValuesString.append(Catalog.getInstance().getDefinitionsContainer().getFeatureDefinition(featureId).getLabel() + "\t");
|
|
|
100 |
}
|
|
|
101 |
featureValuesString.append("\n");
|
|
|
102 |
|
|
|
103 |
for(Entity entity: CreationUtils.getEntities().values()){
|
|
|
104 |
if(entity == null || entity.getSlides() == null || Catalog.getInstance().getDefinitionsContainer().getCategory(entity.getCategoryID()).getParentCategory().getID() != 10001){
|
|
|
105 |
continue;
|
|
|
106 |
}
|
|
|
107 |
featureValuesString.append(Catalog.getInstance().getDefinitionsContainer().getCategory(entity.getCategoryID()).getLabel() + "\t");
|
|
|
108 |
featureValuesString.append(entity.getBrand()+ " " + entity.getModelName() + " " + entity.getModelNumber() + "\t");
|
|
|
109 |
featureValuesString.append(entity.getID() + "\t");
|
| 4218 |
rajveer |
110 |
featureValuesString.append(getImageUrl(entity) + "\t");
|
| 4229 |
rajveer |
111 |
//Just to get map
|
|
|
112 |
getAllImageUrls(entity);
|
| 1678 |
rajveer |
113 |
Map<Long, String> fvalues = extractFeatureValuesForEntity(entity);
|
|
|
114 |
for(Long featureId : featureIds){
|
|
|
115 |
if(fvalues.get(featureId)!=null){
|
|
|
116 |
featureValuesString.append(fvalues.get(featureId).trim() + "\t");
|
|
|
117 |
}else{
|
|
|
118 |
featureValuesString.append("\t");
|
|
|
119 |
}
|
|
|
120 |
}
|
|
|
121 |
featureValuesString.append("\n");
|
|
|
122 |
}
|
|
|
123 |
return featureValuesString;
|
|
|
124 |
}
|
|
|
125 |
|
| 4218 |
rajveer |
126 |
private String getImageUrl(Entity entity) throws Exception{
|
|
|
127 |
ExpandedEntity expEntity = new ExpandedEntity(entity);
|
|
|
128 |
long defaultImageCreationTime = EntityUtils.getCreationTimeFromSummarySlide(expEntity, "default");
|
|
|
129 |
return "http://static0.saholic.com/images/media" + File.separator + entity.getID() + File.separator + NewVUI.computeNewFileName(EntityUtils.getMediaPrefix(expEntity), "default.jpg", String.valueOf(defaultImageCreationTime));
|
|
|
130 |
}
|
|
|
131 |
|
| 4229 |
rajveer |
132 |
private void getAllImageUrls(Entity entity) throws Exception{
|
|
|
133 |
if(entity.getID() == 1000147){
|
|
|
134 |
System.out.println("N*");
|
|
|
135 |
}
|
|
|
136 |
ExpandedEntity expEntity = new ExpandedEntity(entity);
|
|
|
137 |
Map<String, Media> medias = expEntity.getAllMedias();
|
|
|
138 |
for(Item item :cl.getClient().getItemsByCatalogId(expEntity.getID())){
|
|
|
139 |
String url = "";
|
|
|
140 |
String color = item.getColor();
|
|
|
141 |
if(color==null){
|
|
|
142 |
color = "jsfhdjsfdhjfdfhdjffh";
|
|
|
143 |
}
|
|
|
144 |
String parts[] = color.split("(-|&|\\s|\\+|and|NA|\\.)+");
|
|
|
145 |
url = "http://static0.saholic.com/images/media"
|
|
|
146 |
+ File.separator + entity.getID()
|
|
|
147 |
+ File.separator + NewVUI.computeNewFileName(EntityUtils.getMediaPrefix(expEntity),
|
|
|
148 |
"default.jpg",
|
|
|
149 |
String.valueOf(EntityUtils.getCreationTimeFromSummarySlide(expEntity, "default")));
|
|
|
150 |
for(String part: parts){
|
|
|
151 |
if(part.length() < 3){
|
|
|
152 |
continue;
|
|
|
153 |
}
|
|
|
154 |
for(String label: expEntity.getAllImageLabels()){
|
|
|
155 |
if(!StringUtils.containsIgnoreCase(label, part.trim())){
|
|
|
156 |
url = "http://static0.saholic.com/images/media"
|
|
|
157 |
+ File.separator + entity.getID()
|
|
|
158 |
+ File.separator + NewVUI.computeNewFileName(EntityUtils.getMediaPrefix(expEntity),
|
|
|
159 |
"default.jpg",
|
|
|
160 |
String.valueOf(EntityUtils.getCreationTimeFromSummarySlide(expEntity, "default")));
|
|
|
161 |
continue;
|
|
|
162 |
}else{
|
|
|
163 |
url = "http://static0.saholic.com/images/media" + File.separator + entity.getID() + File.separator + NewVUI.computeNewFileName(EntityUtils.getMediaPrefix(expEntity), medias.get(label).getFileName(), String.valueOf(medias.get(label).getCreationTime().getTime()));
|
|
|
164 |
break;
|
|
|
165 |
}
|
|
|
166 |
}
|
|
|
167 |
}
|
|
|
168 |
imageNames.append(item.getId() + "\t" + url + "\n");
|
|
|
169 |
}
|
|
|
170 |
|
|
|
171 |
|
|
|
172 |
}
|
|
|
173 |
|
| 1678 |
rajveer |
174 |
public static void main(String[] args) throws Exception{
|
| 1917 |
rajveer |
175 |
|
|
|
176 |
FeatureValueExtractor extractor = new FeatureValueExtractor();
|
|
|
177 |
DefinitionsContainer dfc = Catalog.getInstance().getDefinitionsContainer();
|
|
|
178 |
List<SlideDefinition> slideDefs = dfc.getSlideDefinitions(10002);
|
|
|
179 |
for(SlideDefinition slideDef: slideDefs){
|
|
|
180 |
for(SlideFeatureDefinition sfDef: slideDef.getSlideFeatureDefinitions()){
|
|
|
181 |
long fid = sfDef.getFeatureDefintionID();
|
|
|
182 |
if(!extractor.featureIds.contains(fid)){
|
|
|
183 |
extractor.featureIds.add(fid);
|
|
|
184 |
}
|
|
|
185 |
}
|
|
|
186 |
if(slideDef.hasChildren()){
|
|
|
187 |
for(long slideid: slideDef.getChildrenSlideDefinitionIDs()){
|
|
|
188 |
for(SlideFeatureDefinition sfDef: dfc.getSlideDefinition(slideid).getSlideFeatureDefinitions()){
|
|
|
189 |
long fid = sfDef.getFeatureDefintionID();
|
|
|
190 |
if(!extractor.featureIds.contains(fid)){
|
|
|
191 |
extractor.featureIds.add(fid);
|
|
|
192 |
}
|
|
|
193 |
}
|
|
|
194 |
if(dfc.getSlideDefinition(slideid).hasChildren()){
|
|
|
195 |
for(long slideid2: dfc.getSlideDefinition(slideid).getChildrenSlideDefinitionIDs()){
|
|
|
196 |
for(SlideFeatureDefinition sfDef: dfc.getSlideDefinition(slideid2).getSlideFeatureDefinitions()){
|
|
|
197 |
long fid = sfDef.getFeatureDefintionID();
|
|
|
198 |
if(!extractor.featureIds.contains(fid)){
|
|
|
199 |
extractor.featureIds.add(fid);
|
|
|
200 |
}
|
|
|
201 |
}
|
|
|
202 |
}
|
|
|
203 |
}
|
|
|
204 |
}
|
|
|
205 |
|
|
|
206 |
}
|
|
|
207 |
}
|
| 1678 |
rajveer |
208 |
|
| 1917 |
rajveer |
209 |
for(long fid: Catalog.getInstance().getDefinitionsContainer().getFeatureDefinitionIDs(10002)){
|
|
|
210 |
if(!extractor.featureIds.contains(fid)){
|
|
|
211 |
extractor.featureIds.add(fid);
|
|
|
212 |
}
|
|
|
213 |
}
|
|
|
214 |
for(long fid: Catalog.getInstance().getDefinitionsContainer().getFeatureDefinitionIDs(10003)){
|
|
|
215 |
if(!extractor.featureIds.contains(fid)){
|
|
|
216 |
extractor.featureIds.add(fid);
|
|
|
217 |
}
|
|
|
218 |
}
|
|
|
219 |
for(long fid: Catalog.getInstance().getDefinitionsContainer().getFeatureDefinitionIDs(10004)){
|
|
|
220 |
if(!extractor.featureIds.contains(fid)){
|
|
|
221 |
extractor.featureIds.add(fid);
|
|
|
222 |
}
|
|
|
223 |
}
|
|
|
224 |
for(long fid: Catalog.getInstance().getDefinitionsContainer().getFeatureDefinitionIDs(10005)){
|
|
|
225 |
if(!extractor.featureIds.contains(fid)){
|
|
|
226 |
extractor.featureIds.add(fid);
|
|
|
227 |
}
|
|
|
228 |
}
|
|
|
229 |
|
| 1678 |
rajveer |
230 |
/*
|
|
|
231 |
extractor.featureIds.add(120001L);
|
|
|
232 |
extractor.featureIds.add(120002L);
|
|
|
233 |
extractor.featureIds.add(120003L);
|
|
|
234 |
extractor.featureIds.add(120008L);
|
|
|
235 |
extractor.featureIds.add(120005L);
|
|
|
236 |
extractor.featureIds.add(120006L);
|
|
|
237 |
extractor.featureIds.add(120007L);
|
|
|
238 |
extractor.featureIds.add(120009L);
|
|
|
239 |
extractor.featureIds.add(120010L);
|
|
|
240 |
extractor.featureIds.add(120082L);
|
|
|
241 |
extractor.featureIds.add(120048L);
|
|
|
242 |
extractor.featureIds.add(120049L);
|
|
|
243 |
extractor.featureIds.add(120127L);
|
|
|
244 |
extractor.featureIds.add(120011L);
|
|
|
245 |
extractor.featureIds.add(120014L);
|
|
|
246 |
extractor.featureIds.add(120015L);
|
|
|
247 |
extractor.featureIds.add(120016L);
|
|
|
248 |
extractor.featureIds.add(120017L);
|
|
|
249 |
extractor.featureIds.add(120018L);
|
|
|
250 |
extractor.featureIds.add(120019L);
|
|
|
251 |
extractor.featureIds.add(120021L);
|
|
|
252 |
extractor.featureIds.add(120023L);
|
|
|
253 |
extractor.featureIds.add(120051L);
|
|
|
254 |
extractor.featureIds.add(120022L);
|
|
|
255 |
extractor.featureIds.add(120052L);
|
|
|
256 |
extractor.featureIds.add(120020L);
|
|
|
257 |
extractor.featureIds.add(120024L);
|
|
|
258 |
extractor.featureIds.add(120025L);
|
|
|
259 |
extractor.featureIds.add(120053L);
|
|
|
260 |
extractor.featureIds.add(120026L);
|
|
|
261 |
extractor.featureIds.add(120027L);
|
|
|
262 |
extractor.featureIds.add(120028L);
|
|
|
263 |
extractor.featureIds.add(120056L);
|
|
|
264 |
extractor.featureIds.add(120058L);
|
|
|
265 |
extractor.featureIds.add(120029L);
|
|
|
266 |
extractor.featureIds.add(120030L);
|
|
|
267 |
extractor.featureIds.add(120031L);
|
|
|
268 |
extractor.featureIds.add(120032L);
|
|
|
269 |
extractor.featureIds.add(120033L);
|
|
|
270 |
extractor.featureIds.add(120072L);
|
|
|
271 |
extractor.featureIds.add(120073L);
|
|
|
272 |
extractor.featureIds.add(120076L);
|
|
|
273 |
extractor.featureIds.add(120043L);
|
|
|
274 |
extractor.featureIds.add(120044L);
|
|
|
275 |
extractor.featureIds.add(120045L);
|
|
|
276 |
extractor.featureIds.add(120122L);
|
|
|
277 |
extractor.featureIds.add(120046L);
|
|
|
278 |
*/
|
|
|
279 |
StringBuffer featureValuesString = extractor.printFeatureValues();
|
|
|
280 |
File f = new File("/home/rajveer/Desktop/cms/featurevalues.txt");
|
|
|
281 |
FileWriter writer = new FileWriter(f);
|
|
|
282 |
writer.write(featureValuesString.toString());
|
|
|
283 |
writer.close();
|
| 4229 |
rajveer |
284 |
|
|
|
285 |
File f1 = new File("/home/rajveer/Desktop/cms/imagenames.txt");
|
|
|
286 |
FileWriter writer1 = new FileWriter(f1);
|
|
|
287 |
writer1.write(extractor.imageNames.toString());
|
|
|
288 |
writer1.close();
|
|
|
289 |
|
|
|
290 |
/*
|
|
|
291 |
String color = "rajveer . this";
|
|
|
292 |
String parts[] = color.split("(-|&|\\s|\\+|and|NA|\\.)+");
|
|
|
293 |
//String parts[] = color.split("-|\\s|&|.|NA|\\+|and");
|
|
|
294 |
for(String part: parts){
|
|
|
295 |
System.out.println(part);
|
|
|
296 |
}
|
|
|
297 |
*/
|
| 1678 |
rajveer |
298 |
}
|
|
|
299 |
}
|