ComparisonSetCollator extends DiffCollator { public void collate(ComparisonSet comparisonSet, CollatorConfig config, BackgroundTaskStatus taskStatus) throws IOException { this.comparisonSet = comparisonSet; this.witnessList = this.setDao.getWitnesses(comparisonSet); this.comparisonSet.setStatus(ComparisonSet.Status.COLLATING); this.setDao.update(this.comparisonSet); final Set<Witness> witnesses = new HashSet<Witness>( this.witnessList ); final CollatorConfigAdapter configAdapter = new CollatorConfigAdapter(config); final BackgroundTaskSegment ts = taskStatus.add(1, new BackgroundTaskSegment((witnesses.size() * (witnesses.size() - 1)) / 2)); taskStatus.setNote("Collating SET " + JSONObject.escape(comparisonSet.getName())); LOG.info("Collating " + comparisonSet); try { for (Iterator<Witness> baseIt = witnesses.iterator(); baseIt.hasNext(); ) { final Witness base = baseIt.next(); baseIt.remove(); for (Witness witness : witnesses) { taskStatus.setNote(base.getJsonName() + " vs. " + witness.getJsonName()); LOG.info("Collating: " + base + " vs. " + witness); collate(configAdapter, base, witness); configAdapter.getDifferenceStore().save(); ts.incrementValue(); } } this.comparisonSet.setStatus(ComparisonSet.Status.COLLATED); this.setDao.update(this.comparisonSet); } catch ( OutOfMemoryError oom ) { LOG.error("Not enough memory to collate "+this.comparisonSet); this.comparisonSet.setStatus(ComparisonSet.Status.ERROR); this.setDao.update(this.comparisonSet); } catch ( Exception e ) { LOG.error("Collation of "+this.comparisonSet+" FAILED",e); this.comparisonSet.setStatus(ComparisonSet.Status.ERROR); this.setDao.update(this.comparisonSet); } }  void collate(ComparisonSet comparisonSet, CollatorConfig config, BackgroundTaskStatus taskStatus);  }
@Test public void simpleCase() throws Exception { final Workspace pub = this.workspaceDao.getPublic(); final String w1Contents = "The quick brown fox died."; final String w2Contents = "Quick red fox got rabies and died."; final String w3Contents = "The quick blue fox lives."; final Long srcId1 = this.sourceDao.create(pub, "w1.src", Source.Type.TXT, new StringReader(w1Contents)); final Source src1 = this.sourceDao.find(pub.getId(), srcId1); final Long srcId2 = this.sourceDao.create(pub, "w2.src", Source.Type.TXT, new StringReader(w2Contents)); final Source src2 = this.sourceDao.find(pub.getId(), srcId2); final Long srcId3 = this.sourceDao.create(pub, "w3.src", Source.Type.TXT, new StringReader(w3Contents)); final Source src3 = this.sourceDao.find(pub.getId(), srcId3); final Witness w1 = new Witness(); w1.setName("w1"); w1.setSourceId(srcId2); w1.setText(src1.getText()); w1.setWorkspaceId(pub.getId()); w1.setId(witnessDao.create(w1)); final Witness w2 = new Witness(); w2.setName("w2"); w2.setSourceId(src2.getId()); w2.setText(src2.getText()); w2.setWorkspaceId(pub.getId()); w2.setId(witnessDao.create(w2)); final Witness w3 = new Witness(); w3.setName("w3"); w3.setSourceId(src3.getId()); w3.setText(src3.getText()); w3.setWorkspaceId(pub.getId()); w3.setId(witnessDao.create(w3)); final ComparisonSet comparisonSet = new ComparisonSet(); comparisonSet.setName("test"); comparisonSet.setWorkspaceId(pub.getId()); comparisonSetDao.create(comparisonSet); comparisonSetDao.addWitnesses(comparisonSet, Sets.newHashSet(w1, w2, w3)); CollatorConfig cfg = this.comparisonSetDao.getCollatorConfig(comparisonSet); tokenizer.tokenize(comparisonSet, cfg, new BackgroundTaskStatus("tokenize")); collator.collate(comparisonSet, cfg, new BackgroundTaskStatus("collate")); LOG.debug("["+w2Contents+"] vs ["+w3Contents+"]"); AlignmentConstraint constraint = new AlignmentConstraint(comparisonSet); constraint.addWitnessIdFilter(w2.getId()); constraint.addWitnessIdFilter(w3.getId()); for (Alignment align : this.alignmentDao.list(constraint) ) { final StringBuilder rowStr = new StringBuilder(); AlignedAnnotation a = align.getWitnessAnnotation(w2.getId()); rowStr.append("[").append(substringOf(w2Contents, a.getRange())).append("]"); rowStr.append(" ").append(a.getRange()); rowStr.append(" <===> "); a = align.getWitnessAnnotation(w3.getId()); rowStr.append("[").append(substringOf(w3Contents, a.getRange())).append("]"); rowStr.append(" ").append(a.getRange()); LOG.debug(rowStr.toString()); } }