| 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;
|
|
|
8 |
import in.shop2020.metamodel.util.CreationUtils;
|
|
|
9 |
import in.shop2020.metamodel.util.ExpandedBullet;
|
|
|
10 |
import in.shop2020.metamodel.util.ExpandedFeature;
|
|
|
11 |
|
|
|
12 |
|
|
|
13 |
import java.io.File;
|
|
|
14 |
import java.io.FileOutputStream;
|
|
|
15 |
import java.io.FileWriter;
|
|
|
16 |
import java.util.ArrayList;
|
|
|
17 |
import java.util.HashMap;
|
|
|
18 |
import java.util.List;
|
|
|
19 |
import java.util.Map;
|
|
|
20 |
|
|
|
21 |
public class FeatureValueExtractor {
|
|
|
22 |
List<Long> featureIds = new ArrayList<Long>();
|
|
|
23 |
|
|
|
24 |
public Map<Long, String> extractFeatureValuesForEntity(Entity entity) throws Exception{
|
|
|
25 |
Map<Long, String> featureIdValuesMap = new HashMap<Long, String>();
|
|
|
26 |
|
|
|
27 |
for(Slide slide: entity.getSlides()){
|
|
|
28 |
if(slide.hasChildrenSlides()){
|
|
|
29 |
for(Slide sl: slide.getChildrenSlides()){
|
|
|
30 |
if(sl.getFeatures()!=null){
|
|
|
31 |
slide.getFeatures().addAll(sl.getFeatures());
|
|
|
32 |
}
|
|
|
33 |
if(sl.hasChildrenSlides()){
|
|
|
34 |
for(Slide sl2: sl.getChildrenSlides()){
|
|
|
35 |
if(sl2.getFeatures()!=null){
|
|
|
36 |
slide.getFeatures().addAll(sl2.getFeatures());
|
|
|
37 |
}
|
|
|
38 |
}
|
|
|
39 |
}
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
}
|
|
|
43 |
for(Feature feature: slide.getFeatures()){
|
|
|
44 |
if(featureIds.contains(feature.getFeatureDefinitionID())){
|
|
|
45 |
String value = "";
|
|
|
46 |
ExpandedFeature expFeature = new ExpandedFeature(feature);
|
|
|
47 |
if(expFeature.getExpandedBullets()!=null){
|
|
|
48 |
int count = 0;
|
|
|
49 |
for(ExpandedBullet expBullet: expFeature.getExpandedBullets()){
|
|
|
50 |
if(count==0){
|
|
|
51 |
value = value + expBullet.displayText();
|
|
|
52 |
}else{
|
|
|
53 |
value = value + " -- " + expBullet.displayText();
|
|
|
54 |
}
|
|
|
55 |
count++;
|
|
|
56 |
}
|
|
|
57 |
}
|
|
|
58 |
featureIdValuesMap.put(feature.getFeatureDefinitionID(), value);
|
|
|
59 |
}
|
|
|
60 |
}
|
|
|
61 |
}
|
|
|
62 |
return featureIdValuesMap;
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
public StringBuffer printFeatureValues() throws Exception{
|
|
|
66 |
StringBuffer featureValuesString = new StringBuffer();
|
|
|
67 |
featureValuesString.append("Category Name" + "\t");
|
|
|
68 |
featureValuesString.append("Entity Name" + "\t");
|
|
|
69 |
featureValuesString.append("EntityID" + "\t");
|
|
|
70 |
|
|
|
71 |
for(Long featureId : featureIds){
|
|
|
72 |
featureValuesString.append(Catalog.getInstance().getDefinitionsContainer().getFeatureDefinition(featureId).getLabel() + "\t");
|
|
|
73 |
}
|
|
|
74 |
featureValuesString.append("\n");
|
|
|
75 |
|
|
|
76 |
for(Entity entity: CreationUtils.getEntities().values()){
|
|
|
77 |
if(entity == null || entity.getSlides() == null || Catalog.getInstance().getDefinitionsContainer().getCategory(entity.getCategoryID()).getParentCategory().getID() != 10001){
|
|
|
78 |
continue;
|
|
|
79 |
}
|
|
|
80 |
featureValuesString.append(Catalog.getInstance().getDefinitionsContainer().getCategory(entity.getCategoryID()).getLabel() + "\t");
|
|
|
81 |
featureValuesString.append(entity.getBrand()+ " " + entity.getModelName() + " " + entity.getModelNumber() + "\t");
|
|
|
82 |
featureValuesString.append(entity.getID() + "\t");
|
|
|
83 |
Map<Long, String> fvalues = extractFeatureValuesForEntity(entity);
|
|
|
84 |
for(Long featureId : featureIds){
|
|
|
85 |
if(fvalues.get(featureId)!=null){
|
|
|
86 |
featureValuesString.append(fvalues.get(featureId).trim() + "\t");
|
|
|
87 |
}else{
|
|
|
88 |
featureValuesString.append("\t");
|
|
|
89 |
}
|
|
|
90 |
}
|
|
|
91 |
featureValuesString.append("\n");
|
|
|
92 |
}
|
|
|
93 |
return featureValuesString;
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
public static void main(String[] args) throws Exception{
|
|
|
97 |
FeatureValueExtractor extractor = new FeatureValueExtractor();
|
|
|
98 |
|
|
|
99 |
extractor.featureIds.addAll(Catalog.getInstance().getDefinitionsContainer().getFeatureDefinitionIDs(10002));
|
|
|
100 |
extractor.featureIds.addAll(Catalog.getInstance().getDefinitionsContainer().getFeatureDefinitionIDs(10003));
|
|
|
101 |
extractor.featureIds.addAll(Catalog.getInstance().getDefinitionsContainer().getFeatureDefinitionIDs(10004));
|
|
|
102 |
extractor.featureIds.addAll(Catalog.getInstance().getDefinitionsContainer().getFeatureDefinitionIDs(10005));
|
|
|
103 |
|
|
|
104 |
/*
|
|
|
105 |
extractor.featureIds.add(120001L);
|
|
|
106 |
extractor.featureIds.add(120002L);
|
|
|
107 |
extractor.featureIds.add(120003L);
|
|
|
108 |
extractor.featureIds.add(120008L);
|
|
|
109 |
extractor.featureIds.add(120005L);
|
|
|
110 |
extractor.featureIds.add(120006L);
|
|
|
111 |
extractor.featureIds.add(120007L);
|
|
|
112 |
extractor.featureIds.add(120009L);
|
|
|
113 |
extractor.featureIds.add(120010L);
|
|
|
114 |
extractor.featureIds.add(120082L);
|
|
|
115 |
extractor.featureIds.add(120048L);
|
|
|
116 |
extractor.featureIds.add(120049L);
|
|
|
117 |
extractor.featureIds.add(120127L);
|
|
|
118 |
extractor.featureIds.add(120011L);
|
|
|
119 |
extractor.featureIds.add(120014L);
|
|
|
120 |
extractor.featureIds.add(120015L);
|
|
|
121 |
extractor.featureIds.add(120016L);
|
|
|
122 |
extractor.featureIds.add(120017L);
|
|
|
123 |
extractor.featureIds.add(120018L);
|
|
|
124 |
extractor.featureIds.add(120019L);
|
|
|
125 |
extractor.featureIds.add(120021L);
|
|
|
126 |
extractor.featureIds.add(120023L);
|
|
|
127 |
extractor.featureIds.add(120051L);
|
|
|
128 |
extractor.featureIds.add(120022L);
|
|
|
129 |
extractor.featureIds.add(120052L);
|
|
|
130 |
extractor.featureIds.add(120020L);
|
|
|
131 |
extractor.featureIds.add(120024L);
|
|
|
132 |
extractor.featureIds.add(120025L);
|
|
|
133 |
extractor.featureIds.add(120053L);
|
|
|
134 |
extractor.featureIds.add(120026L);
|
|
|
135 |
extractor.featureIds.add(120027L);
|
|
|
136 |
extractor.featureIds.add(120028L);
|
|
|
137 |
extractor.featureIds.add(120056L);
|
|
|
138 |
extractor.featureIds.add(120058L);
|
|
|
139 |
extractor.featureIds.add(120029L);
|
|
|
140 |
extractor.featureIds.add(120030L);
|
|
|
141 |
extractor.featureIds.add(120031L);
|
|
|
142 |
extractor.featureIds.add(120032L);
|
|
|
143 |
extractor.featureIds.add(120033L);
|
|
|
144 |
extractor.featureIds.add(120072L);
|
|
|
145 |
extractor.featureIds.add(120073L);
|
|
|
146 |
extractor.featureIds.add(120076L);
|
|
|
147 |
extractor.featureIds.add(120043L);
|
|
|
148 |
extractor.featureIds.add(120044L);
|
|
|
149 |
extractor.featureIds.add(120045L);
|
|
|
150 |
extractor.featureIds.add(120122L);
|
|
|
151 |
extractor.featureIds.add(120046L);
|
|
|
152 |
*/
|
|
|
153 |
StringBuffer featureValuesString = extractor.printFeatureValues();
|
|
|
154 |
File f = new File("/home/rajveer/Desktop/cms/featurevalues.txt");
|
|
|
155 |
FileWriter writer = new FileWriter(f);
|
|
|
156 |
writer.write(featureValuesString.toString());
|
|
|
157 |
writer.close();
|
|
|
158 |
}
|
|
|
159 |
}
|