diff --git a/cli/src/test/resources/updated-fields.sssom.tsv b/cli/src/test/resources/updated-fields.sssom.tsv index b9bc486..4fab5ca 100644 --- a/cli/src/test/resources/updated-fields.sssom.tsv +++ b/cli/src/test/resources/updated-fields.sssom.tsv @@ -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 diff --git a/core/src/main/java/org/incenp/obofoundry/sssom/MatchTermTypeConverter.java b/core/src/main/java/org/incenp/obofoundry/sssom/MatchTermTypeConverter.java new file mode 100644 index 0000000..d0f49bd --- /dev/null +++ b/core/src/main/java/org/incenp/obofoundry/sssom/MatchTermTypeConverter.java @@ -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 . + */ + +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. + *

+ * 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 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); + } + } + +} diff --git a/core/src/main/java/org/incenp/obofoundry/sssom/YAMLConverter.java b/core/src/main/java/org/incenp/obofoundry/sssom/YAMLConverter.java index 7ced758..aa511cf 100644 --- a/core/src/main/java/org/incenp/obofoundry/sssom/YAMLConverter.java +++ b/core/src/main/java/org/incenp/obofoundry/sssom/YAMLConverter.java @@ -49,6 +49,7 @@ public YAMLConverter() { preprocessors = new ArrayList(); preprocessors.add(new MatchTypeConverter()); + preprocessors.add(new MatchTermTypeConverter()); setSlotMaps = new HashMap>(); for ( Slot slot : SlotHelper.getMappingSetHelper().getSlots() ) { diff --git a/core/src/test/java/org/incenp/obofoundry/sssom/TSVReaderTest.java b/core/src/test/java/org/incenp/obofoundry/sssom/TSVReaderTest.java index f9195f4..11d0ec2 100644 --- a/core/src/test/java/org/incenp/obofoundry/sssom/TSVReaderTest.java +++ b/core/src/test/java/org/incenp/obofoundry/sssom/TSVReaderTest.java @@ -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; @@ -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()); } } diff --git a/core/src/test/resources/obsolete-fields.sssom.tsv b/core/src/test/resources/obsolete-fields.sssom.tsv index b561e7c..45bad11 100644 --- a/core/src/test/resources/obsolete-fields.sssom.tsv +++ b/core/src/test/resources/obsolete-fields.sssom.tsv @@ -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