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

SO-6106: "Sub...PropertyOf" support for axiom-relationship conversions #1289

Merged
merged 7 commits into from
May 8, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
<setEntry value="org.objectweb.asm@default:default"/>
<setEntry value="org.objenesis@default:default"/>
<setEntry value="org.reactivestreams.reactive-streams@default:default"/>
<setEntry value="org.snomed.otf.snomed-owl-toolkit@default:default"/>
<setEntry value="com.b2international.snomed-owl-toolkit@default:default"/>
<setEntry value="org.w3c.css.sac@default:default"/>
<setEntry value="org.yaml.snakeyaml@default:default"/>
<setEntry value="slf4j.api@default:default"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@
<setEntry value="org.protege.editor.owl@default:default"/>
<setEntry value="org.reactivestreams.reactive-streams@default:default"/>
<setEntry value="org.semanticweb.owl.owlapi@default:default"/>
<setEntry value="org.snomed.otf.snomed-owl-toolkit@default:default"/>
<setEntry value="com.b2international.snomed-owl-toolkit@default:default"/>
<setEntry value="org.yaml.snakeyaml@default:default"/>
<setEntry value="slf4j.api@default:default"/>
</setAttribute>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@
<setEntry value="org.protege.editor.owl@default:default"/>
<setEntry value="org.reactivestreams.reactive-streams@default:default"/>
<setEntry value="org.semanticweb.owl.owlapi@default:default"/>
<setEntry value="org.snomed.otf.snomed-owl-toolkit@default:default"/>
<setEntry value="com.b2international.snomed-owl-toolkit@default:default"/>
<setEntry value="org.w3c.dom.events@default:default"/>
<setEntry value="org.yaml.snakeyaml@default:default"/>
<setEntry value="slf4j.api@default:default"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@
<setEntry value="org.protege.editor.owl@default:default"/>
<setEntry value="org.reactivestreams.reactive-streams@default:default"/>
<setEntry value="org.semanticweb.owl.owlapi@default:default"/>
<setEntry value="org.snomed.otf.snomed-owl-toolkit@default:default"/>
<setEntry value="com.b2international.snomed-owl-toolkit@default:default"/>
<setEntry value="org.w3c.css.sac@default:default"/>
<setEntry value="org.w3c.dom.events@default:default"/>
<setEntry value="org.w3c.dom.smil@default:default"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@
<setEntry value="org.sat4j.core@default:default"/>
<setEntry value="org.sat4j.pb@default:default"/>
<setEntry value="org.semanticweb.owl.owlapi@default:default"/>
<setEntry value="org.snomed.otf.snomed-owl-toolkit@default:default"/>
<setEntry value="com.b2international.snomed-owl-toolkit@default:default"/>
<setEntry value="org.tukaani.xz@default:default"/>
<setEntry value="org.yaml.snakeyaml@default:default"/>
<setEntry value="slf4j.api@default:default"/>
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<fastutil.version>8.3.1</fastutil.version>
<jaxb.api.version>2.3.0</jaxb.api.version>
<javax.activation.version>1.2.0</javax.activation.version>
<snomed.owl.toolkit.version>3.0.6</snomed.owl.toolkit.version>
<snomed.owl.toolkit.version>3.0.106</snomed.owl.toolkit.version>
<failsafe.version>2.3.1</failsafe.version>
<osgi.versionRange>[3.16.0,3.17.0]</osgi.versionRange>

Expand Down Expand Up @@ -626,7 +626,7 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.snomed.otf</groupId>
<groupId>com.b2international</groupId>
<artifactId>snomed-owl-toolkit</artifactId>
<version>${snomed.owl.toolkit.version}</version>
<classifier>bundle</classifier>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
<setEntry value="org.reactivestreams.reactive-streams@default:default"/>
<setEntry value="org.semanticweb.elk@default:default"/>
<setEntry value="org.semanticweb.owl.owlapi@default:default"/>
<setEntry value="org.snomed.otf.snomed-owl-toolkit@default:default"/>
<setEntry value="com.b2international.snomed-owl-toolkit@default:default"/>
<setEntry value="org.yaml.snakeyaml@default:default"/>
<setEntry value="slf4j.api@default:default"/>
<setEntry value="stax2-api@default:default"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2011-2023 B2i Healthcare Pte Ltd, http://b2i.sg
* Copyright 2011-2024 B2i Healthcare Pte Ltd, http://b2i.sg
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -274,6 +274,9 @@ private Concepts() { }
public static final String CONCEPT_MODEL_OBJECT_ATTRIBUTE = "762705008";
public static final String CONCEPT_MODEL_DATA_ATTRIBUTE = "762706009";

// Concept model attribute hierarchy roots, starting with INT 20240301
public static final String ANNOTATION_ATTRIBUTE = "1295447006";

// Concepts that require special care when classifying
public static final String ROLE_GROUP = "609096000";
public static final String PART_OF = "123005000";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@
<setEntry value="org.reactivestreams.reactive-streams@default:default"/>
<setEntry value="org.semanticweb.elk@default:default"/>
<setEntry value="org.semanticweb.owl.owlapi@default:default"/>
<setEntry value="org.snomed.otf.snomed-owl-toolkit@default:default"/>
<setEntry value="com.b2international.snomed-owl-toolkit@default:default"/>
<setEntry value="org.yaml.snakeyaml@default:default"/>
<setEntry value="slf4j.api@default:default"/>
</setAttribute>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@
<setEntry value="org.reactivestreams.reactive-streams@default:default"/>
<setEntry value="org.semanticweb.elk@default:default"/>
<setEntry value="org.semanticweb.owl.owlapi@default:default"/>
<setEntry value="org.snomed.otf.snomed-owl-toolkit@default:default"/>
<setEntry value="com.b2international.snomed-owl-toolkit@default:default"/>
<setEntry value="org.yaml.snakeyaml@default:default"/>
<setEntry value="slf4j.api@default:default"/>
</setAttribute>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
<setEntry value="org.protege.editor.owl@default:default"/>
<setEntry value="org.reactivestreams.reactive-streams@default:default"/>
<setEntry value="org.semanticweb.owl.owlapi@default:default"/>
<setEntry value="org.snomed.otf.snomed-owl-toolkit@default:default"/>
<setEntry value="com.b2international.snomed-owl-toolkit@default:default"/>
<setEntry value="org.yaml.snakeyaml@default:default"/>
<setEntry value="slf4j.api@default:default"/>
</setAttribute>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
import com.b2international.snowowl.snomed.datastore.internal.id.SnomedIdentifierTest;
import com.b2international.snowowl.snomed.datastore.internal.id.reservations.ReservationImplTest;
import com.b2international.snowowl.snomed.datastore.internal.id.reservations.SnomedIdentifierReservationServiceImplTest;
import com.b2international.snowowl.snomed.datastore.request.SnomedOWLExpressionConverterTest;
import com.b2international.snowowl.snomed.datastore.request.SnomedOWLRelationshipConverterTest;
import com.b2international.snowowl.snomed.validation.SnomedQueryValidationRuleEvaluatorTest;

/**
Expand Down Expand Up @@ -82,6 +84,8 @@
SnomedDescriptionUtilsTest.class,
// Validate Rule Evaluators
SnomedQueryValidationRuleEvaluatorTest.class,
SnomedOWLExpressionConverterTest.class,
SnomedOWLRelationshipConverterTest.class,
})
public class AllSnomedDatastoreTests {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright 2024 B2i Healthcare Ltd, http://b2ihealthcare.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.b2international.snowowl.snomed.datastore.request;

import static org.junit.Assert.*;

import java.util.List;

import org.elasticsearch.core.Set;
import org.junit.Test;

import com.b2international.snowowl.snomed.common.SnomedConstants.Concepts;
import com.b2international.snowowl.snomed.datastore.index.entry.SnomedOWLRelationshipDocument;
import com.google.common.collect.Iterables;

/**
* @since 7.24.3
*/
public class SnomedOWLExpressionConverterTest {

@Test
public void testSubObjectPropertyOf() {
testSubPropertyOf("SubObjectPropertyOf");
}

@Test
public void testSubDataPropertyOf() {
testSubPropertyOf("SubDataPropertyOf");
}

@Test
public void testSubAnnotationPropertyOf() {
testSubPropertyOf("SubAnnotationPropertyOf");
}

private void testSubPropertyOf(String subPropertyOfAxiom) {
SnomedOWLExpressionConverter converter = new SnomedOWLExpressionConverter(() -> Set.of());

// XXX: Using nonsensical but valid SCTIDs
SnomedOWLExpressionConverterResult converterResult = converter.toSnomedOWLRelationships(
Concepts.FINDING_SITE,
String.format("%s(:%s :%s)", subPropertyOfAxiom, Concepts.FINDING_SITE, Concepts.AMBIGUOUS));

assertNull(converterResult.getGciAxiomRelationships());

final List<SnomedOWLRelationshipDocument> relationships = converterResult.getClassAxiomRelationships();
assertEquals(1, relationships.size());

final SnomedOWLRelationshipDocument relationship = Iterables.getOnlyElement(relationships);
assertEquals(Concepts.IS_A, relationship.getTypeId());
assertEquals(Concepts.AMBIGUOUS, relationship.getDestinationId());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* Copyright 2024 B2i Healthcare Ltd, http://b2ihealthcare.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.b2international.snowowl.snomed.datastore.request;

import static org.junit.Assert.assertEquals;

import java.util.Collection;
import java.util.List;

import org.elasticsearch.core.Set;
import org.junit.Test;

import com.b2international.snowowl.snomed.common.SnomedConstants.Concepts;
import com.b2international.snowowl.snomed.datastore.index.entry.SnomedOWLRelationshipDocument;

/**
* @since 7.24.3
*/
public class SnomedOWLRelationshipConverterTest {

@Test
public void testSubClassOf() {
testSubPropertyOf(
"SubClassOf",
Set.of(),
Set.of(),
Set.of(),
Concepts.DEVICE
);
}

@Test
public void testSubObjectPropertyOf() {
testSubPropertyOf(
"SubObjectPropertyOf",
Set.of(Long.parseLong(Concepts.CONCEPT_MODEL_OBJECT_ATTRIBUTE)),
Set.of(),
Set.of(),
Concepts.CONCEPT_MODEL_OBJECT_ATTRIBUTE
);
}

@Test
public void testSubDataPropertyOf() {
testSubPropertyOf(
"SubDataPropertyOf",
Set.of(),
Set.of(Long.parseLong(Concepts.CONCEPT_MODEL_DATA_ATTRIBUTE)),
Set.of(),
Concepts.CONCEPT_MODEL_DATA_ATTRIBUTE
);
}

@Test
public void testSubAnnotationPropertyOf() {
testSubPropertyOf(
"SubAnnotationPropertyOf",
Set.of(),
Set.of(),
Set.of(Long.parseLong(Concepts.ANNOTATION_ATTRIBUTE)),
Concepts.ANNOTATION_ATTRIBUTE
);
}

private void testSubPropertyOf(
String subPropertyOfAxiom,
Collection<Long> objectAttributes,
Collection<Long> dataAttributes,
Collection<Long> annotationAttributes,
String destinationId
) {
SnomedOWLRelationshipConverter converter = new SnomedOWLRelationshipConverter(
Set.of(),
objectAttributes,
dataAttributes,
annotationAttributes);

// XXX: Using nonsensical but valid SCTIDs
final List<SnomedOWLRelationshipDocument> owlRelationships = List.of(
SnomedOWLRelationshipDocument.create(Concepts.IS_A, destinationId, 0)
);

final String expectedExpression = String.format("%s(:%s :%s)", subPropertyOfAxiom, Concepts.FINDING_SITE, destinationId);
final String actualExpression = converter.fromSnomedOwlRelationships(
false,
true,
Concepts.FINDING_SITE,
owlRelationships
);

assertEquals(expectedExpression, actualExpression);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="3.9.0",
org.eclipse.core.databinding;bundle-version="1.4.0",
org.eclipse.core.expressions;bundle-version="3.4.400",
com.fasterxml.jackson.dataformat.jackson-dataformat-csv;bundle-version="2.8.6",
org.snomed.otf.snomed-owl-toolkit;bundle-version="3.0.2",
com.b2international.snomed-owl-toolkit,
org.eclipse.xtext.xbase.lib,
com.b2international.snowowl.snomed.cis;visibility:=reexport,
com.b2international.snowowl.snomed.common;visibility:=reexport,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ public final class SnomedOWLExpressionConverter {
"SubClassOf",
"EquivalentClasses",
"SubObjectPropertyOf",
"SubDataPropertyOf");
"SubDataPropertyOf",
"SubAnnotationPropertyOf"
);

private final Supplier<AxiomRelationshipConversionService> conversionService;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,21 @@ public final class SnomedOWLRelationshipConverter {

private final Supplier<AxiomRelationshipConversionService> conversionService;

public SnomedOWLRelationshipConverter(final Set<Long> ungroupedAttributes, final Collection<Long> objectAttributes, final Collection<Long> dataAttributes) {
public SnomedOWLRelationshipConverter(
final Set<Long> ungroupedAttributes,
final Collection<Long> objectAttributes,
final Collection<Long> dataAttributes,
final Collection<Long> annotationAttributes
) {
this.conversionService = Suppliers.memoize(() -> {
final Stopwatch stopwatch = Stopwatch.createStarted();
final AxiomRelationshipConversionService service = withTccl(() -> new AxiomRelationshipConversionService(ungroupedAttributes, objectAttributes, dataAttributes));
final AxiomRelationshipConversionService service = withTccl(() -> new AxiomRelationshipConversionService(
ungroupedAttributes,
objectAttributes,
dataAttributes,
annotationAttributes)
);

LOG.debug("SNOMED OWL Toolkit conversion service initialization took {}", TimeUtil.toString(stopwatch));
return service;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@
<setEntry value="org.protege.editor.owl@default:default"/>
<setEntry value="org.reactivestreams.reactive-streams@default:default"/>
<setEntry value="org.semanticweb.owl.owlapi@default:default"/>
<setEntry value="org.snomed.otf.snomed-owl-toolkit@default:default"/>
<setEntry value="com.b2international.snomed-owl-toolkit@default:default"/>
<setEntry value="org.yaml.snakeyaml@default:default"/>
<setEntry value="slf4j.api@default:default"/>
</setAttribute>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
<setEntry value="org.protege.editor.owl@default:default"/>
<setEntry value="org.reactivestreams.reactive-streams@default:default"/>
<setEntry value="org.semanticweb.owl.owlapi@default:default"/>
<setEntry value="org.snomed.otf.snomed-owl-toolkit@default:default"/>
<setEntry value="com.b2international.snomed-owl-toolkit@default:default"/>
<setEntry value="org.w3c.dom.events@default:default"/>
<setEntry value="org.yaml.snakeyaml@default:default"/>
<setEntry value="slf4j.api@default:default"/>
Expand Down
Loading