Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(snomed.reasoner): Add support for annotation properties in DelegateOntology as well #1291

Merged
merged 4 commits into from
May 8, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ public final class DelegateOntology extends DelegateOntologyStub implements OWLM
private static final long PRE_2018_OBJECT_ATTRIBUTE = Long.parseLong(Concepts.CONCEPT_MODEL_ATTRIBUTE);
private static final long PRE_2018_DATA_ATTRIBUTE = Long.parseLong(Concepts.SG_CONCRETE_DOMAIN_ATTRIBUTE);

private static final long ANNOTATION_ATTRIBUTE = Long.parseLong(Concepts.ANNOTATION_ATTRIBUTE);

private static final long IS_A = Long.parseLong(Concepts.IS_A);
private static final long ROLE_GROUP = Long.parseLong(Concepts.ROLE_GROUP);

Expand Down Expand Up @@ -237,6 +239,52 @@ private long nextApplicableParentId() {
return -1L;
}
}

private final class SubAnnotationPropertyOfAxiomIterator extends AbstractIterator<OWLSubAnnotationPropertyOfAxiom> {
private final LongIterator childIterator;

private long childId = -1L;
private LongIterator parentIterator;

public SubAnnotationPropertyOfAxiomIterator(final LongIterator childIterator) {
this.childIterator = childIterator;
}

@Override
protected OWLSubAnnotationPropertyOfAxiom computeNext() {
final long parentId = nextApplicableParentId();
if (parentId == -1L) {
return endOfData();
}

final OWLAnnotationProperty childProperty = getConceptAnnotationProperty(childId);
final OWLAnnotationProperty parentProperty = getConceptAnnotationProperty(parentId);
return getOWLSubAnnotationPropertyOfAxiom(childProperty, parentProperty);
}

private long nextApplicableParentId() {
// Check if there are more parents to return for the current value of "childId"
if (parentIterator != null) {
while (parentIterator.hasNext()) {
return parentIterator.next();
}
}

// Otherwise, look for the next child which has parents
while (childIterator.hasNext()) {
childId = childIterator.next();
parentIterator = taxonomy.getStatedAncestors()
.getDestinations(childId, true)
.iterator();

while (parentIterator.hasNext()) {
return parentIterator.next();
}
}

return -1L;
}
}

private final class SubClassOfAxiomIterator extends AbstractIterator<OWLSubClassOfAxiom> {
private final LongIterator childIterator;
Expand Down Expand Up @@ -376,6 +424,7 @@ private static DefaultPrefixManager createPrefixManager() {

private final long objectAttributeId;
private final long dataAttributeId;
private final long annotationAttributeId;
private final LongSet neverGroupedIds;

public DelegateOntology(final OWLOntologyManager manager,
Expand All @@ -400,6 +449,12 @@ public DelegateOntology(final OWLOntologyManager manager,
dataAttributeId = PRE_2018_DATA_ATTRIBUTE;
}

if (taxonomy.getConceptMap().getInternalId(ANNOTATION_ATTRIBUTE) != -1) {
annotationAttributeId = ANNOTATION_ATTRIBUTE;
} else {
annotationAttributeId = -1L;
}

if (!taxonomy.getNeverGroupedTypeIds().isEmpty()) {
this.neverGroupedIds = taxonomy.getNeverGroupedTypeIds();
} else {
Expand Down Expand Up @@ -539,6 +594,7 @@ public Iterator<OWLLogicalAxiom> iterator() {
objectAttributeSubClassOfAxioms(),
dataAttributeSubPropertyOfAxioms(),
dataAttributeSubClassOfAxioms(),
annotationAttributeSubClassOfAxioms(),
disjointUnionAxioms());
}

Expand All @@ -554,7 +610,10 @@ public Set<OWLAxiom> getAxioms() {
return new AbstractSet<OWLAxiom>() {
@Override
public Iterator<OWLAxiom> iterator() {
return Iterators.concat(conceptFsnAxioms(), getLogicalAxioms().iterator());
return Iterators.concat(
conceptFsnAxioms(),
annotationAttributeSubPropertyOfAxioms(),
getLogicalAxioms().iterator());
}

@Override
Expand All @@ -572,12 +631,14 @@ public int getLogicalAxiomCount() {
+ objectHierarchyCount() // objectAttributeSubClassOfAxioms()
+ dataHierarchyCount() // dataAttributeSubPropertyOfAxioms()
+ dataHierarchyCount() // dataAttributeSubClassOfAxioms()
+ annotationHierarchyCount() // annotationAttributeSubClassOfAxioms()
+ disjointUnionCount(); // disjointUnionAxioms()
}

@Override
public int getAxiomCount() {
return conceptFsnAxiomCount() // conceptFsnAxioms()
+ annotationHierarchyCount() // annotationAttributeSubPropertyOfAxioms()
+ getLogicalAxiomCount();
}

Expand Down Expand Up @@ -679,6 +740,18 @@ private int dataHierarchyCount() {
return hierarchyCount(dataAttributeId);
}

private Iterator<OWLSubAnnotationPropertyOfAxiom> annotationAttributeSubPropertyOfAxioms() {
return new SubAnnotationPropertyOfAxiomIterator(annotationAttributeIdIterator());
}

private Iterator<OWLSubClassOfAxiom> annotationAttributeSubClassOfAxioms() {
return new SubClassOfAxiomIterator(annotationAttributeIdIterator());
}

private int annotationHierarchyCount() {
return hierarchyCount(annotationAttributeId);
}

private int hierarchyCount(final long ancestorId) {
return getAllSubTypes(ancestorId).size();
}
Expand Down Expand Up @@ -726,6 +799,10 @@ private LongIterator objectAttributeIdIterator() {
private LongIterator dataAttributeIdIterator() {
return getAllSubTypes(dataAttributeId).iterator();
}

private LongIterator annotationAttributeIdIterator() {
return getAllSubTypes(annotationAttributeId).iterator();
}

private LongIterator exhaustiveIdIterator() {
return taxonomy.getExhaustiveConcepts().iterator();
Expand Down Expand Up @@ -786,6 +863,10 @@ private OWLObjectProperty getConceptObjectProperty(final long conceptId) {
private OWLDataProperty getConceptDataProperty(final long conceptId) {
return getOWLDataProperty(PREFIX_SCT + conceptId);
}

private OWLAnnotationProperty getConceptAnnotationProperty(final long conceptId) {
return getOWLAnnotationProperty(PREFIX_SCT + conceptId);
}

private OWLClassExpression getRelationshipExpression(final StatementFragment fragment) {
return fragment.map(
Expand Down Expand Up @@ -989,6 +1070,10 @@ private OWLDataProperty getOWLDataProperty(final String abbreviatedIRI) {
return getDataFactory().getOWLDataProperty(abbreviatedIRI, prefixManager);
}

private OWLAnnotationProperty getOWLAnnotationProperty(final String abbreviatedIRI) {
return getDataFactory().getOWLAnnotationProperty(abbreviatedIRI, prefixManager);
}

private OWLClassExpression getOWLObjectIntersectionOf(final Set<OWLClassExpression> conjuncts) {
if (conjuncts.size() > 1) {
return getDataFactory().getOWLObjectIntersectionOf(conjuncts);
Expand Down Expand Up @@ -1059,4 +1144,8 @@ private OWLSubObjectPropertyOfAxiom getOWLSubObjectPropertyOfAxiom(final OWLObje
private OWLSubDataPropertyOfAxiom getOWLSubDataPropertyOfAxiom(final OWLDataPropertyExpression child, final OWLDataPropertyExpression parent) {
return getDataFactory().getOWLSubDataPropertyOfAxiom(child, parent);
}

private OWLSubAnnotationPropertyOfAxiom getOWLSubAnnotationPropertyOfAxiom(final OWLAnnotationProperty child, final OWLAnnotationProperty parent) {
return getDataFactory().getOWLSubAnnotationPropertyOfAxiom(child, parent);
}
}
Loading