// Add the role axioms
for (String r1 : roles.keySet()) {
String parentRole = roles.get(r1).get("parentrole");
if (!"".equals(parentRole)) {
axioms.add(new RoleInclusion(new NamedRole(r1), new NamedRole(parentRole)));
}
String rightId = roles.get(r1).get("rightID");
if (!"".equals(rightId)) {
axioms.add(new RoleInclusion(new Role[] { new NamedRole(r1), new NamedRole(rightId) },
new NamedRole(r1)));
}
}
// Add concept axioms
for (String c1 : primitive.keySet()) {
if (roles.get(c1) != null)
continue;
Set<String> prs = parents.get(c1);
int numParents = (prs != null) ? prs.size() : 0;
List<String[]> relsVal = rels.get(c1);
int numRels = 0;
if (relsVal != null)
numRels = 1;
int numElems = numParents + numRels;
if (numElems == 0) {
// do nothing
} else if (numElems == 1 && (prs != null && !prs.isEmpty())) {
axioms.add(new ConceptInclusion(new NamedConcept(c1), new NamedConcept(prs.iterator().next())));
} else {
List<Concept> conjs = new ArrayList<Concept>();
if(prs != null) {
for (String pr : prs) {
conjs.add(new NamedConcept(pr));
}
}
if (relsVal != null) {
for (Set<RoleValuePair> rvs : groupRoles(relsVal)) {
if (rvs.size() > 1) {
List<Concept> innerConjs = new ArrayList<Concept>();
for (RoleValuePair rv : rvs) {
NamedRole role = new NamedRole(rv.role);
Concept filler = new NamedConcept(rv.value);
Existential exis = new Existential(role, filler);
innerConjs.add(exis);
}
// Wrap with a role group
conjs.add(new Existential(new NamedRole("RoleGroup"), new Conjunction(innerConjs)));
} else {
RoleValuePair first = rvs.iterator().next();
NamedRole role = new NamedRole(first.role);
Concept filler = new NamedConcept(first.value);
Existential exis = new Existential(role, filler);
if (metadata.getNeverGroupedIds().contains(first.role)) {
// Does not need a role group
conjs.add(exis);
} else {
// Needs a role group
conjs.add(new Existential(new NamedRole("RoleGroup"), exis));
}
}
}
}