Rev 1678 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
package in.shop2020.util;import in.shop2020.metamodel.core.Bullet;import in.shop2020.metamodel.core.Entity;import in.shop2020.metamodel.core.Feature;import in.shop2020.metamodel.core.Slide;import in.shop2020.metamodel.definitions.Catalog;import in.shop2020.metamodel.definitions.DefinitionsContainer;import in.shop2020.metamodel.definitions.FeatureDefinition;import in.shop2020.metamodel.definitions.SlideDefinition;import in.shop2020.metamodel.definitions.SlideFeatureDefinition;import in.shop2020.metamodel.util.CreationUtils;import in.shop2020.metamodel.util.ExpandedBullet;import in.shop2020.metamodel.util.ExpandedFeature;import java.io.File;import java.io.FileOutputStream;import java.io.FileWriter;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;public class FeatureValueExtractor {List<Long> featureIds = new ArrayList<Long>();public Map<Long, String> extractFeatureValuesForEntity(Entity entity) throws Exception{Map<Long, String> featureIdValuesMap = new HashMap<Long, String>();for(Slide slide: entity.getSlides()){if(slide.hasChildrenSlides()){for(Slide sl: slide.getChildrenSlides()){if(sl.getFeatures()!=null){slide.getFeatures().addAll(sl.getFeatures());}if(sl.hasChildrenSlides()){for(Slide sl2: sl.getChildrenSlides()){if(sl2.getFeatures()!=null){slide.getFeatures().addAll(sl2.getFeatures());}}}}}for(Feature feature: slide.getFeatures()){if(featureIds.contains(feature.getFeatureDefinitionID())){String value = "";ExpandedFeature expFeature = new ExpandedFeature(feature);if(expFeature.getExpandedBullets()!=null){int count = 0;for(ExpandedBullet expBullet: expFeature.getExpandedBullets()){if(count==0){value = value + expBullet.displayText();}else{value = value + " -- " + expBullet.displayText();}count++;}}featureIdValuesMap.put(feature.getFeatureDefinitionID(), value);}}}return featureIdValuesMap;}public StringBuffer printFeatureValues() throws Exception{StringBuffer featureValuesString = new StringBuffer();featureValuesString.append("Category Name" + "\t");featureValuesString.append("Entity Name" + "\t");featureValuesString.append("EntityID" + "\t");for(Long featureId : featureIds){featureValuesString.append(Catalog.getInstance().getDefinitionsContainer().getFeatureDefinition(featureId).getLabel() + "\t");}featureValuesString.append("\n");for(Entity entity: CreationUtils.getEntities().values()){if(entity == null || entity.getSlides() == null || Catalog.getInstance().getDefinitionsContainer().getCategory(entity.getCategoryID()).getParentCategory().getID() != 10001){continue;}featureValuesString.append(Catalog.getInstance().getDefinitionsContainer().getCategory(entity.getCategoryID()).getLabel() + "\t");featureValuesString.append(entity.getBrand()+ " " + entity.getModelName() + " " + entity.getModelNumber() + "\t");featureValuesString.append(entity.getID() + "\t");Map<Long, String> fvalues = extractFeatureValuesForEntity(entity);for(Long featureId : featureIds){if(fvalues.get(featureId)!=null){featureValuesString.append(fvalues.get(featureId).trim() + "\t");}else{featureValuesString.append("\t");}}featureValuesString.append("\n");}return featureValuesString;}public static void main(String[] args) throws Exception{FeatureValueExtractor extractor = new FeatureValueExtractor();DefinitionsContainer dfc = Catalog.getInstance().getDefinitionsContainer();List<SlideDefinition> slideDefs = dfc.getSlideDefinitions(10002);for(SlideDefinition slideDef: slideDefs){for(SlideFeatureDefinition sfDef: slideDef.getSlideFeatureDefinitions()){long fid = sfDef.getFeatureDefintionID();if(!extractor.featureIds.contains(fid)){extractor.featureIds.add(fid);}}if(slideDef.hasChildren()){for(long slideid: slideDef.getChildrenSlideDefinitionIDs()){for(SlideFeatureDefinition sfDef: dfc.getSlideDefinition(slideid).getSlideFeatureDefinitions()){long fid = sfDef.getFeatureDefintionID();if(!extractor.featureIds.contains(fid)){extractor.featureIds.add(fid);}}if(dfc.getSlideDefinition(slideid).hasChildren()){for(long slideid2: dfc.getSlideDefinition(slideid).getChildrenSlideDefinitionIDs()){for(SlideFeatureDefinition sfDef: dfc.getSlideDefinition(slideid2).getSlideFeatureDefinitions()){long fid = sfDef.getFeatureDefintionID();if(!extractor.featureIds.contains(fid)){extractor.featureIds.add(fid);}}}}}}}for(long fid: Catalog.getInstance().getDefinitionsContainer().getFeatureDefinitionIDs(10002)){if(!extractor.featureIds.contains(fid)){extractor.featureIds.add(fid);}}for(long fid: Catalog.getInstance().getDefinitionsContainer().getFeatureDefinitionIDs(10003)){if(!extractor.featureIds.contains(fid)){extractor.featureIds.add(fid);}}for(long fid: Catalog.getInstance().getDefinitionsContainer().getFeatureDefinitionIDs(10004)){if(!extractor.featureIds.contains(fid)){extractor.featureIds.add(fid);}}for(long fid: Catalog.getInstance().getDefinitionsContainer().getFeatureDefinitionIDs(10005)){if(!extractor.featureIds.contains(fid)){extractor.featureIds.add(fid);}}/*extractor.featureIds.add(120001L);extractor.featureIds.add(120002L);extractor.featureIds.add(120003L);extractor.featureIds.add(120008L);extractor.featureIds.add(120005L);extractor.featureIds.add(120006L);extractor.featureIds.add(120007L);extractor.featureIds.add(120009L);extractor.featureIds.add(120010L);extractor.featureIds.add(120082L);extractor.featureIds.add(120048L);extractor.featureIds.add(120049L);extractor.featureIds.add(120127L);extractor.featureIds.add(120011L);extractor.featureIds.add(120014L);extractor.featureIds.add(120015L);extractor.featureIds.add(120016L);extractor.featureIds.add(120017L);extractor.featureIds.add(120018L);extractor.featureIds.add(120019L);extractor.featureIds.add(120021L);extractor.featureIds.add(120023L);extractor.featureIds.add(120051L);extractor.featureIds.add(120022L);extractor.featureIds.add(120052L);extractor.featureIds.add(120020L);extractor.featureIds.add(120024L);extractor.featureIds.add(120025L);extractor.featureIds.add(120053L);extractor.featureIds.add(120026L);extractor.featureIds.add(120027L);extractor.featureIds.add(120028L);extractor.featureIds.add(120056L);extractor.featureIds.add(120058L);extractor.featureIds.add(120029L);extractor.featureIds.add(120030L);extractor.featureIds.add(120031L);extractor.featureIds.add(120032L);extractor.featureIds.add(120033L);extractor.featureIds.add(120072L);extractor.featureIds.add(120073L);extractor.featureIds.add(120076L);extractor.featureIds.add(120043L);extractor.featureIds.add(120044L);extractor.featureIds.add(120045L);extractor.featureIds.add(120122L);extractor.featureIds.add(120046L);*/StringBuffer featureValuesString = extractor.printFeatureValues();File f = new File("/home/rajveer/Desktop/cms/featurevalues.txt");FileWriter writer = new FileWriter(f);writer.write(featureValuesString.toString());writer.close();}}