Search in sources :

Example 1 with SnomedOWLExpressionConverterResult

use of com.b2international.snowowl.snomed.datastore.request.SnomedOWLExpressionConverterResult in project snow-owl by b2ihealthcare.

the class SnomedRefSetMemberDocumentSerializationTest method indexOWLAxiomMember_GroupedProperties.

@Test
public void indexOWLAxiomMember_GroupedProperties() throws Exception {
    final String referencedComponentId = "359728003";
    final String owlExpression = "EquivalentClasses(" + ":359728003 " + "ObjectIntersectionOf(:384723003 " + "		ObjectSomeValuesFrom(:609096000 " + "			ObjectIntersectionOf(" + "				ObjectSomeValuesFrom(:260686004 :129304002) " + "				ObjectSomeValuesFrom(:405813007 :245269009)" + "			)" + "		) " + "		ObjectSomeValuesFrom(:609096000 " + "			ObjectIntersectionOf(" + "				ObjectSomeValuesFrom(:260686004 :129304002) " + "				ObjectSomeValuesFrom(:405813007 :81802002)" + "			)" + "		)" + "))";
    final SnomedOWLExpressionConverterResult owlRelationships = toSnomedOWLRelationships(referencedComponentId, owlExpression);
    final SnomedRefSetMemberIndexEntry member = createBaseMember().referencedComponentId(referencedComponentId).refsetId(Concepts.REFSET_OWL_AXIOM).referenceSetType(SnomedRefSetType.OWL_AXIOM).field(Fields.OWL_EXPRESSION, owlExpression).classAxiomRelationships(owlRelationships.getClassAxiomRelationships()).gciAxiomRelationships(owlRelationships.getGciAxiomRelationships()).build();
    indexRevision(RevisionBranch.MAIN_PATH, member);
    final SnomedRefSetMemberIndexEntry actual = getRevision(RevisionBranch.MAIN_PATH, SnomedRefSetMemberIndexEntry.class, member.getId());
    assertEquals(owlExpression, actual.getOwlExpression());
    assertEquals(// expected
    ImmutableList.of(SnomedOWLRelationshipDocument.create(Concepts.IS_A, "384723003", 0), SnomedOWLRelationshipDocument.create("260686004", "129304002", 1), SnomedOWLRelationshipDocument.create("405813007", "245269009", 1), SnomedOWLRelationshipDocument.create("260686004", "129304002", 2), SnomedOWLRelationshipDocument.create("405813007", "81802002", 2)), // actual
    actual.getClassAxiomRelationships());
    assertThat(actual.getGciAxiomRelationships()).isEmpty();
    assertDocEquals(member, actual);
}
Also used : SnomedOWLExpressionConverterResult(com.b2international.snowowl.snomed.datastore.request.SnomedOWLExpressionConverterResult) Test(org.junit.Test) BaseRevisionIndexTest(com.b2international.index.revision.BaseRevisionIndexTest)

Example 2 with SnomedOWLExpressionConverterResult

use of com.b2international.snowowl.snomed.datastore.request.SnomedOWLExpressionConverterResult in project snow-owl by b2ihealthcare.

the class SnomedRefSetMemberDocumentSerializationTest method createGciAxiomMember.

private SnomedRefSetMemberIndexEntry createGciAxiomMember() {
    final String referencedComponentId = "231907006";
    final String owlExpression = "" + "SubClassOf(" + "	ObjectIntersectionOf(" + "		:193783008 " + "		ObjectSomeValuesFrom(:609096000 " + "			ObjectIntersectionOf(" + "				ObjectSomeValuesFrom(:116676008 :23583003) " + "				ObjectSomeValuesFrom(:246075003 :19551004) " + "				ObjectSomeValuesFrom(:363698007 :65431007) " + "				ObjectSomeValuesFrom(:370135005 :441862004)" + "			)" + "		)" + "	)" + "	:231907006" + ")";
    final SnomedOWLExpressionConverterResult owlRelationships = toSnomedOWLRelationships(referencedComponentId, owlExpression);
    return createBaseMember().referencedComponentId(referencedComponentId).refsetId(Concepts.REFSET_OWL_AXIOM).referenceSetType(SnomedRefSetType.OWL_AXIOM).field(Fields.OWL_EXPRESSION, owlExpression).classAxiomRelationships(owlRelationships.getClassAxiomRelationships()).gciAxiomRelationships(owlRelationships.getGciAxiomRelationships()).build();
}
Also used : SnomedOWLExpressionConverterResult(com.b2international.snowowl.snomed.datastore.request.SnomedOWLExpressionConverterResult)

Example 3 with SnomedOWLExpressionConverterResult

use of com.b2international.snowowl.snomed.datastore.request.SnomedOWLExpressionConverterResult in project snow-owl by b2ihealthcare.

the class Taxonomies method updateEdge.

private static void updateEdge(SnomedRefSetMemberIndexEntry member, TaxonomyGraph graphToUpdate, SnomedOWLExpressionConverter expressionConverter) {
    if (member.isActive()) {
        SnomedOWLExpressionConverterResult result = expressionConverter.toSnomedOWLRelationships(member.getReferencedComponentId(), member.getOwlExpression());
        if (!CompareUtils.isEmpty(result.getClassAxiomRelationships())) {
            /*
				 * XXX: IS A relationships are expected to have a destination ID, not a value,
				 * but we do not check this explicitly here -- Long#parseLong will throw a
				 * NumberFormatException if it encounters a null value.
				 */
            final long[] destinationIds = result.getClassAxiomRelationships().stream().filter(r -> Concepts.IS_A.equals(r.getTypeId())).map(SnomedOWLRelationshipDocument::getDestinationId).mapToLong(Long::parseLong).toArray();
            graphToUpdate.addEdge(member.getId(), Long.parseLong(member.getReferencedComponentId()), destinationIds);
        } else {
            graphToUpdate.removeEdge(member.getId());
        }
    } else {
        graphToUpdate.removeEdge(member.getId());
    }
}
Also used : Query(com.b2international.index.query.Query) Hits(com.b2international.index.Hits) SnomedRefSetMemberIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRefSetMemberIndexEntry) SnomedRelationshipIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry) LoggerFactory(org.slf4j.LoggerFactory) LongCollections(com.b2international.collections.longs.LongCollections) SnomedOWLExpressionConverterResult(com.b2international.snowowl.snomed.datastore.request.SnomedOWLExpressionConverterResult) Expressions.typeId(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry.Expressions.typeId) Concepts(com.b2international.snowowl.snomed.common.SnomedConstants.Concepts) ImmutableList(com.google.common.collect.ImmutableList) LongSets(com.b2international.commons.collect.LongSets) RevisionSearcher(com.b2international.index.revision.RevisionSearcher) ExpressionBuilder(com.b2international.index.query.Expressions.ExpressionBuilder) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) CompareUtils(com.b2international.commons.CompareUtils) RevisionPropertyDiff(com.b2international.index.revision.StagingArea.RevisionPropertyDiff) SnomedConceptDocument(com.b2international.snowowl.snomed.datastore.index.entry.SnomedConceptDocument) SnomedOWLRelationshipDocument(com.b2international.snowowl.snomed.datastore.index.entry.SnomedOWLRelationshipDocument) Logger(org.slf4j.Logger) LongIterator(com.b2international.collections.longs.LongIterator) LongCollection(com.b2international.collections.longs.LongCollection) SnowowlRuntimeException(com.b2international.snowowl.core.api.SnowowlRuntimeException) Collection(java.util.Collection) SnomedOWLExpressionConverter(com.b2international.snowowl.snomed.datastore.request.SnomedOWLExpressionConverter) Expressions.characteristicTypeId(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry.Expressions.characteristicTypeId) Expressions.sourceIds(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry.Expressions.sourceIds) Set(java.util.Set) IOException(java.io.IOException) Sets(com.google.common.collect.Sets) Expressions.destinationIds(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry.Expressions.destinationIds) Preconditions.checkState(com.google.common.base.Preconditions.checkState) Expressions(com.b2international.index.query.Expressions) Expressions.active(com.b2international.snowowl.snomed.datastore.index.entry.SnomedDocument.Expressions.active) StagingArea(com.b2international.index.revision.StagingArea) IComponent(com.b2international.snowowl.core.domain.IComponent) Collections(java.util.Collections) SnomedRefSetType(com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType) SnomedOWLRelationshipDocument(com.b2international.snowowl.snomed.datastore.index.entry.SnomedOWLRelationshipDocument) SnomedOWLExpressionConverterResult(com.b2international.snowowl.snomed.datastore.request.SnomedOWLExpressionConverterResult)

Example 4 with SnomedOWLExpressionConverterResult

use of com.b2international.snowowl.snomed.datastore.request.SnomedOWLExpressionConverterResult in project snow-owl by b2ihealthcare.

the class SnomedOWLExpressionReferenceSetMemberBuilder method init.

@Override
public void init(final SnomedRefSetMemberIndexEntry.Builder component, final TransactionContext context) {
    super.init(component, context);
    SnomedOWLExpressionConverterResult result = context.service(SnomedOWLExpressionConverter.class).toSnomedOWLRelationships(getReferencedComponentId(), owlExpression);
    component.field(SnomedRf2Headers.FIELD_OWL_EXPRESSION, owlExpression).classAxiomRelationships(result.getClassAxiomRelationships()).gciAxiomRelationships(result.getGciAxiomRelationships());
}
Also used : SnomedOWLExpressionConverter(com.b2international.snowowl.snomed.datastore.request.SnomedOWLExpressionConverter) SnomedOWLExpressionConverterResult(com.b2international.snowowl.snomed.datastore.request.SnomedOWLExpressionConverterResult)

Example 5 with SnomedOWLExpressionConverterResult

use of com.b2international.snowowl.snomed.datastore.request.SnomedOWLExpressionConverterResult in project snow-owl by b2ihealthcare.

the class SnomedRefSetMemberDocumentSerializationTest method indexOWLAxiomMember_MalformedGCIAxiom.

@Test
public void indexOWLAxiomMember_MalformedGCIAxiom() throws Exception {
    /*
		 * According to the OWL Guide (Yong):
		 * If an axiom is in the form of SubClassOf(C D) and C is a precoordinated concept,
		 * this SubclassOf axiom is NOT a GCI axiom and the concept D should not be assigned as the referencedComponentId.
		 * 
		 * This would be a normal SubclassOf axiom and C is the referenced component.
		 * 
		 */
    final String referencedComponentId = "231907006";
    final String owlExpression = "SubClassOf(:193783008 :231907006)";
    try {
        final SnomedOWLExpressionConverterResult owlRelationships = toSnomedOWLRelationships(referencedComponentId, owlExpression);
        final SnomedRefSetMemberIndexEntry member = createBaseMember().referencedComponentId(referencedComponentId).refsetId(Concepts.REFSET_OWL_AXIOM).referenceSetType(SnomedRefSetType.OWL_AXIOM).field(Fields.OWL_EXPRESSION, owlExpression).classAxiomRelationships(owlRelationships.getClassAxiomRelationships()).gciAxiomRelationships(owlRelationships.getGciAxiomRelationships()).build();
        indexRevision(RevisionBranch.MAIN_PATH, member);
        final SnomedRefSetMemberIndexEntry actual = getRevision(RevisionBranch.MAIN_PATH, SnomedRefSetMemberIndexEntry.class, member.getId());
        assertThat(actual.getGciAxiomRelationships()).isEmpty();
        assertThat(actual.getClassAxiomRelationships()).isEmpty();
        assertDocEquals(member, actual);
    } catch (Exception e) {
        // the OWL conversion process must not throw any exception in such cases, but
        // rather convert the expression with empty relationship results
        fail();
    }
}
Also used : SnomedOWLExpressionConverterResult(com.b2international.snowowl.snomed.datastore.request.SnomedOWLExpressionConverterResult) Test(org.junit.Test) BaseRevisionIndexTest(com.b2international.index.revision.BaseRevisionIndexTest)

Aggregations

SnomedOWLExpressionConverterResult (com.b2international.snowowl.snomed.datastore.request.SnomedOWLExpressionConverterResult)8 BaseRevisionIndexTest (com.b2international.index.revision.BaseRevisionIndexTest)3 Test (org.junit.Test)3 SnomedOWLExpressionConverter (com.b2international.snowowl.snomed.datastore.request.SnomedOWLExpressionConverter)2 LongCollection (com.b2international.collections.longs.LongCollection)1 LongCollections (com.b2international.collections.longs.LongCollections)1 LongIterator (com.b2international.collections.longs.LongIterator)1 CompareUtils (com.b2international.commons.CompareUtils)1 LongSets (com.b2international.commons.collect.LongSets)1 Hits (com.b2international.index.Hits)1 Expressions (com.b2international.index.query.Expressions)1 ExpressionBuilder (com.b2international.index.query.Expressions.ExpressionBuilder)1 Query (com.b2international.index.query.Query)1 RevisionSearcher (com.b2international.index.revision.RevisionSearcher)1 StagingArea (com.b2international.index.revision.StagingArea)1 RevisionPropertyDiff (com.b2international.index.revision.StagingArea.RevisionPropertyDiff)1 SnowowlRuntimeException (com.b2international.snowowl.core.api.SnowowlRuntimeException)1 IComponent (com.b2international.snowowl.core.domain.IComponent)1 Concepts (com.b2international.snowowl.snomed.common.SnomedConstants.Concepts)1 SnomedRefSetType (com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType)1