-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1302 from b2ihealthcare/issue/support-cd-member-i…
…nference feat(classification): resurrect cd member inference
- Loading branch information
Showing
4 changed files
with
160 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
...international/snowowl/snomed/reasoner/normalform/NormalFormConcreteDomainMemberValue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/* | ||
* Copyright 2024 B2i Healthcare, https://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.reasoner.normalform; | ||
|
||
import static com.google.common.base.Preconditions.checkNotNull; | ||
|
||
import java.text.MessageFormat; | ||
import java.util.Objects; | ||
|
||
import com.b2international.snowowl.snomed.core.domain.refset.DataType; | ||
import com.b2international.snowowl.snomed.datastore.ConcreteDomainFragment; | ||
import com.b2international.snowowl.snomed.datastore.SnomedRefSetUtil; | ||
import com.b2international.snowowl.snomed.datastore.index.taxonomy.ReasonerTaxonomy; | ||
|
||
/** | ||
* Wraps concept concrete domain members, used in the normal form generation process. | ||
*/ | ||
final class NormalFormConcreteDomainMemberValue implements NormalFormProperty { | ||
|
||
private final ConcreteDomainFragment fragment; | ||
private final ReasonerTaxonomy reasonerTaxonomy; | ||
|
||
/** | ||
* Creates a new instance from the specified concrete domain member. | ||
* | ||
* @param fragment the concrete domain fragment to wrap (may not be <code>null</code>) | ||
* @param reasonerTaxonomy | ||
* | ||
* @throws NullPointerException if the given concrete domain member is <code>null</code> | ||
*/ | ||
public NormalFormConcreteDomainMemberValue(final ConcreteDomainFragment fragment, final ReasonerTaxonomy reasonerTaxonomy) { | ||
this.fragment = checkNotNull(fragment, "fragment"); | ||
this.reasonerTaxonomy = checkNotNull(reasonerTaxonomy, "reasonerTaxonomy"); | ||
} | ||
|
||
public ConcreteDomainFragment getFragment() { | ||
return fragment; | ||
} | ||
|
||
public String getSerializedValue() { | ||
return fragment.getSerializedValue(); | ||
} | ||
|
||
public long getTypeId() { | ||
return fragment.getTypeId(); | ||
} | ||
|
||
public long getRefSetId() { | ||
return fragment.getRefSetId(); | ||
} | ||
|
||
public String getMemberId() { | ||
return fragment.getMemberId(); | ||
} | ||
|
||
public boolean isReleased() { | ||
return fragment.isReleased(); | ||
} | ||
|
||
@Override | ||
public boolean isSameOrStrongerThan(final NormalFormProperty property) { | ||
if (this == property) { return true; } | ||
if (!(property instanceof NormalFormConcreteDomainMemberValue)) { return false; } | ||
|
||
final NormalFormConcreteDomainMemberValue other = (NormalFormConcreteDomainMemberValue) property; | ||
|
||
// Check type SCTID subsumption, data type (reference set SCTID) and value equality | ||
return true | ||
&& getRefSetId() == other.getRefSetId() | ||
&& closureContains(getTypeId(), other.getTypeId()) | ||
&& getSerializedValue().equals(other.getSerializedValue()); | ||
} | ||
|
||
private boolean ancestorsContains(final long conceptId1, final long conceptId2) { | ||
return reasonerTaxonomy.getInferredAncestors().getDestinations(conceptId1, false).contains(conceptId2); | ||
} | ||
|
||
private boolean closureContains(final long conceptId1, final long conceptId2) { | ||
return (conceptId1 == conceptId2) || ancestorsContains(conceptId1, conceptId2); | ||
} | ||
|
||
@Override | ||
public boolean equals(final Object obj) { | ||
if (this == obj) { return true; } | ||
if (!(obj instanceof NormalFormConcreteDomainMemberValue)) { return false; } | ||
|
||
final NormalFormConcreteDomainMemberValue other = (NormalFormConcreteDomainMemberValue) obj; | ||
|
||
if (getRefSetId() != other.getRefSetId()) { return false; } | ||
if (getTypeId() != other.getTypeId()) { return false; } | ||
if (!getSerializedValue().equals(other.getSerializedValue())) { return false; } | ||
|
||
return true; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(getSerializedValue(), getRefSetId(), getTypeId()); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
final String refSetId = Long.toString(getRefSetId()); | ||
final DataType dataType = SnomedRefSetUtil.getDataType(refSetId); | ||
return MessageFormat.format("{0,number,#} : {1} [{2}]", getTypeId(), getSerializedValue(), dataType); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters