| 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;
|
|
|
6 |
import in.shop2020.metamodel.core.Slide;
|
|
|
7 |
import in.shop2020.metamodel.definitions.Catalog;
|
| 1917 |
rajveer |
8 |
import in.shop2020.metamodel.definitions.DefinitionsContainer;
|
|
|
9 |
import in.shop2020.metamodel.definitions.FeatureDefinition;
|
|
|
10 |
import in.shop2020.metamodel.definitions.SlideDefinition;
|
|
|
11 |
import in.shop2020.metamodel.definitions.SlideFeatureDefinition;
|
| 1678 |
rajveer |
12 |
import in.shop2020.metamodel.util.CreationUtils;
|
|
|
13 |
import in.shop2020.metamodel.util.ExpandedBullet;
|
| 4218 |
rajveer |
14 |
import in.shop2020.metamodel.util.ExpandedEntity;
|
| 1678 |
rajveer |
15 |
import in.shop2020.metamodel.util.ExpandedFeature;
|
| 4218 |
rajveer |
16 |
import in.shop2020.ui.util.NewVUI;
|
| 1678 |
rajveer |
17 |
|
|
|
18 |
|
|
|
19 |
import java.io.File;
|
|
|
20 |
import java.io.FileWriter;
|
|
|
21 |
import java.util.ArrayList;
|
|
|
22 |
import java.util.HashMap;
|
|
|
23 |
import java.util.List;
|
|
|
24 |
import java.util.Map;
|
|
|
25 |
|
|
|
26 |
public class FeatureValueExtractor {
|
|
|
27 |
List<Long> featureIds = new ArrayList<Long>();
|
|
|
28 |
|
|
|
29 |
public Map<Long, String> extractFeatureValuesForEntity(Entity entity) throws Exception{
|
|
|
30 |
Map<Long, String> featureIdValuesMap = new HashMap<Long, String>();
|
|
|
31 |
|
|
|
32 |
for(Slide slide: entity.getSlides()){
|
|
|
33 |
if(slide.hasChildrenSlides()){
|
|
|
34 |
for(Slide sl: slide.getChildrenSlides()){
|
|
|
35 |
if(sl.getFeatures()!=null){
|
|
|
36 |
slide.getFeatures().addAll(sl.getFeatures());
|
|
|
37 |
}
|
|
|
38 |
if(sl.hasChildrenSlides()){
|
|
|
39 |
for(Slide sl2: sl.getChildrenSlides()){
|
|
|
40 |
if(sl2.getFeatures()!=null){
|
|
|
41 |
slide.getFeatures().addAll(sl2.getFeatures());
|
|
|
42 |
}
|
|
|
43 |
}
|
|
|
44 |
}
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
}
|
| 4218 |
rajveer |
48 |
if(slide.getFeatures() == null){
|
|
|
49 |
continue;
|
|
|
50 |
}
|
| 1678 |
rajveer |
51 |
for(Feature feature: slide.getFeatures()){
|
|
|
52 |
if(featureIds.contains(feature.getFeatureDefinitionID())){
|
|
|
53 |
String value = "";
|
|
|
54 |
ExpandedFeature expFeature = new ExpandedFeature(feature);
|
|
|
55 |
if(expFeature.getExpandedBullets()!=null){
|
|
|
56 |
int count = 0;
|
|
|
57 |
for(ExpandedBullet expBullet: expFeature.getExpandedBullets()){
|
|
|
58 |
if(count==0){
|
|
|
59 |
value = value + expBullet.displayText();
|
|
|
60 |
}else{
|
|
|
61 |
value = value + " -- " + expBullet.displayText();
|
|
|
62 |
}
|
|
|
63 |
count++;
|
|
|
64 |
}
|
|
|
65 |
}
|
|
|
66 |
featureIdValuesMap.put(feature.getFeatureDefinitionID(), value);
|
|
|
67 |
}
|
|
|
68 |
}
|
|
|
69 |
}
|
|
|
70 |
return featureIdValuesMap;
|
|
|
71 |
}
|
|
|
72 |
|
|
|
73 |
public StringBuffer printFeatureValues() throws Exception{
|
|
|
74 |
StringBuffer featureValuesString = new StringBuffer();
|
|
|
75 |
featureValuesString.append("Category Name" + "\t");
|
|
|
76 |
featureValuesString.append("Entity Name" + "\t");
|
|
|
77 |
featureValuesString.append("EntityID" + "\t");
|
| 4218 |
rajveer |
78 |
featureValuesString.append("ImageURL" + "\t");
|
| 1678 |
rajveer |
79 |
|
|
|
80 |
for(Long featureId : featureIds){
|
|
|
81 |
featureValuesString.append(Catalog.getInstance().getDefinitionsContainer().getFeatureDefinition(featureId).getLabel() + "\t");
|
|
|
82 |
}
|
|
|
83 |
featureValuesString.append("\n");
|
|
|
84 |
|
|
|
85 |
for(Entity entity: CreationUtils.getEntities().values()){
|
|
|
86 |
if(entity == null || entity.getSlides() == null || Catalog.getInstance().getDefinitionsContainer().getCategory(entity.getCategoryID()).getParentCategory().getID() != 10001){
|
|
|
87 |
continue;
|
|
|
88 |
}
|
|
|
89 |
featureValuesString.append(Catalog.getInstance().getDefinitionsContainer().getCategory(entity.getCategoryID()).getLabel() + "\t");
|
|
|
90 |
featureValuesString.append(entity.getBrand()+ " " + entity.getModelName() + " " + entity.getModelNumber() + "\t");
|
|
|
91 |
featureValuesString.append(entity.getID() + "\t");
|
| 4218 |
rajveer |
92 |
featureValuesString.append(getImageUrl(entity) + "\t");
|
| 1678 |
rajveer |
93 |
Map<Long, String> fvalues = extractFeatureValuesForEntity(entity);
|
|
|
94 |
for(Long featureId : featureIds){
|
|
|
95 |
if(fvalues.get(featureId)!=null){
|
|
|
96 |
featureValuesString.append(fvalues.get(featureId).trim() + "\t");
|
|
|
97 |
}else{
|
|
|
98 |
featureValuesString.append("\t");
|
|
|
99 |
}
|
|
|
100 |
}
|
|
|
101 |
featureValuesString.append("\n");
|
|
|
102 |
}
|
|
|
103 |
return featureValuesString;
|
|
|
104 |
}
|
|
|
105 |
|
| 4218 |
rajveer |
106 |
private String getImageUrl(Entity entity) throws Exception{
|
|
|
107 |
ExpandedEntity expEntity = new ExpandedEntity(entity);
|
|
|
108 |
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));
|
|
|
110 |
|
|
|
111 |
|
|
|
112 |
}
|
|
|
113 |
|
|
|
114 |
|
| 1678 |
rajveer |
115 |
public static void main(String[] args) throws Exception{
|
| 1917 |
rajveer |
116 |
|
|
|
117 |
FeatureValueExtractor extractor = new FeatureValueExtractor();
|
|
|
118 |
DefinitionsContainer dfc = Catalog.getInstance().getDefinitionsContainer();
|
|
|
119 |
List<SlideDefinition> slideDefs = dfc.getSlideDefinitions(10002);
|
|
|
120 |
for(SlideDefinition slideDef: slideDefs){
|
|
|
121 |
for(SlideFeatureDefinition sfDef: slideDef.getSlideFeatureDefinitions()){
|
|
|
122 |
long fid = sfDef.getFeatureDefintionID();
|
|
|
123 |
if(!extractor.featureIds.contains(fid)){
|
|
|
124 |
extractor.featureIds.add(fid);
|
|
|
125 |
}
|
|
|
126 |
}
|
|
|
127 |
if(slideDef.hasChildren()){
|
|
|
128 |
for(long slideid: slideDef.getChildrenSlideDefinitionIDs()){
|
|
|
129 |
for(SlideFeatureDefinition sfDef: dfc.getSlideDefinition(slideid).getSlideFeatureDefinitions()){
|
|
|
130 |
long fid = sfDef.getFeatureDefintionID();
|
|
|
131 |
if(!extractor.featureIds.contains(fid)){
|
|
|
132 |
extractor.featureIds.add(fid);
|
|
|
133 |
}
|
|
|
134 |
}
|
|
|
135 |
if(dfc.getSlideDefinition(slideid).hasChildren()){
|
|
|
136 |
for(long slideid2: dfc.getSlideDefinition(slideid).getChildrenSlideDefinitionIDs()){
|
|
|
137 |
for(SlideFeatureDefinition sfDef: dfc.getSlideDefinition(slideid2).getSlideFeatureDefinitions()){
|
|
|
138 |
long fid = sfDef.getFeatureDefintionID();
|
|
|
139 |
if(!extractor.featureIds.contains(fid)){
|
|
|
140 |
extractor.featureIds.add(fid);
|
|
|
141 |
}
|
|
|
142 |
}
|
|
|
143 |
}
|
|
|
144 |
}
|
|
|
145 |
}
|
|
|
146 |
|
|
|
147 |
}
|
|
|
148 |
}
|
| 1678 |
rajveer |
149 |
|
| 1917 |
rajveer |
150 |
for(long fid: Catalog.getInstance().getDefinitionsContainer().getFeatureDefinitionIDs(10002)){
|
|
|
151 |
if(!extractor.featureIds.contains(fid)){
|
|
|
152 |
extractor.featureIds.add(fid);
|
|
|
153 |
}
|
|
|
154 |
}
|
|
|
155 |
for(long fid: Catalog.getInstance().getDefinitionsContainer().getFeatureDefinitionIDs(10003)){
|
|
|
156 |
if(!extractor.featureIds.contains(fid)){
|
|
|
157 |
extractor.featureIds.add(fid);
|
|
|
158 |
}
|
|
|
159 |
}
|
|
|
160 |
for(long fid: Catalog.getInstance().getDefinitionsContainer().getFeatureDefinitionIDs(10004)){
|
|
|
161 |
if(!extractor.featureIds.contains(fid)){
|
|
|
162 |
extractor.featureIds.add(fid);
|
|
|
163 |
}
|
|
|
164 |
}
|
|
|
165 |
for(long fid: Catalog.getInstance().getDefinitionsContainer().getFeatureDefinitionIDs(10005)){
|
|
|
166 |
if(!extractor.featureIds.contains(fid)){
|
|
|
167 |
extractor.featureIds.add(fid);
|
|
|
168 |
}
|
|
|
169 |
}
|
|
|
170 |
|
| 1678 |
rajveer |
171 |
/*
|
|
|
172 |
extractor.featureIds.add(120001L);
|
|
|
173 |
extractor.featureIds.add(120002L);
|
|
|
174 |
extractor.featureIds.add(120003L);
|
|
|
175 |
extractor.featureIds.add(120008L);
|
|
|
176 |
extractor.featureIds.add(120005L);
|
|
|
177 |
extractor.featureIds.add(120006L);
|
|
|
178 |
extractor.featureIds.add(120007L);
|
|
|
179 |
extractor.featureIds.add(120009L);
|
|
|
180 |
extractor.featureIds.add(120010L);
|
|
|
181 |
extractor.featureIds.add(120082L);
|
|
|
182 |
extractor.featureIds.add(120048L);
|
|
|
183 |
extractor.featureIds.add(120049L);
|
|
|
184 |
extractor.featureIds.add(120127L);
|
|
|
185 |
extractor.featureIds.add(120011L);
|
|
|
186 |
extractor.featureIds.add(120014L);
|
|
|
187 |
extractor.featureIds.add(120015L);
|
|
|
188 |
extractor.featureIds.add(120016L);
|
|
|
189 |
extractor.featureIds.add(120017L);
|
|
|
190 |
extractor.featureIds.add(120018L);
|
|
|
191 |
extractor.featureIds.add(120019L);
|
|
|
192 |
extractor.featureIds.add(120021L);
|
|
|
193 |
extractor.featureIds.add(120023L);
|
|
|
194 |
extractor.featureIds.add(120051L);
|
|
|
195 |
extractor.featureIds.add(120022L);
|
|
|
196 |
extractor.featureIds.add(120052L);
|
|
|
197 |
extractor.featureIds.add(120020L);
|
|
|
198 |
extractor.featureIds.add(120024L);
|
|
|
199 |
extractor.featureIds.add(120025L);
|
|
|
200 |
extractor.featureIds.add(120053L);
|
|
|
201 |
extractor.featureIds.add(120026L);
|
|
|
202 |
extractor.featureIds.add(120027L);
|
|
|
203 |
extractor.featureIds.add(120028L);
|
|
|
204 |
extractor.featureIds.add(120056L);
|
|
|
205 |
extractor.featureIds.add(120058L);
|
|
|
206 |
extractor.featureIds.add(120029L);
|
|
|
207 |
extractor.featureIds.add(120030L);
|
|
|
208 |
extractor.featureIds.add(120031L);
|
|
|
209 |
extractor.featureIds.add(120032L);
|
|
|
210 |
extractor.featureIds.add(120033L);
|
|
|
211 |
extractor.featureIds.add(120072L);
|
|
|
212 |
extractor.featureIds.add(120073L);
|
|
|
213 |
extractor.featureIds.add(120076L);
|
|
|
214 |
extractor.featureIds.add(120043L);
|
|
|
215 |
extractor.featureIds.add(120044L);
|
|
|
216 |
extractor.featureIds.add(120045L);
|
|
|
217 |
extractor.featureIds.add(120122L);
|
|
|
218 |
extractor.featureIds.add(120046L);
|
|
|
219 |
*/
|
|
|
220 |
StringBuffer featureValuesString = extractor.printFeatureValues();
|
|
|
221 |
File f = new File("/home/rajveer/Desktop/cms/featurevalues.txt");
|
|
|
222 |
FileWriter writer = new FileWriter(f);
|
|
|
223 |
writer.write(featureValuesString.toString());
|
|
|
224 |
writer.close();
|
|
|
225 |
}
|
|
|
226 |
}
|