From 7dd59952687d8dd77dd7d6c37acbc35fa573702a Mon Sep 17 00:00:00 2001 From: "James A. Overton" Date: Wed, 29 Nov 2023 11:13:23 -0500 Subject: [PATCH 1/3] Handle IRIs that are not entities in export --- .../org/obolibrary/robot/ExportOperation.java | 8 +++++-- .../obolibrary/robot/ExportOperationTest.java | 23 ++++++++++++++++--- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/robot-core/src/main/java/org/obolibrary/robot/ExportOperation.java b/robot-core/src/main/java/org/obolibrary/robot/ExportOperation.java index 72cd3885d..2a10711ee 100644 --- a/robot-core/src/main/java/org/obolibrary/robot/ExportOperation.java +++ b/robot-core/src/main/java/org/obolibrary/robot/ExportOperation.java @@ -496,8 +496,12 @@ private static List getPropertyValues( IRI iri = a.getValue().asIRI().orNull(); if (iri != null) { Set entities = ontology.getEntitiesInSignature(iri); - for (OWLEntity e : entities) { - values.add(OntologyHelper.renderManchester(e, provider, rt)); + if (entities.size() > 0) { + for (OWLEntity e : entities) { + values.add(OntologyHelper.renderManchester(e, provider, rt)); + } + } else { + values.add(iri.toString()); } } } else { diff --git a/robot-core/src/test/java/org/obolibrary/robot/ExportOperationTest.java b/robot-core/src/test/java/org/obolibrary/robot/ExportOperationTest.java index 2dab8b5b2..fe4a53e85 100644 --- a/robot-core/src/test/java/org/obolibrary/robot/ExportOperationTest.java +++ b/robot-core/src/test/java/org/obolibrary/robot/ExportOperationTest.java @@ -1,5 +1,7 @@ package org.obolibrary.robot; +import static org.junit.Assert.assertEquals; + import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -121,7 +123,7 @@ public void testLargeExcelExport() throws Exception { */ @Test public void testExportNamedHeadingsSimple() throws Exception { - OWLOntology ontology = loadOntology("/simple.owl"); + OWLOntology ontology = loadOntology("/simple_defined_by.owl"); IOHelper ioHelper = new IOHelper(); ioHelper.addPrefix( "simple", "https://github.com/ontodev/robot/robot-core/src/test/resources/simple.owl#"); @@ -135,6 +137,7 @@ public void testExportNamedHeadingsSimple() throws Exception { "CURIE", "Type", "SYNONYMS", + "rdfs:isDefinedBy", "SUBCLASSES", "SubClass Of", "SubProperty Of", @@ -152,9 +155,18 @@ public void testExportNamedHeadingsSimple() throws Exception { Table t = ExportOperation.createExportTable(ontology, ioHelper, columns, options); Workbook wb = t.asWorkbook("|"); + // Write test.xlsx for debugging + // try { + // System.out.println("Writing result to robot-core/test.xlsx"); + // FileOutputStream out = new FileOutputStream("test.xlsx"); + // wb.write(out); + // out.close(); + // } catch (Exception ex) { + // System.out.println("Error: " + ex); + // } + Sheet s = wb.getSheetAt(0); - // There should be three rows (0, 1, 2) - assert (s.getLastRowNum() == 3); + assertEquals(s.getLastRowNum(), 4); // Validate header // should match size and label @@ -176,6 +188,11 @@ public void testExportNamedHeadingsSimple() throws Exception { String expectedHeader = columns.get(colIx); assert (foundHeader.equals(expectedHeader)); } + + // rdfs:isDefinedBy should work + assertEquals( + s.getRow(4).getCell(6).getStringCellValue(), + "https://github.com/ontodev/robot/robot-core/src/test/resources/simple.owl"); } /** From 0a809020523b8ed7e3f4d8d003cf4e4c35e1712b Mon Sep 17 00:00:00 2001 From: "James A. Overton" Date: Wed, 29 Nov 2023 11:19:15 -0500 Subject: [PATCH 2/3] Update CHANGELOG for export fix --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 37cfc19ea..955f1cf4b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - '--annotate-with-source true' does not work with extract --method subset [#1160] - Fix how Template adds entities to the QuotedEntityChecker [#1104] +- Handle IRIs that are not entities in export [#1168] ## [1.9.5] - 2023-09-20 @@ -380,6 +381,7 @@ First official release of ROBOT! [`template`]: http://robot.obolibrary.org/template [`validate`]: http://robot.obolibrary.org/validate +[#1168]: https://github.com/ontodev/robot/pull/1168 [#1160]: https://github.com/ontodev/robot/pull/1160 [#1148]: https://github.com/ontodev/robot/pull/1148 [#1135]: https://github.com/ontodev/robot/pull/1135 From 4acc9a6051d984fcae9eb3ed2d97a9258c785d76 Mon Sep 17 00:00:00 2001 From: "James A. Overton" Date: Thu, 30 Nov 2023 16:22:09 -0500 Subject: [PATCH 3/3] Add writeXLSX utility method --- .../obolibrary/robot/ExportOperationTest.java | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/robot-core/src/test/java/org/obolibrary/robot/ExportOperationTest.java b/robot-core/src/test/java/org/obolibrary/robot/ExportOperationTest.java index fe4a53e85..f33b45d62 100644 --- a/robot-core/src/test/java/org/obolibrary/robot/ExportOperationTest.java +++ b/robot-core/src/test/java/org/obolibrary/robot/ExportOperationTest.java @@ -2,6 +2,7 @@ import static org.junit.Assert.assertEquals; +import java.io.FileOutputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -31,6 +32,23 @@ */ public class ExportOperationTest extends CoreTest { + /** + * Utility method to write XLSX file for debugging. + * + * @param workbook Workfbook to write + * @param path Path (string) to save to, under `robot-core/` + */ + void writeXLSX(Workbook workbook, String path) { + try { + System.out.println("Writing result to robot-core/" + path); + FileOutputStream out = new FileOutputStream(path); + workbook.write(out); + out.close(); + } catch (Exception ex) { + System.out.println("Error writing workbook: " + ex); + } + } + /** * Test exporting simple.owl to XLSX. * @@ -155,16 +173,6 @@ public void testExportNamedHeadingsSimple() throws Exception { Table t = ExportOperation.createExportTable(ontology, ioHelper, columns, options); Workbook wb = t.asWorkbook("|"); - // Write test.xlsx for debugging - // try { - // System.out.println("Writing result to robot-core/test.xlsx"); - // FileOutputStream out = new FileOutputStream("test.xlsx"); - // wb.write(out); - // out.close(); - // } catch (Exception ex) { - // System.out.println("Error: " + ex); - // } - Sheet s = wb.getSheetAt(0); assertEquals(s.getLastRowNum(), 4);