Révision 2762

tmp/org.txm.annotation.kr.core/src/org/txm/annotation/kr/core/storage/temporary/TemporaryAnnotationManager.java (revision 2762)
36 36
		File path = new File(corpus.getProjectDirectory(), "temporary_annotations/" + corpus.getID() + "/db");
37 37
		path.getParentFile().mkdirs();
38 38
		
39
		HashMap<String, Object> properties = new HashMap<String, Object>();
39
		HashMap<String, Object> properties = new HashMap<>();
40 40
		// System.out.println("CLASSLOADER: "+Toolbox.class.getClassLoader());
41 41
		properties.put(PersistenceUnitProperties.CLASSLOADER, clazz.getClassLoader());
42 42
		properties.put("javax.persistence.jdbc.driver", "org.hsqldb.jdbcDriver");
......
125 125
	public List<Annotation> createAnnotationNoCommit(AnnotationType type, TypedValue value, int startPos, int endPos) throws Exception {
126 126
		AnnotationPK pkannot = new AnnotationPK(startPos, endPos, type.getId());
127 127
		Annotation annot = em.find(Annotation.class, pkannot);
128
		List<Annotation> overlapingAnnotations = new ArrayList<Annotation>();
128
		List<Annotation> overlapingAnnotations = new ArrayList<>();
129 129
		if (annot == null) { // create annotation
130 130
			
131 131
			if (type.getEffect().equals(AnnotationEffect.SEGMENT)) {
132 132
				// check if it does not already exist, with either one of the positions (overlaps)
133 133
				// isOverlapAnnots = isOverlapAnnotationCritical(refType, refVal, startPos, endPos);
134
				ArrayList<Match> matches = new ArrayList<Match>();
134
				ArrayList<Match> matches = new ArrayList<>();
135 135
				matches.add(new Match2P(startPos, endPos));
136 136
				overlapingAnnotations = getAnnotations(null, matches, null, false, true); // getAll annotation ovelapping with startPos-endPos
137 137
				for (int i = 0; i < overlapingAnnotations.size(); i++) { // parse overlapping annotations to remove wrapping annotation with different type and annotation with same type and same
......
176 176
				annot = new Annotation(type.getId(), value.getId(), startPos, endPos);
177 177
				
178 178
				em.persist(annot);
179
				
180 179
				// System.out.println("--- Create : "+annot.toString());
181 180
			}
182 181
		}
183 182
		else { // update annotation
184
			// UPDATE
185
			// System.out.println("--- Update annot : "+annot.toString()+" ----- ");
183
				 // UPDATE
184
				 // System.out.println("--- Update annot : "+annot.toString()+" ----- ");
186 185
			annot.setReferentielVal(value.getId());
187 186
		}
188 187
		return overlapingAnnotations;
......
197 196
	 * @throws Exception
198 197
	 */
199 198
	public List<Annotation> createAnnotations(AnnotationType type, TypedValue value, List<Match> matches) throws Exception {
200
		List<Annotation> isOverlappedWithAnnots = new ArrayList<Annotation>();
199
		List<Annotation> isOverlappedWithAnnots = new ArrayList<>();
201 200
		em.getTransaction().begin(); // mandatory ! :@
202 201
		for (Match m : matches) {
203 202
			int t = m.getTarget();
......
399 398
	}
400 399
	
401 400
	public List<Annotation> getAnnotationsForMatches(List<Match> matches, List<Annotation> annotations, boolean overlap) {
402
		List<Annotation> annotsList = new ArrayList<Annotation>();
401
		List<Annotation> annotsList = new ArrayList<>();
403 402
		
404 403
		int iMatch = 0;
405 404
		int iAnnotation = 0;
......
504 503
		
505 504
		EntityManagerFactory emf = pp.createEntityManagerFactory(DatabasePersistenceManager.PERSISTENCE_UNIT_NAME, properties);
506 505
		
507
		em = (EntityManager) emf.createEntityManager();
506
		em = emf.createEntityManager();
508 507
		
509 508
		return em;
510 509
	}
tmp/org.txm.annotation.kr.core/src/org/txm/annotation/kr/core/AnnotationManager.java (revision 2762)
16 16
import org.txm.objects.Match;
17 17
import org.txm.objects.Match2P;
18 18
import org.txm.searchengine.cqp.corpus.MainCorpus;
19
import org.txm.utils.ConsoleProgressBar;
19 20
import org.txm.utils.logger.Log;
20 21

  
21 22
/**
......
177 178
	 */
178 179
	public List<Annotation> getAnnotationsForMatches(AnnotationType type, List<Match> matches, boolean overlap) {
179 180
		List<Annotation> temporaryAnnotations = null;
180
		List<Annotation> resultAnnotations = new ArrayList<Annotation>();
181
		List<Annotation> resultAnnotations = new ArrayList<>();
181 182
		try {
182 183
			temporaryAnnotations = tempManager.getAnnotations(type, matches, null, false, overlap);
183 184
			temporaryAnnotations = tempManager.getAnnotationsForMatches(matches, temporaryAnnotations, overlap);
......
188 189
			// System.out.println("CQP annotations: "+cqpAnnotations);
189 190
			if (cqpAnnotations.size() != matches.size() || temporaryAnnotations.size() != matches.size()) {
190 191
				System.out.println("ERROR in getAnnotationsForMatches methods! ");
191
				return new ArrayList<Annotation>(matches.size());
192
				return new ArrayList<>(matches.size());
192 193
			}
193 194
			// merge the 2 results
194 195
			for (int i = 0; i < matches.size(); i++) {
......
208 209
		}
209 210
		catch (Exception e) {
210 211
			e.printStackTrace();
211
			return new ArrayList<Annotation>(matches.size());
212
			return new ArrayList<>(matches.size());
212 213
		}
213 214
		return resultAnnotations;
214 215
	}
......
248 249
	public HashMap<Match, List<Annotation>> createAnnotations(AnnotationType annotSelectedType,
249 250
			TypedValue annotSelectedTypedValue, List<? extends Match> matches, IProgressMonitor job) {
250 251
		
251
		HashMap<Match, List<Annotation>> allAnnotationsThatCollides = new HashMap<Match, List<Annotation>>();
252
		HashMap<Match, List<Annotation>> allAnnotationsThatCollides = new HashMap<>();
252 253
		tempManager.getEntityManager().getTransaction().begin(); // warning
254
		int nCreation = 0;
255
		ConsoleProgressBar cpb = new ConsoleProgressBar(matches.size());
256
		long t = System.currentTimeMillis();
253 257
		for (Match match : matches) {
258
			cpb.tick();
254 259
			allAnnotationsThatCollides.put(match, new ArrayList<Annotation>());
255 260
			
256 261
			int start, end;
......
290 295
				}
291 296
				else {
292 297
					// no need to test collision (AnnotationType=TOKEN)
293
					cqpAnnotations = new ArrayList<Annotation>();
298
					cqpAnnotations = new ArrayList<>();
294 299
				}
295 300
				
296 301
				if (cqpAnnotations.size() > 0) {
......
308 313
					if (tempAnnotations.size() > 0)
309 314
						allAnnotationsThatCollides.get(match).addAll(tempAnnotations);
310 315
				}
316
				
317
				nCreation++;
318
				
319
				if ((nCreation % 1000) == 0) {
320
					tempManager.getEntityManager().flush(); // warning
321
					tempManager.getEntityManager().clear(); // warning
322
				}
323
				if ((nCreation % 20000) == 0) {
324
					tempManager.getEntityManager().getTransaction().commit(); // warning
325
					tempManager.getEntityManager().getTransaction().begin(); // warning
326
				}
327
				
311 328
			}
312
			catch (Exception e) {
329
			catch (Throwable e) {
313 330
				Log.printStackTrace(e);
314 331
				System.out.println("Error during annotation creation: " + e);
332
				if (tempManager.getEntityManager().getTransaction().isActive()) {
333
					tempManager.getEntityManager().getTransaction().rollback(); // reset state
334
				}
315 335
			}
316 336
			
317 337
			if (allAnnotationsThatCollides.get(match).size() == 0) allAnnotationsThatCollides.remove(match); // keep only colision lists
318 338
		}
339
		
340
		cpb.done();
341
		System.out.println("T=" + (System.currentTimeMillis() - t));
342
		
319 343
		dirty = true;
320 344
		tempManager.getEntityManager().getTransaction().commit(); // warning
321 345
		return allAnnotationsThatCollides;

Formats disponibles : Unified diff