| Line 1... |
Line 1... |
| 1 |
package in.shop2020.util;
|
1 |
package in.shop2020.util;
|
| 2 |
|
2 |
|
| 3 |
import in.shop2020.metamodel.core.Bullet;
|
3 |
import in.shop2020.metamodel.core.Bullet;
|
| 4 |
import in.shop2020.metamodel.core.Entity;
|
4 |
import in.shop2020.metamodel.core.Entity;
|
| 5 |
import in.shop2020.metamodel.core.Feature;
|
5 |
import in.shop2020.metamodel.core.Feature;
|
| - |
|
6 |
import in.shop2020.metamodel.core.Media;
|
| 6 |
import in.shop2020.metamodel.core.Slide;
|
7 |
import in.shop2020.metamodel.core.Slide;
|
| 7 |
import in.shop2020.metamodel.definitions.Catalog;
|
8 |
import in.shop2020.metamodel.definitions.Catalog;
|
| 8 |
import in.shop2020.metamodel.definitions.DefinitionsContainer;
|
9 |
import in.shop2020.metamodel.definitions.DefinitionsContainer;
|
| 9 |
import in.shop2020.metamodel.definitions.FeatureDefinition;
|
10 |
import in.shop2020.metamodel.definitions.FeatureDefinition;
|
| 10 |
import in.shop2020.metamodel.definitions.SlideDefinition;
|
11 |
import in.shop2020.metamodel.definitions.SlideDefinition;
|
| 11 |
import in.shop2020.metamodel.definitions.SlideFeatureDefinition;
|
12 |
import in.shop2020.metamodel.definitions.SlideFeatureDefinition;
|
| 12 |
import in.shop2020.metamodel.util.CreationUtils;
|
13 |
import in.shop2020.metamodel.util.CreationUtils;
|
| 13 |
import in.shop2020.metamodel.util.ExpandedBullet;
|
14 |
import in.shop2020.metamodel.util.ExpandedBullet;
|
| 14 |
import in.shop2020.metamodel.util.ExpandedEntity;
|
15 |
import in.shop2020.metamodel.util.ExpandedEntity;
|
| 15 |
import in.shop2020.metamodel.util.ExpandedFeature;
|
16 |
import in.shop2020.metamodel.util.ExpandedFeature;
|
| - |
|
17 |
import in.shop2020.model.v1.catalog.Item;
|
| - |
|
18 |
import in.shop2020.thrift.clients.CatalogClient;
|
| 16 |
import in.shop2020.ui.util.NewVUI;
|
19 |
import in.shop2020.ui.util.NewVUI;
|
| 17 |
|
20 |
|
| 18 |
|
21 |
|
| 19 |
import java.io.File;
|
22 |
import java.io.File;
|
| 20 |
import java.io.FileWriter;
|
23 |
import java.io.FileWriter;
|
| 21 |
import java.util.ArrayList;
|
24 |
import java.util.ArrayList;
|
| 22 |
import java.util.HashMap;
|
25 |
import java.util.HashMap;
|
| 23 |
import java.util.List;
|
26 |
import java.util.List;
|
| 24 |
import java.util.Map;
|
27 |
import java.util.Map;
|
| 25 |
|
28 |
|
| - |
|
29 |
import org.apache.commons.lang.StringUtils;
|
| - |
|
30 |
import org.apache.thrift.transport.TTransportException;
|
| - |
|
31 |
|
| 26 |
public class FeatureValueExtractor {
|
32 |
public class FeatureValueExtractor {
|
| 27 |
List<Long> featureIds = new ArrayList<Long>();
|
33 |
List<Long> featureIds = new ArrayList<Long>();
|
| - |
|
34 |
Map<Long, List<String>> imageLabels = new HashMap<Long, List<String>>();
|
| - |
|
35 |
StringBuffer imageNames = new StringBuffer();
|
| - |
|
36 |
static CatalogClient cl;
|
| - |
|
37 |
|
| - |
|
38 |
static {
|
| - |
|
39 |
try {
|
| - |
|
40 |
cl = new CatalogClient();
|
| - |
|
41 |
} catch (TTransportException e) {
|
| - |
|
42 |
// TODO Auto-generated catch block
|
| - |
|
43 |
e.printStackTrace();
|
| - |
|
44 |
}
|
| - |
|
45 |
}
|
| 28 |
|
46 |
|
| 29 |
public Map<Long, String> extractFeatureValuesForEntity(Entity entity) throws Exception{
|
47 |
public Map<Long, String> extractFeatureValuesForEntity(Entity entity) throws Exception{
|
| 30 |
Map<Long, String> featureIdValuesMap = new HashMap<Long, String>();
|
48 |
Map<Long, String> featureIdValuesMap = new HashMap<Long, String>();
|
| 31 |
|
49 |
|
| 32 |
for(Slide slide: entity.getSlides()){
|
50 |
for(Slide slide: entity.getSlides()){
|
| Line 88... |
Line 106... |
| 88 |
}
|
106 |
}
|
| 89 |
featureValuesString.append(Catalog.getInstance().getDefinitionsContainer().getCategory(entity.getCategoryID()).getLabel() + "\t");
|
107 |
featureValuesString.append(Catalog.getInstance().getDefinitionsContainer().getCategory(entity.getCategoryID()).getLabel() + "\t");
|
| 90 |
featureValuesString.append(entity.getBrand()+ " " + entity.getModelName() + " " + entity.getModelNumber() + "\t");
|
108 |
featureValuesString.append(entity.getBrand()+ " " + entity.getModelName() + " " + entity.getModelNumber() + "\t");
|
| 91 |
featureValuesString.append(entity.getID() + "\t");
|
109 |
featureValuesString.append(entity.getID() + "\t");
|
| 92 |
featureValuesString.append(getImageUrl(entity) + "\t");
|
110 |
featureValuesString.append(getImageUrl(entity) + "\t");
|
| - |
|
111 |
//Just to get map
|
| - |
|
112 |
getAllImageUrls(entity);
|
| 93 |
Map<Long, String> fvalues = extractFeatureValuesForEntity(entity);
|
113 |
Map<Long, String> fvalues = extractFeatureValuesForEntity(entity);
|
| 94 |
for(Long featureId : featureIds){
|
114 |
for(Long featureId : featureIds){
|
| 95 |
if(fvalues.get(featureId)!=null){
|
115 |
if(fvalues.get(featureId)!=null){
|
| 96 |
featureValuesString.append(fvalues.get(featureId).trim() + "\t");
|
116 |
featureValuesString.append(fvalues.get(featureId).trim() + "\t");
|
| 97 |
}else{
|
117 |
}else{
|
| Line 105... |
Line 125... |
| 105 |
|
125 |
|
| 106 |
private String getImageUrl(Entity entity) throws Exception{
|
126 |
private String getImageUrl(Entity entity) throws Exception{
|
| 107 |
ExpandedEntity expEntity = new ExpandedEntity(entity);
|
127 |
ExpandedEntity expEntity = new ExpandedEntity(entity);
|
| 108 |
long defaultImageCreationTime = EntityUtils.getCreationTimeFromSummarySlide(expEntity, "default");
|
128 |
long defaultImageCreationTime = EntityUtils.getCreationTimeFromSummarySlide(expEntity, "default");
|
| 109 |
return "http://static0.saholic.com/images/media" + File.separator + entity.getID() + File.separator + NewVUI.computeNewFileName(EntityUtils.getMediaPrefix(expEntity), "default.jpg", String.valueOf(defaultImageCreationTime));
|
129 |
return "http://static0.saholic.com/images/media" + File.separator + entity.getID() + File.separator + NewVUI.computeNewFileName(EntityUtils.getMediaPrefix(expEntity), "default.jpg", String.valueOf(defaultImageCreationTime));
|
| 110 |
|
- |
|
| 111 |
|
- |
|
| 112 |
}
|
130 |
}
|
| 113 |
|
131 |
|
| - |
|
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{
|
| 114 |
|
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 |
|
| 115 |
public static void main(String[] args) throws Exception{
|
174 |
public static void main(String[] args) throws Exception{
|
| 116 |
|
175 |
|
| 117 |
FeatureValueExtractor extractor = new FeatureValueExtractor();
|
176 |
FeatureValueExtractor extractor = new FeatureValueExtractor();
|
| 118 |
DefinitionsContainer dfc = Catalog.getInstance().getDefinitionsContainer();
|
177 |
DefinitionsContainer dfc = Catalog.getInstance().getDefinitionsContainer();
|
| 119 |
List<SlideDefinition> slideDefs = dfc.getSlideDefinitions(10002);
|
178 |
List<SlideDefinition> slideDefs = dfc.getSlideDefinitions(10002);
|
| Line 220... |
Line 279... |
| 220 |
StringBuffer featureValuesString = extractor.printFeatureValues();
|
279 |
StringBuffer featureValuesString = extractor.printFeatureValues();
|
| 221 |
File f = new File("/home/rajveer/Desktop/cms/featurevalues.txt");
|
280 |
File f = new File("/home/rajveer/Desktop/cms/featurevalues.txt");
|
| 222 |
FileWriter writer = new FileWriter(f);
|
281 |
FileWriter writer = new FileWriter(f);
|
| 223 |
writer.write(featureValuesString.toString());
|
282 |
writer.write(featureValuesString.toString());
|
| 224 |
writer.close();
|
283 |
writer.close();
|
| - |
|
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 |
*/
|
| 225 |
}
|
298 |
}
|
| 226 |
}
|
299 |
}
|