Skip to content

Commit

Permalink
Create helper method Mapping::isUnmapped().
Browse files Browse the repository at this point in the history
We encapsulate the check to determine whether a mapping refers to
sssom:NoTermFound directly in the Mapping class, by adding to the
LinkML-derived Lombok template a custom `isUnmapped()` method.
  • Loading branch information
gouttegd committed Aug 4, 2024
1 parent 060cea2 commit 4a1e751
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public static void inferCardinality(List<Mapping> mappings) {
HashMap<String, HashSet<String>> objects = new HashMap<String, HashSet<String>>();

for ( Mapping m : mappings ) {
if ( Constants.NoTermFound.equals(m.getSubjectId()) || Constants.NoTermFound.equals(m.getObjectId()) ) {
if ( m.isUnmapped() ) {
continue;
}

Expand All @@ -116,7 +116,7 @@ public static void inferCardinality(List<Mapping> mappings) {
}

for ( Mapping m : mappings ) {
if ( Constants.NoTermFound.equals(m.getSubjectId()) || Constants.NoTermFound.equals(m.getObjectId()) ) {
if ( m.isUnmapped() ) {
m.setMappingCardinality(null);
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,19 @@ public void setSemanticSimilarityScore(Double value) {
}

private Map<String,ExtensionValue> extensions;

/**
* Indicates whether this mapping represents a "missing" mapping.
* <p>
* A missing mapping is a mapping where the <em>subject_id</em> or the
* <em>object_id</em> (or both) is the special value
* <code>sssom:NoTermFound</code>, and indicates that an entity in one
* domain could not be mapped to any entity in another domain.
*
* @return {@code True} if the mapping is a missing mapping,
* {@code false} otherwise.
*/
public boolean isUnmapped() {
return Constants.NoTermFound.equals(subjectId) || Constants.NoTermFound.equals(objectId);
}
}
16 changes: 16 additions & 0 deletions linkml/custom-javagen.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,22 @@
{%- if cls.name == 'MappingSet' or cls.name == 'Mapping' %}
private Map<String,ExtensionValue> extensions;
{% endif -%}
{%- if cls.name == 'Mapping' %}
/**
* Indicates whether this mapping represents a "missing" mapping.
* <p>
* A missing mapping is a mapping where the <em>subject_id</em> or the
* <em>object_id</em> (or both) is the special value
* <code>sssom:NoTermFound</code>, and indicates that an entity in one
* domain could not be mapped to any entity in another domain.
*
* @return {@code True} if the mapping is a missing mapping,
* {@code false} otherwise.
*/
public boolean isUnmapped() {
return Constants.NoTermFound.equals(subjectId) || Constants.NoTermFound.equals(objectId);
}
{% endif -%}
}
"""
Expand Down

0 comments on commit 4a1e751

Please sign in to comment.