Skip to content

Commit 2ef7ae7

Browse files
committed
OWLAP-183 Sub property axioms when converting from relationships.
AxiomRelationshipConversionService.convertRelationshipsToAxiom will now create SubObjectPropertyOf or SubDataPropertyOf axioms when converting a set of relationships to axioms if one of the parents are identified in the set of object property or data property concepts.
1 parent c6c8855 commit 2ef7ae7

File tree

2 files changed

+50
-6
lines changed

2 files changed

+50
-6
lines changed

src/main/java/org/snomed/otf/owltoolkit/conversion/AxiomRelationshipConversionService.java

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,27 @@ public class AxiomRelationshipConversionService {
2323
private final OntologyService ontologyService;
2424

2525
private static final Logger LOGGER = LoggerFactory.getLogger(AxiomRelationshipConversionService.class);
26+
private Collection<Long> objectAttributes;
27+
private Collection<Long> dataAttributes;
2628

2729
public AxiomRelationshipConversionService(Set<Long> ungroupedAttributes) {
2830
snomedTaxonomyLoader = new SnomedTaxonomyLoader();
2931
ontologyService = new OntologyService(ungroupedAttributes);
3032
}
3133

34+
/**
35+
* Use this constructor to enable generating SubObjectPropertyOf and SubDataPropertyOf axioms from relationships.
36+
* @param ungroupedAttributes
37+
* @param objectAttributes
38+
* @param dataAttributes
39+
*/
40+
public AxiomRelationshipConversionService(Set<Long> ungroupedAttributes, Collection<Long> objectAttributes, Collection<Long> dataAttributes) {
41+
snomedTaxonomyLoader = new SnomedTaxonomyLoader();
42+
ontologyService = new OntologyService(ungroupedAttributes);
43+
this.objectAttributes = objectAttributes;
44+
this.dataAttributes = dataAttributes;
45+
}
46+
3247
/**
3348
* Converts an OWL Axiom expression String to an AxiomRepresentation containing a concept id or set of relationships for each side of the expression.
3449
* Currently supported axiom types are SubClassOf and EquivalentClasses.
@@ -172,8 +187,31 @@ public Map<Long, Set<AxiomRepresentation>> convertAxiomsToRelationships(Map<Long
172187
}
173188

174189
public String convertRelationshipsToAxiom(AxiomRepresentation representation) {
175-
OWLClassAxiom owlClassAxiom = ontologyService.createOwlClassAxiom(representation);
176-
return owlClassAxiom.toString().replaceAll(CORE_COMPONENT_NAMESPACE_PATTERN, ":$1").replace(") )", "))");
190+
191+
// Identify and convert object and data property axioms
192+
if (representation.getLeftHandSideNamedConcept() != null && representation.getRightHandSideRelationships() != null) {
193+
List<Relationship> relationships = representation.getRightHandSideRelationships().get(0);
194+
for (Relationship relationship : relationships) {
195+
if (relationship.getTypeId() == Concepts.IS_A_LONG) {
196+
if (objectAttributes != null && objectAttributes.contains(relationship.getDestinationId())) {
197+
// Attributes will only have one parent
198+
return axiomToString(ontologyService.createOwlSubObjectPropertyOfAxiom(representation.getLeftHandSideNamedConcept(), relationship.getDestinationId()));
199+
} else if (dataAttributes != null && dataAttributes.contains(relationship.getDestinationId())) {
200+
return axiomToString(ontologyService.createOwlSubDataPropertyOfAxiom(representation.getLeftHandSideNamedConcept(), relationship.getDestinationId()));
201+
} else {
202+
// If the first parent is not an attribute then the concept is not an attribute.
203+
break;
204+
}
205+
}
206+
}
207+
}
208+
209+
// Normal axioms and GCI axioms go through here
210+
return axiomToString(ontologyService.createOwlClassAxiom(representation));
211+
}
212+
213+
public String axiomToString(OWLLogicalAxiom owlAxiom) {
214+
return owlAxiom.toString().replaceAll(CORE_COMPONENT_NAMESPACE_PATTERN, ":$1").replace(") )", "))");
177215
}
178216

179217
/**

src/main/java/org/snomed/otf/owltoolkit/ontology/OntologyService.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,22 +112,20 @@ public Map<Long, Set<OWLAxiom>> createAxiomsFromStatedRelationships(SnomedTaxono
112112

113113
Set<Long> descendants = snomedTaxonomy.getDescendants(conceptModelObjectAttribute);
114114
for (Long objectAttributeId : descendants) {
115-
OWLObjectProperty owlObjectProperty = getOwlObjectProperty(objectAttributeId);
116115
for (Relationship relationship : snomedTaxonomy.getStatedRelationships(objectAttributeId)) {
117116
if (relationship.getTypeId() == Concepts.IS_A_LONG && (relationship.getDestinationId() != Concepts.CONCEPT_MODEL_ATTRIBUTE_LONG) || !conceptModelObjectAttributePresent) {
118117
axiomsMap.computeIfAbsent(objectAttributeId, (id) -> new HashSet<>())
119-
.add(factory.getOWLSubObjectPropertyOfAxiom(owlObjectProperty, getOwlObjectProperty(relationship.getDestinationId())));
118+
.add(createOwlSubObjectPropertyOfAxiom(objectAttributeId, relationship.getDestinationId()));
120119
}
121120
}
122121
}
123122

124123
if (snomedTaxonomy.getAllConceptIds().contains(Concepts.CONCEPT_MODEL_DATA_ATTRIBUTE_LONG)) {
125124
for (Long dataAttributeId : snomedTaxonomy.getDescendants(Concepts.CONCEPT_MODEL_DATA_ATTRIBUTE_LONG)) {
126-
OWLDataProperty owlDataProperty = getOwlDataProperty(dataAttributeId);
127125
for (Relationship relationship : snomedTaxonomy.getStatedRelationships(dataAttributeId)) {
128126
if (relationship.getTypeId() == Concepts.IS_A_LONG) {
129127
axiomsMap.computeIfAbsent(dataAttributeId, (id) -> new HashSet<>())
130-
.add(factory.getOWLSubDataPropertyOfAxiom(owlDataProperty, getOwlDataProperty(relationship.getDestinationId())));
128+
.add(createOwlSubDataPropertyOfAxiom(dataAttributeId, relationship.getDestinationId()));
131129
}
132130
}
133131
}
@@ -194,6 +192,14 @@ public OWLClassAxiom createOwlClassAxiom(AxiomRepresentation axiomRepresentation
194192
}
195193
}
196194

195+
public OWLSubObjectPropertyOfAxiom createOwlSubObjectPropertyOfAxiom(Long objectAttributeId, long destinationId) {
196+
return factory.getOWLSubObjectPropertyOfAxiom(getOwlObjectProperty(objectAttributeId), getOwlObjectProperty(destinationId));
197+
}
198+
199+
public OWLSubDataPropertyOfAxiom createOwlSubDataPropertyOfAxiom(Long dataAttributeId, long destinationId) {
200+
return factory.getOWLSubDataPropertyOfAxiom(getOwlDataProperty(dataAttributeId), getOwlDataProperty(destinationId));
201+
}
202+
197203
private OWLClassExpression createOwlClassExpression(Long namedConcept, Map<Integer, List<Relationship>> relationships) {
198204
if (namedConcept != null) {
199205
return getOwlClass(namedConcept);

0 commit comments

Comments
 (0)