final Node node = taxonomy.get(id);
if (node != null) {
for (final Node parent: node.getParents()) {
final String parentId = parent.getEquivalentConcepts().iterator().next();
if (!NamedConcept.TOP.equals(parentId)) { // Top is redundant
result.add(new NamedConcept(parentId));
}
}
// Look for Datatype concepts
final IntIterator ancestorItr = contextIndex.get(key).getS().iterator();
while (ancestorItr.hasNext()) {
int anc = ancestorItr.next();
if (factory.isVirtualConcept(anc)) {
Object c = factory.lookupConceptId(anc);
if (c instanceof au.csiro.snorocket.core.model.Datatype) {
addDatatype(result, (au.csiro.snorocket.core.model.Datatype) c);
}
}
}
} else if (id instanceof au.csiro.snorocket.core.model.Conjunction) {
// In this case, we have a result of normalisation so we reach inside and grab out the parents
for (AbstractConcept conjunct: ((au.csiro.snorocket.core.model.Conjunction) id).getConcepts()) {
if (conjunct instanceof au.csiro.snorocket.core.model.Concept) {
final int conjunctInt = ((au.csiro.snorocket.core.model.Concept) conjunct).hashCode();
final String conjunctId = factory.lookupConceptId(conjunctInt).toString();
result.add(new NamedConcept(conjunctId));
} else if (conjunct instanceof au.csiro.snorocket.core.model.Datatype) {
addDatatype(result, (au.csiro.snorocket.core.model.Datatype) conjunct);
}
}
} else {
// Ignore
}
final Context ctx = contextIndex.get(key);
CR succ = ctx.getSucc();
for(int roleId : succ.getRoles()) {
NamedRole role = new NamedRole(factory.lookupRoleId(roleId).toString());
IConceptSet values = getLeaves(succ.lookupConcept(roleId));
for (IntIterator itr2 = values.iterator(); itr2.hasNext(); ) {
int valueInt = itr2.next();
if (!factory.isVirtualConcept(valueInt)) {
final String valueId = factory.lookupConceptId(valueInt).toString();
result.add(new Existential(role, new NamedConcept(valueId)));
} else {
final Concept valueConcept = getNecessary(contextIndex, taxonomy, valueInt);
final Existential x = new Existential(role, Builder.build(no, valueConcept));
result.add(x);
}