Repository: ontodev/robot (java)

Issue:
Export command does not export a column for "rdfs:isDefinedBy"
An export command that includes `rdfs:isDefinedBy` in the header doesn't export any values for this column. 
I believe the issue is in ExportOperation.getPropertyValues() where it attempts to find an entity in the ontology to use as the value for this column. Since the target for rdfs:isDefinedBy is usually an IRI for an ontology (not a term in an ontology), the call `ontology.getEntitiesInSignature(iri)` never returns an entity (the IRI for the ontology and any imported ontologies are not in the signature for the ontology ) so no value is created.
This could be handled either by checking for the IRIs for the ontology and imported ontologies in addition to the term IRIs or just using the IRI as the value if no entities are found for that IRI. 


Pull request:
Handle IRIs that are not entities in export
Resolves #1165

- [ ] `docs/` have been added/updated
- [x] tests have been added/updated
- [x] `mvn verify` says all tests pass
- [ ] `mvn site` says all JavaDocs correct
- [x] `CHANGELOG.md` has been updated


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 37cfc19e..955f1cf4 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
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 72cd3885..2a10711e 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 @@ public class ExportOperation {
           IRI iri = a.getValue().asIRI().orNull();
           if (iri != null) {
             Set<OWLEntity> 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 {


Test patch:
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 2dab8b5b..f33b45d6 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,8 @@
 package org.obolibrary.robot;
 
+import static org.junit.Assert.assertEquals;
+
+import java.io.FileOutputStream;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -29,6 +32,23 @@ import org.semanticweb.owlapi.util.DefaultPrefixManager;
  */
 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.
    *
@@ -121,7 +141,7 @@ public class ExportOperationTest extends CoreTest {
    */
   @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 +155,7 @@ public class ExportOperationTest extends CoreTest {
             "CURIE",
             "Type",
             "SYNONYMS",
+            "rdfs:isDefinedBy",
             "SUBCLASSES",
             "SubClass Of",
             "SubProperty Of",
@@ -153,8 +174,7 @@ public class ExportOperationTest extends CoreTest {
     Workbook wb = t.asWorkbook("|");
 
     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 +196,11 @@ public class ExportOperationTest extends CoreTest {
       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");
   }
 
   /**