}
// ignore self relations
if (!childCUI.equals(parentCUI)) {
boolean parNull = false;
// get parent from cui map
ConcRel crPar = cg.getConceptMap().get(parentCUI);
if (crPar == null) {
parNull = true;
// parent not in cui map - add it
crPar = cg.addConcept(parentCUI);
// this is a candidate root - add it to the set of roots
roots.add(parentCUI);
}
// get the child cui
ConcRel crChild = cg.getConceptMap().get(childCUI);
// crPar already has crChild, return
if (crChild != null && crPar.getChildren().contains(crChild))
return;
// avoid cycles - don't add child cui if it is an ancestor
// of the parent. if the child is not yet in the map, then it can't
// possibly induce a cycle.
// if the parent is not yet in the map, it can't induce a cycle
// else check for cycles
// @TODO: this is very inefficient. implement feedback arc algo
boolean bCycle = !parNull && crChild != null && checkCycle
&& checkCycle(crPar, crChild);
if (bCycle) {
log.warn("skipping relation that induces cycle: par="
+ parentCUI + ", child=" + childCUI);
} else {
if (crChild == null) {
// child not in cui map - add it
crChild = cg.addConcept(childCUI);
} else {
// remove the cui from the list of candidate roots
if (roots.contains(childCUI))
roots.remove(childCUI);
}
// link child to parent and vice-versa
crPar.getChildren().add(crChild);
crChild.getParents().add(crPar);
}
}
}