Skip to content

Commit

Permalink
fix(owl): Add utility methods to Snomed OWL relationships...
Browse files Browse the repository at this point in the history
...Meant to aid with statement fragment generation used by classifiers
and to ease conversion between its document form
  • Loading branch information
AAAlinaaa committed Dec 5, 2024
1 parent 67682e6 commit ca2675e
Showing 1 changed file with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
import com.b2international.snowowl.snomed.core.domain.RelationshipValue;
import com.b2international.snowowl.snomed.core.domain.SnomedConcept;
import com.b2international.snowowl.snomed.core.domain.SnomedRelationship;
import com.b2international.snowowl.snomed.datastore.StatementFragment;
import com.b2international.snowowl.snomed.datastore.StatementFragmentWithDestination;
import com.b2international.snowowl.snomed.datastore.StatementFragmentWithValue;
import com.b2international.snowowl.snomed.datastore.index.entry.SnomedOWLRelationshipDocument;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;

Expand Down Expand Up @@ -204,6 +208,14 @@ public static SnomedOWLRelationship createFrom(final SnomedRelationship r) {
}
}

public static SnomedOWLRelationship createFrom(final SnomedOWLRelationshipDocument r) {
if (r.hasValue()) {
return create(r.getTypeId(), r.getValueAsObject(), r.getRelationshipGroup());

Check warning on line 213 in snomed/com.b2international.snowowl.snomed.datastore/src/com/b2international/snowowl/snomed/core/domain/refset/SnomedOWLRelationship.java

View check run for this annotation

Codecov / codecov/patch

snomed/com.b2international.snowowl.snomed.datastore/src/com/b2international/snowowl/snomed/core/domain/refset/SnomedOWLRelationship.java#L213

Added line #L213 was not covered by tests
} else {
return create(r.getTypeId(), r.getDestinationId(), r.getRelationshipGroup());

Check warning on line 215 in snomed/com.b2international.snowowl.snomed.datastore/src/com/b2international/snowowl/snomed/core/domain/refset/SnomedOWLRelationship.java

View check run for this annotation

Codecov / codecov/patch

snomed/com.b2international.snowowl.snomed.datastore/src/com/b2international/snowowl/snomed/core/domain/refset/SnomedOWLRelationship.java#L215

Added line #L215 was not covered by tests
}
}

public static SnomedOWLRelationship create(final String typeId, final String destinationId, final int relationshipGroup) {
SnomedOWLRelationship owlRelationship = new SnomedOWLRelationship();

Expand All @@ -224,4 +236,38 @@ public static SnomedOWLRelationship create(final String typeId, final Relationsh
return owlRelationship;
}

@JsonIgnore
public StatementFragment toStatementFragment(final int groupOffset) {
final int adjustedGroup;
if (relationshipGroup == 0) {
adjustedGroup = relationshipGroup;
} else {
adjustedGroup = relationshipGroup + groupOffset;

Check warning on line 245 in snomed/com.b2international.snowowl.snomed.datastore/src/com/b2international/snowowl/snomed/core/domain/refset/SnomedOWLRelationship.java

View check run for this annotation

Codecov / codecov/patch

snomed/com.b2international.snowowl.snomed.datastore/src/com/b2international/snowowl/snomed/core/domain/refset/SnomedOWLRelationship.java#L243-L245

Added lines #L243 - L245 were not covered by tests
}

if (getDestinationId() != null) {
return new StatementFragmentWithDestination(
Long.parseLong(getTypeId()), // typeId
adjustedGroup, // adjustedGroup
0, // unionGroup
false, // universal
-1L, // statementId
-1L, // moduleId
false, // released
Long.parseLong(getDestinationId()), // destinationId
false); // destinationNegated

Check warning on line 258 in snomed/com.b2international.snowowl.snomed.datastore/src/com/b2international/snowowl/snomed/core/domain/refset/SnomedOWLRelationship.java

View check run for this annotation

Codecov / codecov/patch

snomed/com.b2international.snowowl.snomed.datastore/src/com/b2international/snowowl/snomed/core/domain/refset/SnomedOWLRelationship.java#L249-L258

Added lines #L249 - L258 were not covered by tests
} else {
return new StatementFragmentWithValue(
Long.parseLong(getTypeId()), // typeId
adjustedGroup, // adjustedGroup
0, // unionGroup
false, // universal
-1L, // statementId
-1L, // moduleId
false, // released
value.type(), // valueType
value.toRawValue()); // rawValue

Check warning on line 269 in snomed/com.b2international.snowowl.snomed.datastore/src/com/b2international/snowowl/snomed/core/domain/refset/SnomedOWLRelationship.java

View check run for this annotation

Codecov / codecov/patch

snomed/com.b2international.snowowl.snomed.datastore/src/com/b2international/snowowl/snomed/core/domain/refset/SnomedOWLRelationship.java#L260-L269

Added lines #L260 - L269 were not covered by tests
}
}

}

0 comments on commit ca2675e

Please sign in to comment.