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 5c32d81..ca2c8e7 100644 --- a/core/src/main/java/org/incenp/obofoundry/sssom/YAMLConverter.java +++ b/core/src/main/java/org/incenp/obofoundry/sssom/YAMLConverter.java @@ -175,6 +175,9 @@ public MappingSet convertMappingSet(Map rawMap) throws SSSOMForm // Process the bulk of the metadata slots Map extensionSlots = new HashMap(); for ( String key : rawMap.keySet() ) { + if ( key.equals("mappings") ) { // To be processed separately + continue; + } if ( setSlotMaps.containsKey(key) ) { setSlotValue(setSlotMaps.get(key), ms, rawMap.get(key)); } else { diff --git a/core/src/test/java/org/incenp/obofoundry/sssom/JSONReaderTest.java b/core/src/test/java/org/incenp/obofoundry/sssom/JSONReaderTest.java index 11f8118..b993d2d 100644 --- a/core/src/test/java/org/incenp/obofoundry/sssom/JSONReaderTest.java +++ b/core/src/test/java/org/incenp/obofoundry/sssom/JSONReaderTest.java @@ -21,6 +21,7 @@ import java.io.IOException; import java.time.LocalDate; +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; @@ -160,4 +161,13 @@ void testSlotPropagation() throws IOException, SSSOMFormatException { // Second mapping has its own mapping tool value Assertions.assertEquals("bar mapper", ms.getMappings().get(1).getMappingTool()); } + + @Test + void testParsingNonStringValues() throws IOException, SSSOMFormatException { + JSONReader reader = new JSONReader("src/test/resources/sets/test-non-string-values.sssom.json"); + MappingSet ms = reader.read(); + + Assertions.assertEquals(EntityType.OWL_CLASS, ms.getMappings().get(0).getSubjectType()); + Assertions.assertEquals(0.7, ms.getMappings().get(0).getConfidence()); + } } diff --git a/core/src/test/java/org/incenp/obofoundry/sssom/JSONWriterTest.java b/core/src/test/java/org/incenp/obofoundry/sssom/JSONWriterTest.java index 1a655d5..6a74269 100644 --- a/core/src/test/java/org/incenp/obofoundry/sssom/JSONWriterTest.java +++ b/core/src/test/java/org/incenp/obofoundry/sssom/JSONWriterTest.java @@ -92,6 +92,54 @@ void testEscapingJSON() throws IOException, SSSOMFormatException { assertWrittenAsExpected(ms, "test-escaping-json", null, null); } + @Test + void testBasicRoundtrip() throws IOException, SSSOMFormatException { + JSONReader reader = new JSONReader("src/test/resources/sets/exo2c.sssom.json"); + MappingSet ms = reader.read(); + + assertWrittenAsExpected(ms, "exo2c", "test-basic-roundtrip", null); + } + + @Test + void testTSVAndJSONRoundtrips() throws IOException, SSSOMFormatException { + TSVtoJSONtoTSVRoundtrip("exo2c", ExtraMetadataPolicy.NONE); + TSVtoJSONtoTSVRoundtrip("test-extensions-defined", ExtraMetadataPolicy.DEFINED); + } + + private void TSVtoJSONtoTSVRoundtrip(String tsvFilename, ExtraMetadataPolicy policy) + throws IOException, SSSOMFormatException { + File origTSV = new File("src/test/resources/sets/" + tsvFilename + ".sssom.tsv"); + if ( !origTSV.exists() ) { + origTSV = new File("src/test/resources/output/" + tsvFilename + ".sssom.tsv"); + } + + TSVReader tsvReader = new TSVReader(origTSV); + tsvReader.setExtraMetadataPolicy(policy); + MappingSet ms = tsvReader.read(); + + File json = new File("src/test/resources/output/" + tsvFilename + ".sssom.json.out"); + JSONWriter jsonWriter = new JSONWriter(json); + jsonWriter.setShortenIRIs(true); + jsonWriter.setExtraMetadataPolicy(policy); + jsonWriter.write(ms); + + JSONReader jsonReader = new JSONReader(json); + jsonReader.setExtraMetadataPolicy(policy); + ms = jsonReader.read(); + + File newTSV = new File("src/test/resources/output/" + tsvFilename + ".sssom.tsv.out"); + TSVWriter tsvWriter = new TSVWriter(newTSV); + tsvWriter.setExtraMetadataPolicy(policy); + tsvWriter.write(ms); + + boolean same = FileUtils.contentEquals(origTSV, newTSV); + Assertions.assertTrue(same); + if ( same ) { + json.delete(); + newTSV.delete(); + } + } + /* * Checks that a mapping set is written exactly as we expect. This method will * write the provided set to a temporary file and compares the written file with diff --git a/core/src/test/resources/sets/test-non-string-values.sssom.json b/core/src/test/resources/sets/test-non-string-values.sssom.json new file mode 100644 index 0000000..2a73bd8 --- /dev/null +++ b/core/src/test/resources/sets/test-non-string-values.sssom.json @@ -0,0 +1,20 @@ +{ + "curie_map": { + "COMENT": "https://example.com/entities/", + "ORGENT": "https://example.org/entities/" + }, + "mapping_set_id": "https://example.org/sets/exo2c", + "mapping_set_title": "O2C set", + "mappings": [ + { + "subject_id": "ORGENT:0001", + "subject_label": "alice", + "predicate_id": "skos:closeMatch", + "object_id": "COMENT:0011", + "object_label": "alpha", + "mapping_justification": "semapv:ManualMappingCuration", + "subject_type": "owl class", + "confidence": 0.7 + } + ] +}