*/
@Override
public void createConceptGraph(String dir, String name, String query,
final boolean checkCycle, final Set<String> forbiddenConcepts)
throws IOException {
ConceptGraph conceptGraph = this.readConceptGraph(name);
if (conceptGraph != null) {
if (log.isWarnEnabled())
log.warn("createConceptGraph(): concept graph already exists, will not create a new one. Delete existing concept graph if you want to recreate it.");
} else {
String outputDir = dir;
if (Strings.isNullOrEmpty(outputDir)) {
outputDir = getDefaultConceptGraphDir();
}
if (Strings.isNullOrEmpty(outputDir)) {
throw new IllegalArgumentException(
"could not determine default concept graph directory; please set property org.apache.ctakes.ytex.conceptGraphDir");
}
if (log.isInfoEnabled())
log.info("createConceptGraph(): file not found, creating concept graph from database.");
final ConceptGraph cg = new ConceptGraph();
final Set<String> roots = new HashSet<String>();
this.jdbcTemplate.query(query, new RowCallbackHandler() {
int nRowsProcessed = 0;
@Override
public void processRow(ResultSet rs) throws SQLException {
String child = rs.getString(1);
String parent = rs.getString(2);
addRelation(cg, roots, child, parent, checkCycle,
forbiddenConcepts);
nRowsProcessed++;
if (nRowsProcessed % 10000 == 0) {
log.info("processed " + nRowsProcessed + " edges");
}
}
});
// set the root
// if there is only one potential root, use it
// else use a synthetic root and add all the roots as its children
String rootId = null;
if (log.isDebugEnabled())
log.debug("roots: " + roots);
if (roots.size() == 1) {
rootId = roots.iterator().next();
} else {
rootId = System
.getProperty("org.apache.ctakes.ytex.defaultRootId",
DEFAULT_ROOT_ID);
ConcRel crRoot = cg.addConcept(rootId);
for (String crChildId : roots) {
ConcRel crChild = cg.getConceptMap().get(crChildId);
crRoot.getChildren().add(crChild);
crChild.getParents().add(crRoot);
}
}
cg.setRoot(rootId);
// can't get the maximum depth unless we're sure there are no
// cycles
if (checkCycle) {
log.info("computing intrinsic info for concept graph: " + name);
this.intrinsicInfoContentEvaluator