| 2171 |
rajveer |
1 |
/**
|
|
|
2 |
*
|
|
|
3 |
*/
|
|
|
4 |
package in.shop2020.util;
|
|
|
5 |
|
|
|
6 |
import in.shop2020.metamodel.core.Bullet;
|
|
|
7 |
import in.shop2020.metamodel.core.Entity;
|
|
|
8 |
import in.shop2020.metamodel.core.Feature;
|
|
|
9 |
import in.shop2020.metamodel.core.PrimitiveDataObject;
|
|
|
10 |
import in.shop2020.metamodel.core.Slide;
|
|
|
11 |
import in.shop2020.metamodel.definitions.BulletDefinition;
|
|
|
12 |
import in.shop2020.metamodel.definitions.Catalog;
|
|
|
13 |
import in.shop2020.metamodel.definitions.Category;
|
|
|
14 |
import in.shop2020.metamodel.definitions.DatatypeDefinition;
|
|
|
15 |
import in.shop2020.metamodel.definitions.DefinitionsContainer;
|
|
|
16 |
import in.shop2020.metamodel.definitions.FacetDefinition;
|
|
|
17 |
import in.shop2020.metamodel.definitions.FacetSlideDefinition;
|
|
|
18 |
import in.shop2020.metamodel.definitions.FeatureDefinition;
|
| 4056 |
rajveer |
19 |
import in.shop2020.metamodel.util.CreationUtils;
|
| 2171 |
rajveer |
20 |
import in.shop2020.metamodel.util.ExpandedBullet;
|
|
|
21 |
import in.shop2020.metamodel.util.ExpandedBulletDefinition;
|
|
|
22 |
import in.shop2020.metamodel.util.ExpandedEntity;
|
|
|
23 |
import in.shop2020.metamodel.util.ExpandedFacetDefinition;
|
|
|
24 |
import in.shop2020.metamodel.util.ExpandedFacetSlideDefinition;
|
|
|
25 |
import in.shop2020.metamodel.util.ExpandedFeature;
|
|
|
26 |
import in.shop2020.metamodel.util.ExpandedFeatureDefinition;
|
|
|
27 |
import in.shop2020.metamodel.util.ExpandedSlide;
|
|
|
28 |
|
|
|
29 |
import java.io.File;
|
|
|
30 |
import java.io.FileOutputStream;
|
|
|
31 |
import java.util.ArrayList;
|
|
|
32 |
import java.util.HashMap;
|
|
|
33 |
import java.util.List;
|
|
|
34 |
import java.util.Map;
|
|
|
35 |
|
| 6842 |
amit.gupta |
36 |
import javax.xml.transform.Transformer;
|
| 2171 |
rajveer |
37 |
import javax.xml.transform.TransformerFactory;
|
|
|
38 |
import javax.xml.transform.stream.StreamResult;
|
|
|
39 |
import javax.xml.transform.stream.StreamSource;
|
|
|
40 |
|
|
|
41 |
import org.apache.commons.lang.StringEscapeUtils;
|
|
|
42 |
import org.apache.commons.lang.StringUtils;
|
|
|
43 |
|
|
|
44 |
|
|
|
45 |
/**
|
|
|
46 |
* Command line utility to convert IR Definitions into IR Data and IR Meta-data
|
|
|
47 |
*
|
|
|
48 |
* @author rajveer
|
|
|
49 |
*
|
|
|
50 |
*/
|
|
|
51 |
public class NewIR {
|
|
|
52 |
|
|
|
53 |
/**
|
|
|
54 |
* Level - 4, 8, 12, 16
|
|
|
55 |
*/
|
|
|
56 |
private String[] xmlIndentation = {"", " ", " ", " "," "};
|
|
|
57 |
|
|
|
58 |
private String[] xmlTabIndentation = {"", "\t", "\t\t", "\t\t\t", "\t\t\t\t", "\t\t\t\t\t", "\t\t\t\t\t\t"};
|
|
|
59 |
|
|
|
60 |
private Map<Long, List<String>> facetIDFacetValues = new HashMap<Long, List<String>>();
|
| 5078 |
amit.gupta |
61 |
private static Map<String, Map<String, String>> synonymMap = null;
|
| 2171 |
rajveer |
62 |
|
| 5078 |
amit.gupta |
63 |
static {
|
|
|
64 |
try {
|
|
|
65 |
synonymMap = CreationUtils.getSynonyms();
|
|
|
66 |
}catch(Exception e){
|
|
|
67 |
e.printStackTrace();
|
|
|
68 |
}
|
|
|
69 |
}
|
|
|
70 |
|
| 2367 |
rajveer |
71 |
List<Entity> entities;
|
| 2171 |
rajveer |
72 |
|
|
|
73 |
/**
|
|
|
74 |
* @param args
|
|
|
75 |
* @throws Exception
|
|
|
76 |
*/
|
|
|
77 |
public static void main(String[] args) throws Exception {
|
|
|
78 |
/*
|
|
|
79 |
NewIR ir = new NewIR();
|
|
|
80 |
ir.exportIRData();
|
|
|
81 |
ir.transformIrDataXMLtoSolrXML();
|
|
|
82 |
ir.exportIRMetaData();
|
| 4056 |
rajveer |
83 |
ir.transformIrMetaDataXMLtoSolrSchemaXML();
|
|
|
84 |
ir.transformIrMetaDataXMLtoSolrCatchAllXML();
|
| 2171 |
rajveer |
85 |
*/
|
|
|
86 |
}
|
|
|
87 |
|
|
|
88 |
/**
|
|
|
89 |
*
|
|
|
90 |
* @param entityIdItemMap
|
|
|
91 |
*/
|
| 2367 |
rajveer |
92 |
public NewIR(List<Entity> entities){
|
|
|
93 |
this.entities = entities;
|
| 2171 |
rajveer |
94 |
}
|
|
|
95 |
|
|
|
96 |
|
|
|
97 |
/**
|
|
|
98 |
*
|
|
|
99 |
* @param inXMLFilename
|
|
|
100 |
* @param xslFilename
|
|
|
101 |
* @param outXMLFilename
|
|
|
102 |
* @throws Exception
|
|
|
103 |
*/
|
|
|
104 |
|
|
|
105 |
public void xsltTransformation(String inXMLFilename, String xslFilename, String outXMLFilename) throws Exception{
|
|
|
106 |
// Use the static TransformerFactory.newInstance() method to instantiate
|
|
|
107 |
// a TransformerFactory. The javax.xml.transform.TransformerFactory
|
|
|
108 |
// system property setting determines the actual class to instantiate --
|
|
|
109 |
// org.apache.xalan.transformer.TransformerImpl.
|
|
|
110 |
TransformerFactory tFactory = TransformerFactory.newInstance();
|
|
|
111 |
|
|
|
112 |
// Use the TransformerFactory to instantiate a Transformer that will work with
|
|
|
113 |
// the stylesheet you specify. This method call also processes the stylesheet
|
|
|
114 |
// into a compiled Templates object.
|
|
|
115 |
Transformer transformer = tFactory.newTransformer(new StreamSource(xslFilename));
|
|
|
116 |
|
|
|
117 |
// Use the Transformer to apply the associated Templates object to an XML document
|
|
|
118 |
// (foo.xml) and write the output to a file (foo.out).
|
|
|
119 |
transformer.transform(new StreamSource(inXMLFilename), new StreamResult(new FileOutputStream(outXMLFilename)));
|
|
|
120 |
|
|
|
121 |
}
|
|
|
122 |
|
|
|
123 |
/**
|
|
|
124 |
*
|
|
|
125 |
* @throws Exception
|
|
|
126 |
*/
|
| 2367 |
rajveer |
127 |
public void transformIrDataXMLtoSolrXML(long catalogId) throws Exception {
|
|
|
128 |
String irDataFilename = Utils.EXPORT_PATH + "xml/intermediate/" + catalogId + "_irdata.xml";
|
|
|
129 |
String irSolrDataFilename = Utils.EXPORT_PATH + "xml/final/" + catalogId + "_irdata_solr.xml";
|
| 2171 |
rajveer |
130 |
String irXslFilename = "src/xsl/irdata_solrdata.xsl";
|
|
|
131 |
System.out.println(irSolrDataFilename);
|
|
|
132 |
File solrFile = new File(irSolrDataFilename);
|
|
|
133 |
if(!solrFile.exists()){
|
|
|
134 |
solrFile.createNewFile();
|
|
|
135 |
}
|
|
|
136 |
xsltTransformation(irDataFilename, irXslFilename, irSolrDataFilename);
|
|
|
137 |
}
|
|
|
138 |
|
|
|
139 |
|
|
|
140 |
/**
|
|
|
141 |
*
|
|
|
142 |
* @throws Exception
|
|
|
143 |
*/
|
| 4056 |
rajveer |
144 |
public void transformIrMetaDataXMLtoSolrSchemaXML() throws Exception {
|
| 2367 |
rajveer |
145 |
String irDataFilename = Utils.EXPORT_PATH + "xml/intermediate/" + "irmetadata.xml";
|
|
|
146 |
String irSolrDataFilename = Utils.EXPORT_PATH + "xml/final/" + "irmetadata_solrschema.xml";
|
| 2171 |
rajveer |
147 |
String irXslFilename = "src/xsl/irmetadata_solrschema.xsl";
|
|
|
148 |
System.out.println(irSolrDataFilename);
|
|
|
149 |
File solrFile = new File(irSolrDataFilename);
|
|
|
150 |
if(!solrFile.exists()){
|
|
|
151 |
solrFile.createNewFile();
|
|
|
152 |
}
|
|
|
153 |
xsltTransformation(irDataFilename, irXslFilename, irSolrDataFilename);
|
|
|
154 |
}
|
|
|
155 |
|
|
|
156 |
|
|
|
157 |
|
|
|
158 |
/**
|
|
|
159 |
*
|
|
|
160 |
* @throws Exception
|
|
|
161 |
*/
|
| 4056 |
rajveer |
162 |
public void transformIrMetaDataXMLtoSolrCatchAllXML() throws Exception {
|
|
|
163 |
String irDataFilename = Utils.EXPORT_PATH + "xml/intermediate/" + "irmetadata.xml";
|
|
|
164 |
String irSolrDataFilename = Utils.EXPORT_PATH + "xml/final/" + "irmetadata_catchall.xml";
|
|
|
165 |
String irXslFilename = "src/xsl/irmetadata_catchall.xsl";
|
|
|
166 |
System.out.println(irSolrDataFilename);
|
|
|
167 |
File solrFile = new File(irSolrDataFilename);
|
|
|
168 |
if(!solrFile.exists()){
|
|
|
169 |
solrFile.createNewFile();
|
|
|
170 |
}
|
|
|
171 |
xsltTransformation(irDataFilename, irXslFilename, irSolrDataFilename);
|
|
|
172 |
}
|
|
|
173 |
|
|
|
174 |
/**
|
|
|
175 |
*
|
|
|
176 |
* @throws Exception
|
|
|
177 |
*/
|
| 2171 |
rajveer |
178 |
public void exportIRMetaData() throws Exception {
|
|
|
179 |
DefinitionsContainer defs =
|
|
|
180 |
Catalog.getInstance().getDefinitionsContainer();
|
|
|
181 |
|
|
|
182 |
// <IRMetaData>
|
|
|
183 |
List<String> xmlSnippets = new ArrayList<String>();
|
|
|
184 |
xmlSnippets.add("<IRMetaData>");
|
|
|
185 |
xmlSnippets.add("\t<Facets>");
|
|
|
186 |
|
|
|
187 |
IRMetaDataJythonWrapper jy = new IRMetaDataJythonWrapper();
|
|
|
188 |
|
|
|
189 |
// Iterate over all facet definitions
|
|
|
190 |
Map<Long, FacetDefinition> facetDefs = defs.getFacetDefinitions();
|
|
|
191 |
for(FacetDefinition facetDef : facetDefs.values()) {
|
|
|
192 |
|
|
|
193 |
jy.reset();
|
|
|
194 |
jy.initialize();
|
|
|
195 |
|
|
|
196 |
ExpandedFacetDefinition expFacetDef =
|
|
|
197 |
new ExpandedFacetDefinition(facetDef);
|
|
|
198 |
|
|
|
199 |
jy.setExpandedFacetDefinition(expFacetDef);
|
|
|
200 |
|
|
|
201 |
jy.executeRule();
|
|
|
202 |
|
|
|
203 |
String facetXMLSnip = jy.getXMLSnippet();
|
|
|
204 |
Utils.info("facetXMLSnip=" + facetXMLSnip);
|
|
|
205 |
|
|
|
206 |
xmlSnippets.add(facetXMLSnip);
|
|
|
207 |
|
|
|
208 |
}
|
|
|
209 |
xmlSnippets.add("\t</Facets>");
|
|
|
210 |
|
|
|
211 |
|
|
|
212 |
|
|
|
213 |
xmlSnippets.add("\n\t<Properties>");
|
|
|
214 |
|
|
|
215 |
// Iterate over all feature definitions
|
|
|
216 |
Map<Long, FeatureDefinition> featureDefs = defs.getFeatureDefinitions();
|
|
|
217 |
for(FeatureDefinition featureDef : featureDefs.values()) {
|
|
|
218 |
String propertyXMLSnip = this.getPropertyXMLSnippet(featureDef);
|
|
|
219 |
Utils.info("propertyXMLSnip=" + propertyXMLSnip);
|
|
|
220 |
|
|
|
221 |
xmlSnippets.add(propertyXMLSnip);
|
|
|
222 |
}
|
| 20851 |
amit.gupta |
223 |
//manually add a property
|
|
|
224 |
xmlSnippets.add("\n\t\t<field name=\"H_00001\" type=\"boolean\" indexed=\"true\" stored=\"false\" multiValued=\"false\" required=\"false\"/>");
|
| 2171 |
rajveer |
225 |
xmlSnippets.add("\t</Properties>");
|
|
|
226 |
|
|
|
227 |
xmlSnippets.add("\n\t<Categories>");
|
|
|
228 |
|
|
|
229 |
Category rootCategory = defs.getCategory(Catalog.getInstance().getRootCategory().getID());
|
|
|
230 |
String categoryXMLSnip = this.getCategoryXMLSnippet(rootCategory, 2);
|
|
|
231 |
Utils.info("categoryXMLSnip=" + categoryXMLSnip);
|
|
|
232 |
|
|
|
233 |
|
|
|
234 |
xmlSnippets.add("\t</Categories>");
|
|
|
235 |
|
|
|
236 |
// </IRMetaData>
|
|
|
237 |
xmlSnippets.add("</IRMetaData>");
|
|
|
238 |
|
|
|
239 |
String irMetaDataXML = StringUtils.join(xmlSnippets, "\n");
|
|
|
240 |
Utils.info(irMetaDataXML);
|
|
|
241 |
|
|
|
242 |
// Write it to file
|
| 2367 |
rajveer |
243 |
String irMetaDataFilename = Utils.EXPORT_PATH + "xml/intermediate/" + "irmetadata.xml";
|
| 2171 |
rajveer |
244 |
DBUtils.store(irMetaDataXML, irMetaDataFilename);
|
|
|
245 |
}
|
|
|
246 |
|
|
|
247 |
/**
|
|
|
248 |
*
|
|
|
249 |
* @param category
|
|
|
250 |
* @return
|
|
|
251 |
* @throws Exception
|
|
|
252 |
*/
|
|
|
253 |
private String getCategoryXMLSnippet(Category category, int indent)
|
|
|
254 |
throws Exception {
|
|
|
255 |
|
|
|
256 |
DefinitionsContainer defs =
|
|
|
257 |
Catalog.getInstance().getDefinitionsContainer();
|
|
|
258 |
|
|
|
259 |
String xmlSnip = this.xmlTabIndentation[indent] + "<Category";
|
|
|
260 |
|
|
|
261 |
xmlSnip += " ID=\"" + category.getID() + "\"";
|
|
|
262 |
xmlSnip += " label=\"" + category.getLabel() + "\"";
|
|
|
263 |
xmlSnip += ">\n";
|
|
|
264 |
|
|
|
265 |
List<Category> children = category.getChildrenCategory();
|
|
|
266 |
|
|
|
267 |
if(children != null) {
|
|
|
268 |
for(Category child : children) {
|
|
|
269 |
xmlSnip += this.getCategoryXMLSnippet(child, indent+1);
|
|
|
270 |
}
|
|
|
271 |
}
|
|
|
272 |
else {
|
|
|
273 |
// Only leaf category will have entities
|
|
|
274 |
// Facet IDs
|
|
|
275 |
xmlSnip += this.xmlTabIndentation[indent+1] + "<Facets>\n";
|
|
|
276 |
|
|
|
277 |
List<Long> facetDefIDs =
|
|
|
278 |
defs.getFacetDefinitionIDs(category.getID());
|
|
|
279 |
//Utils.info("facetDefIDs=" + facetDefIDs);
|
|
|
280 |
|
|
|
281 |
|
|
|
282 |
|
|
|
283 |
if( facetDefIDs != null && !facetDefIDs.isEmpty() ){
|
|
|
284 |
for(Long facetDefID : facetDefIDs) {
|
|
|
285 |
xmlSnip += this.xmlTabIndentation[indent+2] +
|
|
|
286 |
"<FacetID>" + facetDefID + "</FacetID>\n";
|
|
|
287 |
}
|
|
|
288 |
}
|
|
|
289 |
|
|
|
290 |
|
|
|
291 |
xmlSnip += this.xmlTabIndentation[indent+1] + "</Facets>\n\n";
|
|
|
292 |
|
|
|
293 |
// Feature IDs
|
|
|
294 |
xmlSnip += this.xmlTabIndentation[indent+1] + "<Properties>\n";
|
|
|
295 |
|
|
|
296 |
List<Long> featureDefIDs =
|
|
|
297 |
defs.getFeatureDefinitionIDs(category.getID());
|
|
|
298 |
//Utils.info("featureDefIDs=" + featureDefIDs);
|
|
|
299 |
|
|
|
300 |
for(Long featureDefID : featureDefIDs) {
|
|
|
301 |
xmlSnip += this.xmlTabIndentation[indent+2] +
|
|
|
302 |
"<FeatureID>" + featureDefID + "</FeatureID>\n";
|
|
|
303 |
}
|
|
|
304 |
|
|
|
305 |
xmlSnip += this.xmlTabIndentation[indent+1] + "</Properties>\n";
|
|
|
306 |
}
|
|
|
307 |
|
|
|
308 |
xmlSnip += this.xmlTabIndentation[indent] + "</Category>\n";
|
|
|
309 |
|
|
|
310 |
return xmlSnip;
|
|
|
311 |
}
|
|
|
312 |
|
|
|
313 |
/**
|
|
|
314 |
*
|
|
|
315 |
* @param featureDef
|
|
|
316 |
* @return
|
|
|
317 |
* @throws Exception
|
|
|
318 |
*/
|
|
|
319 |
private String getPropertyXMLSnippet(FeatureDefinition featureDef)
|
|
|
320 |
throws Exception {
|
|
|
321 |
String xmlSnip = "\t\t<Property";
|
|
|
322 |
|
|
|
323 |
xmlSnip += " ID=\"" + featureDef.getID() + "\"";
|
|
|
324 |
xmlSnip += " label=\"" + featureDef.getLabel() + "\"";
|
|
|
325 |
|
|
|
326 |
ExpandedFeatureDefinition expFeatureDef =
|
|
|
327 |
new ExpandedFeatureDefinition(featureDef);
|
|
|
328 |
|
|
|
329 |
ExpandedBulletDefinition expBulletDef =
|
|
|
330 |
expFeatureDef.getExpandedBulletDefinition();
|
|
|
331 |
|
|
|
332 |
String datatype = "string";
|
|
|
333 |
if(expBulletDef.isComposite() || expBulletDef.isEnumerated()) {
|
|
|
334 |
datatype = "string";
|
|
|
335 |
}
|
|
|
336 |
else {
|
|
|
337 |
DatatypeDefinition datatypeDef =
|
|
|
338 |
expBulletDef.getDatatypeDefinition();
|
|
|
339 |
|
|
|
340 |
datatype = datatypeDef.getName();
|
|
|
341 |
|
|
|
342 |
// REVISIT
|
|
|
343 |
if(datatype.equals("hours_mins") || datatype.equals("days_hours") ||
|
|
|
344 |
datatype.equals("hours_mins") ||
|
|
|
345 |
datatype.equals("days_hours")) {
|
|
|
346 |
datatype = "string";
|
|
|
347 |
}
|
|
|
348 |
}
|
|
|
349 |
xmlSnip += " datatype=\"" + datatype + "\"";
|
|
|
350 |
|
|
|
351 |
String multivalue = "false";
|
|
|
352 |
if (expBulletDef.isMultivalue()) {
|
|
|
353 |
multivalue = "true";
|
|
|
354 |
}
|
|
|
355 |
xmlSnip += " isMultivalue=\"" + multivalue + "\"";
|
|
|
356 |
|
|
|
357 |
xmlSnip += "/>";
|
|
|
358 |
return xmlSnip;
|
|
|
359 |
}
|
|
|
360 |
|
|
|
361 |
|
|
|
362 |
|
|
|
363 |
private String processFacet(FacetDefinition facet, ExpandedSlide expSlide, ExpandedFacetSlideDefinition expFacetSlideDef, Long facetDefID) throws Exception {
|
|
|
364 |
|
|
|
365 |
IRDataJythonWrapper jw = new IRDataJythonWrapper();
|
|
|
366 |
|
|
|
367 |
jw.setExpandedSlide(expSlide);
|
|
|
368 |
jw.setExpandedFacetSlideDefinition(expFacetSlideDef);
|
|
|
369 |
|
|
|
370 |
// Execute Python script
|
|
|
371 |
jw.executeRule();
|
|
|
372 |
|
|
|
373 |
//FIXME
|
|
|
374 |
// Normalize
|
|
|
375 |
// if(defs.needsNormalization(feature.getFeatureDefinitionID())) {
|
|
|
376 |
// Utils.info("needsNormalization feature=" + feature.getFeatureDefinitionID());
|
|
|
377 |
//
|
|
|
378 |
// feature = this.normalize(feature);
|
|
|
379 |
// }
|
|
|
380 |
|
|
|
381 |
|
|
|
382 |
|
|
|
383 |
List<Object> values = (List<Object>)jw.getValues();
|
|
|
384 |
Utils.info("values=" + values);
|
|
|
385 |
|
|
|
386 |
// Append to facet values
|
|
|
387 |
|
|
|
388 |
Utils.info("facetDefID=" + facetDefID);
|
|
|
389 |
|
|
|
390 |
List<String> facetValues = this.facetIDFacetValues.get(
|
|
|
391 |
new Long(facetDefID));
|
|
|
392 |
|
|
|
393 |
if(facetValues == null) {
|
|
|
394 |
facetValues = new ArrayList<String>();
|
|
|
395 |
this.facetIDFacetValues.put(new Long(facetDefID), facetValues);
|
|
|
396 |
}
|
|
|
397 |
|
|
|
398 |
if(values != null) {
|
|
|
399 |
for(Object value : values) {
|
|
|
400 |
String strValue = value.toString();
|
|
|
401 |
|
|
|
402 |
if(!facetValues.contains(strValue)) {
|
|
|
403 |
facetValues.add(strValue);
|
|
|
404 |
}
|
|
|
405 |
}
|
|
|
406 |
}
|
|
|
407 |
|
|
|
408 |
ExpandedFacetDefinition expFacet = new ExpandedFacetDefinition(facet);
|
|
|
409 |
// Parse returned Python list
|
|
|
410 |
String facetXMLSnip = null;
|
|
|
411 |
if(values != null) {
|
|
|
412 |
facetXMLSnip = this.getFacetXMLSnippet(expFacet, values, 2);
|
|
|
413 |
}
|
|
|
414 |
|
|
|
415 |
Utils.info("0 facetXMLSnip=" + facetXMLSnip);
|
|
|
416 |
return facetXMLSnip;
|
|
|
417 |
}
|
|
|
418 |
|
|
|
419 |
|
|
|
420 |
|
|
|
421 |
/**
|
|
|
422 |
*
|
|
|
423 |
* @param expFacetDef
|
|
|
424 |
* @param values
|
|
|
425 |
* @param indent
|
|
|
426 |
* @return String XML Snippet
|
|
|
427 |
*/
|
|
|
428 |
private String getFacetXMLSnippet(ExpandedFacetDefinition expFacetDef, List<Object> values, int indent) {
|
|
|
429 |
|
|
|
430 |
// <Facet Label="Form Factor">
|
|
|
431 |
List<String> xmlSnippet = new ArrayList<String>();
|
|
|
432 |
String target = expFacetDef.getTarget();
|
|
|
433 |
|
|
|
434 |
xmlSnippet.add(this.xmlIndentation[indent] + "<Facet ID=\"" + expFacetDef.getID() + "\" Label=\"" + target + "\">");
|
|
|
435 |
|
|
|
436 |
//<Value>Candybar</Value>
|
|
|
437 |
for(Object value : values) {
|
| 8266 |
amit.gupta |
438 |
xmlSnippet.add(this.xmlIndentation[indent + 1] + "<Value>" + StringEscapeUtils.escapeXml(value.toString()) + "</Value>");
|
| 2171 |
rajveer |
439 |
}
|
|
|
440 |
|
|
|
441 |
//</Facet>
|
|
|
442 |
xmlSnippet.add(this.xmlIndentation[indent] + "</Facet>");
|
|
|
443 |
|
|
|
444 |
return StringUtils.join(xmlSnippet, "\n");
|
|
|
445 |
}
|
|
|
446 |
|
|
|
447 |
/**
|
|
|
448 |
* @throws Exception
|
|
|
449 |
*
|
|
|
450 |
*/
|
|
|
451 |
public void exportIRData() throws Exception {
|
|
|
452 |
DefinitionsContainer defs = Catalog.getInstance().getDefinitionsContainer();
|
|
|
453 |
Map<Long, List<FacetDefinition>> slideFacets = defs.getSlideFacetDefinitions();
|
|
|
454 |
|
| 2367 |
rajveer |
455 |
for(Entity entity: entities){
|
| 18767 |
amit.gupta |
456 |
try{
|
| 15843 |
amit.gupta |
457 |
Utils.info(entity.getID());
|
| 2367 |
rajveer |
458 |
// <IRData>
|
|
|
459 |
List<String> irDataXMLSnippets = new ArrayList<String>();
|
|
|
460 |
irDataXMLSnippets.add("<IRData>");
|
|
|
461 |
long entityID = entity.getID();
|
|
|
462 |
|
|
|
463 |
//Setting minPrice zero because irdatarule requires float. It wont accept string
|
|
|
464 |
double minPrice = 0;
|
| 2171 |
rajveer |
465 |
ExpandedEntity expEntity = new ExpandedEntity(entity);
|
|
|
466 |
long categoryID = expEntity.getCategoryID();
|
|
|
467 |
List<ExpandedSlide> expSlides = expEntity.getExpandedSlides();
|
|
|
468 |
|
|
|
469 |
List<String> entityXMLSnippets = new ArrayList<String>();
|
|
|
470 |
entityXMLSnippets.add(this.xmlIndentation[1] + "<Entity ID=\""+ entityID +"\">");
|
|
|
471 |
|
|
|
472 |
String parentCategory = expEntity.getCategory().getLabel();
|
|
|
473 |
entityXMLSnippets.add(this.xmlIndentation[2] + "<Category>" + StringEscapeUtils.escapeXml(parentCategory) + "</Category>");
|
|
|
474 |
|
|
|
475 |
|
|
|
476 |
String title = StringEscapeUtils.escapeXml(expEntity.getBrand()) + " " + StringEscapeUtils.escapeXml(expEntity.getModelName()) +
|
|
|
477 |
((expEntity.getModelNumber() != null) ? (" " + StringEscapeUtils.escapeXml(expEntity.getModelNumber())): "");
|
|
|
478 |
|
| 8261 |
amit.gupta |
479 |
entityXMLSnippets.add(this.xmlIndentation[2] + "<Title>" + title + "</Title>");
|
| 2171 |
rajveer |
480 |
|
| 5367 |
rajveer |
481 |
//Boost titles for the mobile phones, laptops and tablets only
|
|
|
482 |
if(expEntity.getCategory().getParentCategory().isHasAccessories() || expEntity.getCategory().getParentCategory().getID() == Utils.TABLETS_CATEGORY || expEntity.getCategory().getParentCategory().getID() == Utils.LAPTOPS_CATEGORY){
|
| 2171 |
rajveer |
483 |
entityXMLSnippets.add(this.xmlIndentation[2] + "<Boost>" + 5 + "</Boost>");
|
|
|
484 |
}else{
|
|
|
485 |
entityXMLSnippets.add(this.xmlIndentation[2] + "<Boost>" + 0 + "</Boost>");
|
|
|
486 |
}
|
|
|
487 |
|
|
|
488 |
|
|
|
489 |
String subCategory = defs.getCategory(categoryID).getLabel();
|
|
|
490 |
String mainCategory = defs.getCategory(categoryID).getParentCategory().getLabel();
|
|
|
491 |
|
| 2500 |
rajveer |
492 |
long mainCatId = defs.getCategory(categoryID).getParentCategory().getID();
|
|
|
493 |
if(mainCatId == Utils.ROOT_CATAGOEY){
|
|
|
494 |
mainCategory = subCategory;
|
|
|
495 |
}
|
|
|
496 |
|
| 2171 |
rajveer |
497 |
String brand = expEntity.getBrand();
|
|
|
498 |
|
|
|
499 |
|
|
|
500 |
|
|
|
501 |
//Create zero slide
|
| 6602 |
amit.gupta |
502 |
Slide zeroSlide = createZeroSlide(brand, minPrice, mainCategory, subCategory, "In Stock");
|
| 2171 |
rajveer |
503 |
ExpandedSlide expandedZeroSlide = new ExpandedSlide(zeroSlide);
|
|
|
504 |
expSlides.add(expandedZeroSlide);
|
|
|
505 |
|
|
|
506 |
for(ExpandedSlide expSlide: expSlides){
|
|
|
507 |
System.out.println(expSlide.getSlideDefinitionID());
|
|
|
508 |
if(slideFacets.containsKey(expSlide.getSlideDefinitionID())){
|
|
|
509 |
List<FacetDefinition> facets = slideFacets.get(expSlide.getSlideDefinitionID());
|
|
|
510 |
for(FacetDefinition facet: facets){
|
|
|
511 |
for(FacetSlideDefinition facetSlides: facet.getFacetSlideDefinitions()){
|
|
|
512 |
if(facetSlides.getSlideDefinitionID() != expSlide.getSlideDefinitionID()){continue;}
|
|
|
513 |
ExpandedFacetSlideDefinition expFacetSlideDef = new ExpandedFacetSlideDefinition(facetSlides) ;
|
|
|
514 |
for(ExpandedFeature expFeature: expSlide.getExpandedFeatures()){
|
|
|
515 |
if(defs.needsNormalization(expFeature.getFeatureDefinitionID())) {
|
|
|
516 |
Utils.info("needsNormalization feature=" + expFeature.getFeatureDefinitionID());
|
|
|
517 |
//expFeature = this.normalize(expFeature);
|
|
|
518 |
}
|
|
|
519 |
}
|
|
|
520 |
entityXMLSnippets.add(processFacet(facet, expSlide, expFacetSlideDef, facet.getID()));
|
|
|
521 |
}
|
|
|
522 |
}
|
|
|
523 |
}
|
|
|
524 |
}
|
|
|
525 |
|
|
|
526 |
// Collect PROPERTIES
|
| 5074 |
amit.gupta |
527 |
List<Long>facetFeatureIds = new ArrayList<Long>();
|
|
|
528 |
facetFeatureIds.add(Utils.BRAND_FEATURE_DEFINITION_ID);
|
|
|
529 |
facetFeatureIds.add(Utils.MAIN_CAT_FEATURE_DEFINITION_ID);
|
|
|
530 |
facetFeatureIds.add(Utils.SUB_CAT_FEATURE_DEFINITION_ID);
|
|
|
531 |
facetFeatureIds.add(Utils.PRICE_FEATURE_DEFINITION_ID);
|
| 6842 |
amit.gupta |
532 |
facetFeatureIds.add(Utils.TAG_FEATURE_DEFINITION_ID);
|
|
|
533 |
|
| 5074 |
amit.gupta |
534 |
String propertiesXMLSnippetsStr = this.getPropertiesXMLSnippet(expEntity, facetFeatureIds, 2);
|
| 2171 |
rajveer |
535 |
entityXMLSnippets.add(propertiesXMLSnippetsStr);
|
|
|
536 |
entityXMLSnippets.add(this.xmlIndentation[1] + "</Entity>");
|
|
|
537 |
System.out.println(entityXMLSnippets);
|
|
|
538 |
irDataXMLSnippets.addAll(entityXMLSnippets);
|
| 2367 |
rajveer |
539 |
irDataXMLSnippets.add("</IRData>");
|
|
|
540 |
String irDataXML = StringUtils.join(irDataXMLSnippets, "\n");
|
|
|
541 |
Utils.info(irDataXML);
|
|
|
542 |
|
|
|
543 |
// Write it to file
|
|
|
544 |
String irDataFilename = Utils.EXPORT_PATH + "xml/intermediate/" + entityID + "_irdata.xml";
|
|
|
545 |
DBUtils.store(irDataXML, irDataFilename);
|
|
|
546 |
transformIrDataXMLtoSolrXML(entityID);
|
| 18767 |
amit.gupta |
547 |
} catch (Exception e){
|
|
|
548 |
Utils.info("Could not process entity:" + entity.getID());
|
| 19109 |
amit.gupta |
549 |
e.printStackTrace();
|
| 2171 |
rajveer |
550 |
}
|
| 18767 |
amit.gupta |
551 |
}
|
| 2171 |
rajveer |
552 |
|
|
|
553 |
|
|
|
554 |
|
| 2367 |
rajveer |
555 |
|
| 2171 |
rajveer |
556 |
}
|
| 2488 |
rajveer |
557 |
|
| 6602 |
amit.gupta |
558 |
private Slide createZeroSlide(String brand, double price, String mainCategory, String subCategory, String availability) {
|
| 2488 |
rajveer |
559 |
Slide zeroSlide = new Slide(Utils.ZERO_SLIDE_DEFINITION_ID);
|
| 2171 |
rajveer |
560 |
List<Feature> zeroSlideFeatures = new ArrayList<Feature>();
|
|
|
561 |
|
| 2488 |
rajveer |
562 |
Feature brandFeature = new Feature(Utils.BRAND_FEATURE_DEFINITION_ID);
|
| 2171 |
rajveer |
563 |
Bullet brandBullet = new Bullet(new PrimitiveDataObject(brand));
|
|
|
564 |
List<Bullet> brandBullets = new ArrayList<Bullet>();
|
|
|
565 |
brandBullets.add(brandBullet);
|
|
|
566 |
brandFeature.setBullets(brandBullets);
|
|
|
567 |
zeroSlideFeatures.add(brandFeature);
|
|
|
568 |
|
| 6602 |
amit.gupta |
569 |
|
|
|
570 |
Feature availabilityFeature = new Feature(Utils.AVAILABILITY_FEATURE_DEFINITION_ID);
|
|
|
571 |
Bullet availabilityBullet = new Bullet(new PrimitiveDataObject(availability));
|
|
|
572 |
List<Bullet> availabilityBullets = new ArrayList<Bullet>();
|
| 6656 |
amit.gupta |
573 |
availabilityBullets.add(availabilityBullet);
|
|
|
574 |
availabilityFeature.setBullets(availabilityBullets);
|
| 6602 |
amit.gupta |
575 |
zeroSlideFeatures.add(availabilityFeature);
|
|
|
576 |
|
| 2171 |
rajveer |
577 |
Feature priceFeature = new Feature(120128);
|
|
|
578 |
Bullet priceBullet = new Bullet(new PrimitiveDataObject((new Double(price)).toString()));
|
|
|
579 |
List<Bullet> priceBullets = new ArrayList<Bullet>();
|
|
|
580 |
priceBullets.add(priceBullet);
|
|
|
581 |
priceFeature.setBullets(priceBullets);
|
|
|
582 |
zeroSlideFeatures.add(priceFeature);
|
|
|
583 |
|
|
|
584 |
Feature mainCategoryFeature = new Feature(120123);
|
|
|
585 |
Bullet mainCategoryBullet = new Bullet(new PrimitiveDataObject(mainCategory));
|
|
|
586 |
List<Bullet> mainCategoryBullets = new ArrayList<Bullet>();
|
|
|
587 |
mainCategoryBullets.add(mainCategoryBullet);
|
|
|
588 |
mainCategoryFeature.setBullets(mainCategoryBullets);
|
|
|
589 |
zeroSlideFeatures.add(mainCategoryFeature);
|
|
|
590 |
|
|
|
591 |
Feature subCategoryFeature = new Feature(120124);
|
|
|
592 |
Bullet subCategoryBullet = new Bullet(new PrimitiveDataObject(subCategory));
|
|
|
593 |
List<Bullet> subCategoryBullets = new ArrayList<Bullet>();
|
|
|
594 |
subCategoryBullets.add(subCategoryBullet);
|
|
|
595 |
subCategoryFeature.setBullets(subCategoryBullets);
|
|
|
596 |
zeroSlideFeatures.add(subCategoryFeature);
|
|
|
597 |
|
| 5074 |
amit.gupta |
598 |
|
|
|
599 |
try {
|
| 5078 |
amit.gupta |
600 |
|
| 5074 |
amit.gupta |
601 |
String brandSynonyms = synonymMap.get("brand").get(brand);
|
|
|
602 |
String subCategorySynonyms = synonymMap.get("subcategory").get(subCategory);
|
|
|
603 |
|
|
|
604 |
if(brandSynonyms != null){
|
|
|
605 |
Feature brandSynonymFeature = new Feature(Utils.BRAND_SYNONYMS_FEATURE_DEFINITION_ID);
|
|
|
606 |
List<Bullet> brandSynonymBullets = new ArrayList<Bullet>();
|
|
|
607 |
for(String brSyn : brandSynonyms.split(",")){
|
|
|
608 |
Bullet brandSynonymBullet = new Bullet(new PrimitiveDataObject(brSyn));
|
|
|
609 |
brandSynonymBullets.add(brandSynonymBullet);
|
|
|
610 |
}
|
|
|
611 |
brandSynonymFeature.setBullets(brandSynonymBullets);
|
|
|
612 |
zeroSlideFeatures.add(brandSynonymFeature);
|
|
|
613 |
}
|
|
|
614 |
|
|
|
615 |
if(subCategorySynonyms != null){
|
|
|
616 |
Feature subCategorySynonymFeature = new Feature(Utils.SUB_CATEGORY_SYNONYMS_FEATURE_DEFINITION_ID);
|
|
|
617 |
List<Bullet> subCategorySynonymBullets = new ArrayList<Bullet>();
|
|
|
618 |
for(String subCatSyn : subCategorySynonyms.split(",")){
|
|
|
619 |
Bullet subCategorySynonymBullet = new Bullet(new PrimitiveDataObject(subCatSyn));
|
|
|
620 |
subCategorySynonymBullets.add(subCategorySynonymBullet);
|
|
|
621 |
}
|
|
|
622 |
subCategorySynonymFeature.setBullets(subCategorySynonymBullets);
|
|
|
623 |
zeroSlideFeatures.add(subCategorySynonymFeature);
|
|
|
624 |
}
|
|
|
625 |
} catch (Exception e) {
|
|
|
626 |
e.printStackTrace();
|
|
|
627 |
}
|
|
|
628 |
|
|
|
629 |
|
|
|
630 |
|
| 2171 |
rajveer |
631 |
zeroSlide.setFeatures(zeroSlideFeatures);
|
|
|
632 |
return zeroSlide;
|
|
|
633 |
}
|
|
|
634 |
|
|
|
635 |
|
|
|
636 |
/**
|
|
|
637 |
*
|
|
|
638 |
* @param feature
|
|
|
639 |
* @return Feature
|
|
|
640 |
* @throws Exception
|
|
|
641 |
*/
|
|
|
642 |
private ExpandedFeature normalize(ExpandedFeature expFeature) throws Exception {
|
|
|
643 |
BulletDefinition bulletDef =
|
|
|
644 |
expFeature.getFeatureDefinition().getBulletDefinition();
|
|
|
645 |
|
|
|
646 |
ExpandedBulletDefinition expBulletDef = new ExpandedBulletDefinition(
|
|
|
647 |
bulletDef);
|
|
|
648 |
|
|
|
649 |
if(expBulletDef.isPrimitive()) {
|
|
|
650 |
PrimitiveNormalizationJythonWrapper jy =
|
|
|
651 |
new PrimitiveNormalizationJythonWrapper();
|
|
|
652 |
|
|
|
653 |
jy.setExpandedFeature(expFeature);
|
|
|
654 |
|
|
|
655 |
jy.excuteRule();
|
|
|
656 |
|
|
|
657 |
String newValue = jy.getNewValue();
|
|
|
658 |
long newUnitID = jy.getNewUnitID();
|
|
|
659 |
|
|
|
660 |
List<Bullet> newBullets = new ArrayList<Bullet>();
|
|
|
661 |
Bullet newBullet = new Bullet(new PrimitiveDataObject(newValue));
|
|
|
662 |
newBullet.setUnitID(newUnitID);
|
|
|
663 |
|
|
|
664 |
newBullets.add(newBullet);
|
|
|
665 |
|
|
|
666 |
expFeature.setBullets(newBullets);
|
|
|
667 |
}
|
|
|
668 |
else {
|
|
|
669 |
Utils.severe("Normalization not defined for non-primitives");
|
|
|
670 |
}
|
|
|
671 |
|
|
|
672 |
return expFeature;
|
|
|
673 |
}
|
|
|
674 |
|
|
|
675 |
/**
|
|
|
676 |
*
|
|
|
677 |
* @param expEntity
|
|
|
678 |
* @param facetFeatureIDs
|
|
|
679 |
* @param indent
|
|
|
680 |
* @return
|
|
|
681 |
*/
|
|
|
682 |
private String getPropertiesXMLSnippet(ExpandedEntity expEntity,
|
|
|
683 |
List<Long> facetFeatureIDs, int indent) {
|
|
|
684 |
|
|
|
685 |
List<String> xmlSnippet = new ArrayList<String>();
|
|
|
686 |
|
|
|
687 |
// Collect all free-form content here
|
|
|
688 |
List<String> ffc = new ArrayList<String>();
|
|
|
689 |
|
|
|
690 |
// Features
|
|
|
691 |
List<ExpandedSlide> expSlides = expEntity.getExpandedSlides();
|
|
|
692 |
|
|
|
693 |
for(ExpandedSlide expSlide : expSlides) {
|
| 5074 |
amit.gupta |
694 |
|
| 2171 |
rajveer |
695 |
List<ExpandedFeature> expFeatures = expSlide.getExpandedFeatures();
|
|
|
696 |
|
|
|
697 |
if(expSlide.getFreeformContent() != null) {
|
|
|
698 |
ffc.add(expSlide.getFreeformContent().getFreeformText());
|
|
|
699 |
}
|
|
|
700 |
|
|
|
701 |
if(expFeatures == null) {
|
|
|
702 |
continue;
|
|
|
703 |
}
|
|
|
704 |
|
|
|
705 |
for(ExpandedFeature expFeature : expFeatures) {
|
|
|
706 |
Long featureDefID =
|
|
|
707 |
new Long(expFeature.getFeatureDefinitionID());
|
|
|
708 |
|
|
|
709 |
// FFC at feature level
|
|
|
710 |
if(expFeature.getFreeformContent() != null) {
|
|
|
711 |
ffc.add(expFeature.getFreeformContent().getFreeformText());
|
|
|
712 |
}
|
|
|
713 |
|
|
|
714 |
// Exclude those who are already covered as facets
|
| 5019 |
amit.gupta |
715 |
// and the ones that are marked false for indexing
|
|
|
716 |
if(facetFeatureIDs.contains(featureDefID) || !expFeature.getFeatureDefinition().isIndexed()) {
|
| 2171 |
rajveer |
717 |
continue;
|
|
|
718 |
}
|
| 6842 |
amit.gupta |
719 |
|
| 2171 |
rajveer |
720 |
List<ExpandedBullet> expBullets =
|
|
|
721 |
expFeature.getExpandedBullets();
|
|
|
722 |
|
|
|
723 |
if(expBullets == null) {
|
|
|
724 |
continue;
|
|
|
725 |
}
|
|
|
726 |
|
|
|
727 |
//<Property Label="">
|
|
|
728 |
xmlSnippet.add(this.xmlIndentation[indent] +
|
|
|
729 |
"<Property ID=\"" + expFeature.getFeatureDefinitionID()
|
|
|
730 |
+ "\" Label=\"" + StringEscapeUtils.escapeXml(
|
|
|
731 |
expFeature.getFeatureDefinition().getLabel()) +
|
|
|
732 |
"\">");
|
|
|
733 |
|
|
|
734 |
//<Value></Value>
|
|
|
735 |
for(ExpandedBullet bullet : expBullets) {
|
| 4270 |
rajveer |
736 |
if(bullet.getValue().trim().equalsIgnoreCase("")){
|
|
|
737 |
continue;
|
|
|
738 |
}
|
| 2171 |
rajveer |
739 |
// FFC at bullet level
|
|
|
740 |
if(bullet.getFreeformContent() != null) {
|
|
|
741 |
ffc.add(bullet.getFreeformContent().getFreeformText());
|
|
|
742 |
}
|
|
|
743 |
|
|
|
744 |
xmlSnippet.add(this.xmlIndentation[indent + 1] + "<Value>" +
|
|
|
745 |
StringEscapeUtils.escapeXml(bullet.getValue()) +
|
|
|
746 |
"</Value>");
|
|
|
747 |
}
|
|
|
748 |
|
|
|
749 |
//</Property>
|
|
|
750 |
xmlSnippet.add(this.xmlIndentation[indent] + "</Property>");
|
|
|
751 |
}
|
|
|
752 |
}
|
|
|
753 |
|
|
|
754 |
// FFC as Label="Free-form Content"
|
|
|
755 |
if(!ffc.isEmpty()) {
|
|
|
756 |
xmlSnippet.add(this.xmlIndentation[indent] +
|
|
|
757 |
"<Property ID=\"000000\" Label=\"Free-form Content\">");
|
|
|
758 |
|
|
|
759 |
for(String f : ffc) {
|
|
|
760 |
if(f != null) {
|
|
|
761 |
f = StringEscapeUtils.escapeXml(f);
|
|
|
762 |
|
|
|
763 |
xmlSnippet.add(this.xmlIndentation[indent + 1] + "<Value>" +
|
|
|
764 |
f + "</Value>");
|
|
|
765 |
}
|
|
|
766 |
}
|
|
|
767 |
|
|
|
768 |
xmlSnippet.add(this.xmlIndentation[indent] + "</Property>");
|
|
|
769 |
}
|
|
|
770 |
|
|
|
771 |
// Children slides
|
|
|
772 |
// TODO
|
| 5074 |
amit.gupta |
773 |
|
| 2171 |
rajveer |
774 |
return StringUtils.join(xmlSnippet, "\n");
|
|
|
775 |
}
|
|
|
776 |
|
|
|
777 |
}
|