Subversion Repositories SmartDukaan

Rev

Rev 5155 | Rev 5566 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5155 Rev 5404
Line 1... Line 1...
1
package in.shop2020.util;
1
package in.shop2020.util;
2
 
2
 
3
import java.util.ArrayList;
-
 
4
import java.util.HashMap;
-
 
5
import java.util.List;
-
 
6
import java.util.Map;
-
 
7
 
-
 
8
import in.shop2020.metamodel.core.Entity;
3
import in.shop2020.metamodel.core.Entity;
9
import in.shop2020.metamodel.core.Slide;
4
import in.shop2020.metamodel.core.Slide;
10
import in.shop2020.metamodel.definitions.Catalog;
5
import in.shop2020.metamodel.definitions.Catalog;
11
import in.shop2020.metamodel.definitions.Category;
6
import in.shop2020.metamodel.definitions.Category;
12
import in.shop2020.metamodel.definitions.DefinitionsContainer;
7
import in.shop2020.metamodel.definitions.DefinitionsContainer;
13
import in.shop2020.metamodel.util.CreationUtils;
8
import in.shop2020.metamodel.util.CreationUtils;
14
 
9
 
-
 
10
import java.util.ArrayList;
-
 
11
import java.util.Arrays;
-
 
12
import java.util.HashMap;
-
 
13
import java.util.List;
-
 
14
import java.util.Map;
-
 
15
 
-
 
16
import org.apache.commons.lang.StringUtils;
-
 
17
 
15
public class CompatibleAccessoriesIndexGenerator {
18
public class CompatibleAccessoriesIndexGenerator {
16
 
19
 
17
	private String[] indentation = {"", "    ", "        ", "            ","                "};
20
	private String[] indentation = {"", "    ", "        ", "            ","                "};
18
	private DefinitionsContainer defContainer = Catalog.getInstance().getDefinitionsContainer();
21
	private DefinitionsContainer defContainer = Catalog.getInstance().getDefinitionsContainer();
19
	List<Entity> entities;
22
	List<Entity> entities;
20
	private Map<Long, Long> categorySlides = new HashMap<Long, Long>();
23
	private Map<Long, Long> categorySlides = new HashMap<Long, Long>();
21
	private Map<Long, String> categoryLabels = new HashMap<Long, String>();
24
	private Map<Long, String> categoryLabels = new HashMap<Long, String>();
-
 
25
 
-
 
26
	private Map<Long, List<String>> categorySynonyms = new HashMap<Long, List<String>>();
-
 
27
	private Map<String, List<String>> brandSynonyms = new HashMap<String, List<String>>();
22
	
28
	
23
	public CompatibleAccessoriesIndexGenerator(List<Entity> entities) throws Exception	{
29
	public CompatibleAccessoriesIndexGenerator(List<Entity> entities) throws Exception	{
24
		
30
		
25
		categorySlides.put((long) 10014, (long) 130067);
31
		categorySlides.put((long) 10014, (long) 130067);
26
		categorySlides.put((long) 10018, (long) 130073);
32
		categorySlides.put((long) 10018, (long) 130073);
27
		
33
		
28
		categoryLabels.put((long) 10014, "Battery");
34
		categoryLabels.put((long) 10014, "Battery");
29
		categoryLabels.put((long) 10018, "Carrying Case");
35
		categoryLabels.put((long) 10018, "Carrying Case");
-
 
36
 
-
 
37
		Map<String, String> brSynonyms = new HashMap<String, String>(); 
-
 
38
		Map<String, String> catSynonyms = new HashMap<String, String>();
-
 
39
		
-
 
40
		
-
 
41
		try {
-
 
42
			brSynonyms =  CreationUtils.getSynonyms().get("brand");
-
 
43
			catSynonyms =  CreationUtils.getSynonyms().get("subcategory");
-
 
44
			
-
 
45
			for(String brand : brSynonyms.keySet()){
-
 
46
				List<String> brandSyns = Arrays.asList((brand + "," + StringUtils.defaultString(brSynonyms.get(brand))).split(","));
-
 
47
				brandSynonyms.put(brand, brandSyns);
-
 
48
			}
-
 
49
		} catch (Exception e) {
-
 
50
			// TODO: handle exception
-
 
51
		}
-
 
52
		catSynonyms.put("Battery", StringUtils.defaultString("Battery," + StringUtils.defaultString(catSynonyms.get("Battery"))));
-
 
53
		catSynonyms.put("Carrying Case", StringUtils.defaultString("Carrying Case," + StringUtils.defaultString(catSynonyms.get("Carrying Case"))));
30
		
54
		
-
 
55
		categorySynonyms.put((long) 10014, Arrays.asList(catSynonyms.get("Battery").split(",")));
-
 
56
		categorySynonyms.put((long) 10018, Arrays.asList(catSynonyms.get("Carrying Case").split(",")));
31
		this.entities = entities;
57
		this.entities = entities;
32
	}
58
	}
33
	
59
	
34
	public void generate()	{
60
	public void generate()	{
35
		StringBuilder sb = new StringBuilder();
61
		StringBuilder sb = new StringBuilder();
Line 45... Line 71...
45
				
71
				
46
				try {
72
				try {
47
					String text = compatibilitySlide.getFreeformContent().getFreeformText();
73
					String text = compatibilitySlide.getFreeformContent().getFreeformText();
48
					
74
					
49
					if(text.indexOf("<ul>") > -1)	continue;
75
					if(text.indexOf("<ul>") > -1)	continue;
50
					
-
 
51
					for(String name: getHandsetNames(text))	{
76
					for(String name: getHandsetNames(text))	{
-
 
77
						for(String categoryLabel : getCategorySynonyms(categoryId)){
52
						sb.append(indentation[1] + "<div>\n");
78
							sb.append(indentation[1] + "<div>\n");
53
						sb.append(indentation[2] + "<a href='" + url + "'>" + name + " " + categoryLabels.get(categoryId)+ "</a>\n");
79
							sb.append(indentation[2] + "<a href='" + url + "'>" + name + " " + categoryLabel + "</a>\n");
54
						sb.append(indentation[1] + "</div>\n");
80
							sb.append(indentation[1] + "</div>\n");
-
 
81
						}
55
					}
82
					}
56
					
83
					
57
				} catch (NullPointerException e) {
84
				} catch (NullPointerException e) {
58
					// TODO: handle exception
85
					// TODO: handle exception
59
				}
86
				}
Line 95... Line 122...
95
		
122
		
96
		List<String> names = new ArrayList<String>();
123
		List<String> names = new ArrayList<String>();
97
		
124
		
98
		for (String namesWithSameBrand: rawText.trim().split("\n"))	{
125
		for (String namesWithSameBrand: rawText.trim().split("\n"))	{
99
			boolean isFirst = true;
126
			boolean isFirst = true;
100
			String brand = "";
127
			List<String> brandSynonyms = null;
101
			
128
			
102
			for(String name: namesWithSameBrand.trim().split(","))	{
129
			for(String name: namesWithSameBrand.trim().split(","))	{
103
				name = name.trim();
130
				name = name.trim();
104
				
131
				String [] brandName;
105
				if(isFirst)	{
132
				if(isFirst)	{
-
 
133
					brandName = name.split(" ", 2);
-
 
134
					if(brandName.length==1){
106
					names.add(name);
135
						continue;
-
 
136
					}
-
 
137
					if(brandName[1].startsWith("Ericsson")) {
-
 
138
						brandName[0] = "Sony Ericsson";
107
					brand = name.split(" ")[0];
139
						brandName[1] = brandName[1].substring(9);
-
 
140
					}
-
 
141
					brandSynonyms = getBrandSynonyms(brandName[0]);
-
 
142
					name = brandName[1];
108
					isFirst = false;
143
					isFirst = false;
109
				} else	{
144
				} 
-
 
145
				for(String brand : brandSynonyms){
110
					names.add(brand + " " + name);
146
					names.add(brand + " " + name);
111
				}
147
				}
-
 
148
				
112
			}
149
			}
113
		}
150
		}
114
		return names;
151
		return names;
115
	}
152
	}
116
	
153
	
-
 
154
	private List<String> getBrandSynonyms(String brand) {
-
 
155
		if(!brandSynonyms.containsKey(brand)){
-
 
156
			List<String> list = new ArrayList<String>();
-
 
157
			list.add(brand);
-
 
158
			brandSynonyms.put(brand, list);
-
 
159
		}
-
 
160
		return brandSynonyms.get(brand);
-
 
161
	}
-
 
162
 
-
 
163
	private List<String> getCategorySynonyms(Long categoryId) {
-
 
164
		return categorySynonyms.get(categoryId);
-
 
165
	}
-
 
166
	
-
 
167
	
-
 
168
 
117
	public static void main(String[] args) {
169
	public static void main(String[] args) {
118
		try {
170
		try {
119
			List<Entity> entities = new ArrayList<Entity>(CreationUtils.getEntities().values());
171
			List<Entity> entities = new ArrayList<Entity>(CreationUtils.getEntities().values());
120
			CompatibleAccessoriesIndexGenerator generator = new CompatibleAccessoriesIndexGenerator(entities);
172
			CompatibleAccessoriesIndexGenerator generator = new CompatibleAccessoriesIndexGenerator(entities);
121
			generator.generate();
173
			generator.generate();