use of org.snomed.otf.owltoolkit.domain.AxiomRepresentation in project snow-owl by b2ihealthcare.
the class SnomedOWLExpressionConverter method toSnomedOWLRelationships.
public SnomedOWLExpressionConverterResult toSnomedOWLRelationships(String conceptId, String axiomExpression) {
// Only attempt to convert axioms which the OWL toolkit supports
if (Strings.isNullOrEmpty(axiomExpression) || !isAxiomSupported(axiomExpression)) {
return SnomedOWLExpressionConverterResult.EMPTY;
}
try {
final Long conceptIdLong = Long.valueOf(conceptId);
final AxiomRepresentation axiomRepresentation = convertAxiom(conceptId, axiomExpression);
if (axiomRepresentation == null) {
return SnomedOWLExpressionConverterResult.EMPTY;
}
boolean gci = false;
Map<Integer, List<Relationship>> relationships = null;
if (conceptIdLong.equals(axiomRepresentation.getLeftHandSideNamedConcept())) {
relationships = axiomRepresentation.getRightHandSideRelationships();
} else if (conceptIdLong.equals(axiomRepresentation.getRightHandSideNamedConcept())) {
/*
* XXX: EquivalentClasses axioms are not ordered in any meaningful way, so it
* can happen that the class expression representing relationships falls on the left-hand side
*/
gci = axiomRepresentation.isPrimitive();
relationships = axiomRepresentation.getLeftHandSideRelationships();
} else {
LOG.warn("Illegal assignment of referenced component id ('{}') was detected for the OWL expression: '{}'", conceptId, axiomExpression);
}
if (relationships == null) {
return SnomedOWLExpressionConverterResult.EMPTY;
}
final List<SnomedOWLRelationshipDocument> convertedRelationships = relationships.values().stream().flatMap(List::stream).map(relationship -> {
if (relationship.isConcrete()) {
return SnomedOWLRelationshipDocument.createValue(Long.toString(relationship.getTypeId()), toRelationshipValue(relationship.getValue()), relationship.getGroup());
} else {
return SnomedOWLRelationshipDocument.create(Long.toString(relationship.getTypeId()), Long.toString(relationship.getDestinationId()), relationship.getGroup());
}
}).collect(Collectors.toList());
return new SnomedOWLExpressionConverterResult(gci ? null : convertedRelationships, gci ? convertedRelationships : null);
} catch (ApiException e) {
throw e;
} catch (Exception e) {
LOG.error("Failed to convert OWL axiom '{}' to relationship representations for concept '{}'", axiomExpression, conceptId, e);
return SnomedOWLExpressionConverterResult.EMPTY;
}
}
use of org.snomed.otf.owltoolkit.domain.AxiomRepresentation in project snow-owl by b2ihealthcare.
the class SnomedOWLRelationshipConverter method fromSnomedOwlRelationships.
public String fromSnomedOwlRelationships(final boolean gci, final boolean isPrimitive, final String conceptId, final List<SnomedOWLRelationshipDocument> owlRelationships) {
final AxiomRepresentation axiomRepresentation = new AxiomRepresentation();
final Long conceptIdLong = Long.valueOf(conceptId);
final ListMultimap<Integer, Relationship> relationships = ArrayListMultimap.create();
for (final SnomedOWLRelationshipDocument owlRelationship : owlRelationships) {
final Relationship relationship;
if (owlRelationship.hasValue()) {
relationship = new Relationship(owlRelationship.getRelationshipGroup(), Long.valueOf(owlRelationship.getTypeId()), toConcreteValue(owlRelationship.getValueAsObject()));
} else {
relationship = new Relationship(owlRelationship.getRelationshipGroup(), Long.valueOf(owlRelationship.getTypeId()), Long.valueOf(owlRelationship.getDestinationId()));
}
relationships.put(relationship.getGroup(), relationship);
}
final Map<Integer, List<Relationship>> relationshipsMap = Multimaps.asMap(relationships);
if (gci) {
axiomRepresentation.setLeftHandSideRelationships(relationshipsMap);
axiomRepresentation.setRightHandSideNamedConcept(conceptIdLong);
} else {
axiomRepresentation.setLeftHandSideNamedConcept(conceptIdLong);
axiomRepresentation.setRightHandSideRelationships(relationshipsMap);
}
axiomRepresentation.setPrimitive(isPrimitive);
return convertRelationshipToAxiom(conceptId, axiomRepresentation);
}
Aggregations