Subversion Repositories SmartDukaan

Rev

Rev 81 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 81 Rev 82
Line 64... Line 64...
64
	/**
64
	/**
65
	 * Learns all features where definition is marked "learned=true"
65
	 * Learns all features where definition is marked "learned=true"
66
	 * @throws Exception 
66
	 * @throws Exception 
67
	 */
67
	 */
68
	public void learn() throws Exception {
68
	public void learn() throws Exception {
69
		Map<Long, List<Bullet>> learnedBullets = 
69
		Map<Long, List<ExpandedBullet>> learnedBullets = 
70
			new HashMap<Long, List<Bullet>>();
70
			new HashMap<Long, List<ExpandedBullet>>();
-
 
71
		
-
 
72
		DefinitionsContainer defs = 
-
 
73
			Catalog.getInstance().getDefinitionsContainer();
71
		
74
		
72
		EntityContainer entContainer = 
75
		EntityContainer entContainer = 
73
			Catalog.getInstance().getEntityContainer();
76
			Catalog.getInstance().getEntityContainer();
74
		
77
		
75
		Map<Long, Entity> entities = entContainer.getEntities();
78
		Map<Long, Entity> entities = entContainer.getEntities();
76
 
79
 
77
		// Insert Brand
80
		// Insert Brand
78
		List<Bullet> brandBullets = new ArrayList<Bullet>();
81
		List<ExpandedBullet> brandBullets = new ArrayList<ExpandedBullet>();
79
		learnedBullets.put(new Long(Utils.BRAND_FEATURE_DEFINITION_ID), 
82
		learnedBullets.put(new Long(Utils.BRAND_FEATURE_DEFINITION_ID), 
80
				brandBullets);
83
				brandBullets);
81
		
84
		
-
 
85
		FeatureDefinition brandFeatureDef = 
-
 
86
			defs.getFeatureDefinition(Utils.BRAND_FEATURE_DEFINITION_ID);
-
 
87
		
-
 
88
		BulletDefinition brandBulletDef = brandFeatureDef.getBulletDefinition();
-
 
89
		
82
		for(Entity entity : entities.values()) {
90
		for(Entity entity : entities.values()) {
83
			
91
			
84
			// Brand bullet
92
			// Brand bullet
85
			Bullet brandBullet = new Bullet(
93
			Bullet brandBullet = new Bullet(
86
					new PrimitiveDataObject(entity.getBrand()));
94
					new PrimitiveDataObject(entity.getBrand()));
87
			
95
			
-
 
96
			ExpandedBullet expBrandBullet = new ExpandedBullet(brandBullet, 
-
 
97
					brandBulletDef);
-
 
98
			
88
			if(!brandBullets.contains(brandBullet)) {
99
			if(!brandBullets.contains(expBrandBullet)) {
89
				brandBullets.add(brandBullet);
100
				brandBullets.add(expBrandBullet);
90
			}
101
			}
91
			
102
			
92
			List<Slide> slides = entity.getSlides();
103
			List<Slide> slides = entity.getSlides();
93
			
104
			
94
			for(Slide slide : slides) {
105
			for(Slide slide : slides) {
Line 108... Line 119...
108
	 * 
119
	 * 
109
	 * @param slide
120
	 * @param slide
110
	 * @param learnedBullets
121
	 * @param learnedBullets
111
	 * @throws Exception 
122
	 * @throws Exception 
112
	 */
123
	 */
113
	private void learn(Slide slide, Map<Long, List<Bullet>> learnedBullets) 
124
	private void learn(Slide slide, Map<Long, 
114
		throws Exception {
125
			List<ExpandedBullet>> learnedBullets) throws Exception {
115
		
126
		
116
		DefinitionsContainer defs = 
127
		DefinitionsContainer defs = 
117
			Catalog.getInstance().getDefinitionsContainer();
128
			Catalog.getInstance().getDefinitionsContainer();
118
		
129
		
119
		// Features
130
		// Features
Line 129... Line 140...
129
				BulletDefinition bulletDef = featureDef.getBulletDefinition();
140
				BulletDefinition bulletDef = featureDef.getBulletDefinition();
130
				
141
				
131
				if (!bulletDef.isLearned()) {
142
				if (!bulletDef.isLearned()) {
132
					continue;
143
					continue;
133
				}
144
				}
-
 
145
 
-
 
146
				// Store expanded bullets to facilitate easy 
-
 
147
				// processing later
-
 
148
				ExpandedFeature expandedFeature = new ExpandedFeature(feature);
-
 
149
				
-
 
150
				List<ExpandedBullet> expBullets = 
-
 
151
					expandedFeature.getExpandedBullets();
134
				
152
				
135
				List<Bullet> bullets = feature.getBullets();
-
 
136
				if(bullets != null) {
153
				if(expBullets != null) {
137
					
154
					
138
					List<Bullet> collectedBullets = 
155
					List<ExpandedBullet> collectedBullets = 
139
						learnedBullets.get(new Long(featureDefID));
156
						learnedBullets.get(new Long(featureDefID));
140
					
157
					
141
					if(collectedBullets == null) {
158
					if(collectedBullets == null) {
142
						collectedBullets = new ArrayList<Bullet>();
159
						collectedBullets = new ArrayList<ExpandedBullet>();
143
					}
160
					}
144
					
161
					
145
					for(Bullet bullet : bullets) {
162
					for(ExpandedBullet expBullet : expBullets) {
146
						if(!collectedBullets.contains(bullet)) {
163
						if(!collectedBullets.contains(expBullet)) {
-
 
164
							
147
							collectedBullets.add(bullet);
165
							collectedBullets.add(expBullet);
148
						}
166
						}
149
					}
167
					}
150
					
168
					
151
					learnedBullets.put(new Long(featureDefID), 
169
					learnedBullets.put(new Long(featureDefID), 
152
							collectedBullets);
170
							collectedBullets);