Skip to content

Commit

Permalink
Support old match_term_type metadata slot.
Browse files Browse the repository at this point in the history
Initial versions of SSSOM used a single slot called 'match_term_type' to
indicate what was being mapped. This slot has been replaced in SSSOM
0.9.1 by two slots called 'subject_type' and 'object_type'. If a
'match_term_type' slot is found in a mapping set (and that set does not
contain 'subject_type' and 'object_type' slots), we convert it to its
modern equivalents.
  • Loading branch information
gouttegd committed Oct 29, 2023
1 parent 36b8c0e commit 0ecd470
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 10 deletions.
6 changes: 3 additions & 3 deletions cli/src/test/resources/updated-fields.sssom.tsv
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#curie_map:
# FBbt: "http://purl.obolibrary.org/obo/FBbt_"
# UBERON: "http://purl.obolibrary.org/obo/UBERON_"
subject_id subject_label predicate_id object_id mapping_justification
FBbt:00000001 organism semapv:crossSpeciesExactMatch UBERON:0000468 semapv:LexicalMatching
FBbt:00000002 tagma semapv:crossSpeciesExactMatch UBERON:6000002
subject_id subject_label predicate_id object_id mapping_justification subject_type object_type
FBbt:00000001 organism semapv:crossSpeciesExactMatch UBERON:0000468 semapv:LexicalMatching
FBbt:00000002 tagma semapv:crossSpeciesExactMatch UBERON:6000002 owl class owl class
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* SSSOM-Java - SSSOM library for Java
* Copyright © 2023 Damien Goutte-Gattat
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the Gnu General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package org.incenp.obofoundry.sssom;

import java.util.Map;

/**
* A YAML preprocessor to convert a dictionary containing a
* {@code match_term_type} metadata slot into its standardised equivalents.
* <p>
* Initial versions of the SSSOM specification described a
* {@code match_term_type} metadata slot which accepted values from a specific
* enumeration and was intended to describe what was being matched (e.g., it
* indicated that a given mapping was between two OWL classes, or between two
* SKOS concepts, etc.). In SSSOM 0.9.1, this slot was replaced by two distinct
* slots called {@code subject_type} and {@code object_type}.
*/
public class MatchTermTypeConverter implements IYAMLPreprocessor {

@Override
public void process(Map<String, Object> rawMap) throws SSSOMFormatException {
if ( rawMap.containsKey("match_term_type") && !rawMap.containsKey("subject_type")
&& !rawMap.containsKey("object_type") ) {
Object rawValue = rawMap.get("match_term_type");
String value = null;
if ( rawValue != null ) {
if ( String.class.isInstance(rawValue) ) {
switch ( String.class.cast(rawValue) ) {
case "ConceptMatch":
value = "skos concept";
break;
case "ClassMatch":
value = "owl class";
break;
case "ObjectPropertyMatch":
value = "owl object property";
break;
case "IndividualMatch":
value = "owl named indivdual";
break;
case "DataPropertyMatch":
value = "owl data property";
break;
case "TermMatch":
// FIXME: It's unclear what is the equivalent of TermMatch in the new enum.
value = "rdf literal";
break;
}
}

if ( value == null ) {
throw new SSSOMFormatException("Typing error when parsing 'match_term_type'");
}
}

rawMap.remove("match_term_type");
rawMap.put("subject_type", value);
rawMap.put("object_type", value);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public YAMLConverter() {

preprocessors = new ArrayList<IYAMLPreprocessor>();
preprocessors.add(new MatchTypeConverter());
preprocessors.add(new MatchTermTypeConverter());

setSlotMaps = new HashMap<String, Slot<MappingSet>>();
for ( Slot<MappingSet> slot : SlotHelper.getMappingSetHelper().getSlots() ) {
Expand Down
15 changes: 11 additions & 4 deletions core/src/test/java/org/incenp/obofoundry/sssom/TSVReaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.List;

import org.apache.commons.io.FileUtils;
import org.incenp.obofoundry.sssom.model.EntityType;
import org.incenp.obofoundry.sssom.model.Mapping;
import org.incenp.obofoundry.sssom.model.MappingSet;
import org.junit.jupiter.api.Assertions;
Expand Down Expand Up @@ -273,9 +274,15 @@ void testSlotPropagation() throws IOException, SSSOMFormatException {
void testObsoleteFields() throws IOException, SSSOMFormatException {
TSVReader reader = new TSVReader("src/test/resources/obsolete-fields.sssom.tsv");
MappingSet ms = reader.read();

Assertions.assertEquals("https://w3id.org/semapv/vocab/LexicalMatching",
ms.getMappings().get(0).getMappingJustification());
Assertions.assertNull(ms.getMappings().get(1).getMappingJustification());
Mapping m1 = ms.getMappings().get(0);
Mapping m2 = ms.getMappings().get(1);

Assertions.assertEquals("https://w3id.org/semapv/vocab/LexicalMatching", m1.getMappingJustification());
Assertions.assertNull(m2.getMappingJustification());

Assertions.assertNull(m1.getSubjectType());
Assertions.assertNull(m1.getObjectType());
Assertions.assertEquals(EntityType.OWL_CLASS, m2.getSubjectType());
Assertions.assertEquals(EntityType.OWL_CLASS, m2.getObjectType());
}
}
6 changes: 3 additions & 3 deletions core/src/test/resources/obsolete-fields.sssom.tsv
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#curie_map:
# FBbt: "http://purl.obolibrary.org/obo/FBbt_"
# UBERON: "http://purl.obolibrary.org/obo/UBERON_"
subject_id subject_label predicate_id object_id match_type
FBbt:00000001 organism semapv:crossSpeciesExactMatch UBERON:0000468 Lexical
FBbt:00000002 tagma semapv:crossSpeciesExactMatch UBERON:6000002
subject_id subject_label predicate_id object_id match_type match_term_type
FBbt:00000001 organism semapv:crossSpeciesExactMatch UBERON:0000468 Lexical
FBbt:00000002 tagma semapv:crossSpeciesExactMatch UBERON:6000002 ClassMatch

0 comments on commit 0ecd470

Please sign in to comment.