Map<KiWiTriple,Collection<Justification>> justificationCache = new HashMap<KiWiTriple, Collection<Justification>>();
for(Justification justification : justifications) {
KiWiTriple triple = justification.getTriple();
Justification newJustification = new Justification();
newJustification.setSupportingRules(justification.getSupportingRules());
newJustification.setTriple(triple);
Set<Justification> tripleJustifications = Collections.singleton(newJustification);
// resolve inferred triples by replacing them by their justifications
for(KiWiTriple support : justification.getSupportingTriples()) {
if(support.isInferred()) {
Collection<Justification> supportJustifications = justificationCache.get(support);
// cache justifications of triple in case they are needed again in this run
if(supportJustifications == null || supportJustifications.size() == 0) {
supportJustifications = getJustifications(connection, support, baseJustifications);
justificationCache.put(support,supportJustifications);
}
if(supportJustifications.size() == 0) {
log.error("error: inferred triple {} is not justified!",support);
}
// mix the two sets
Set<Justification> oldTripleJustifications = tripleJustifications;
tripleJustifications = new HashSet<Justification>();
for(Justification j1 : oldTripleJustifications) {
for(Justification j2 : supportJustifications) {
Justification j3 = new Justification();
j3.setTriple(triple);
j3.getSupportingTriples().addAll(j1.getSupportingTriples());
j3.getSupportingTriples().addAll(j2.getSupportingTriples());
j3.getSupportingRules().addAll(j1.getSupportingRules());
j3.getSupportingRules().addAll(j2.getSupportingRules());
tripleJustifications.add(j3);
}
}
} else {
for(Justification j : tripleJustifications) {