Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export cmd bugfixes #1148

Merged
merged 5 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 29 additions & 13 deletions robot-core/src/main/java/org/obolibrary/robot/ExportOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,11 @@ private static Set<String> getRestrictionFillers(
}
}
break;
// TODO
case DATA_HAS_VALUE:
break;
default:
break;
}
}
return fillers;
Expand Down Expand Up @@ -831,10 +836,25 @@ private static Set<String> getRestrictionFillers(
}
}
break;
// TODO
case OBJECT_HAS_VALUE:
// property value instance
case OBJECT_COMPLEMENT_OF:
// not ce
case OBJECT_HAS_SELF:
// property Self
// this requires the subject entity to render
case OBJECT_ONE_OF:
// {instance, instance,...}
// this should not occur
case OBJECT_UNION_OF:
// ce or ce or ce
// this should not occur
case OBJECT_INTERSECTION_OF:
// TODO
// ce and ce and ce
// this should not occur
break;
default:
break;
}
}
Expand Down Expand Up @@ -1095,18 +1115,8 @@ private static Row getRow(OWLOntology ontology, Table table, OWLEntity entity) t
case "http://www.w3.org/2002/07/owl#equivalentProperty":
// Equivalent Properties
if (entity.isOWLAnnotationProperty()) {
Collection<OWLAnnotationProperty> eqs =
EntitySearcher.getEquivalentProperties(entity.asOWLAnnotationProperty(), ontology);
row.add(
getObjectCell(
eqs,
col,
displayRendererType,
sortRendererType,
provider,
includeNamed,
includeAnonymous));

// no equivalent annotation property in OWL
break;
} else if (entity.isOWLDataProperty()) {
Collection<OWLDataPropertyExpression> eqs =
EntitySearcher.getEquivalentProperties(entity.asOWLDataProperty(), ontology);
Expand Down Expand Up @@ -1140,6 +1150,8 @@ private static Row getRow(OWLOntology ontology, Table table, OWLEntity entity) t
if (entity.isOWLClass()) {
Collection<OWLClassExpression> disjoints =
EntitySearcher.getDisjointClasses(entity.asOWLClass(), ontology);
// remove self-disjoint
disjoints.remove(entity.asOWLClass());
row.add(
getObjectCell(
disjoints,
Expand All @@ -1153,6 +1165,8 @@ private static Row getRow(OWLOntology ontology, Table table, OWLEntity entity) t
} else if (entity.isOWLDataProperty()) {
Collection<OWLDataPropertyExpression> disjoints =
EntitySearcher.getDisjointProperties(entity.asOWLDataProperty(), ontology);
// remove self-disjoint
disjoints.remove(entity.asOWLDataProperty());
row.add(
getObjectCell(
disjoints,
Expand All @@ -1166,6 +1180,8 @@ private static Row getRow(OWLOntology ontology, Table table, OWLEntity entity) t
} else if (entity.isOWLObjectProperty()) {
Collection<OWLObjectPropertyExpression> disjoints =
EntitySearcher.getDisjointProperties(entity.asOWLObjectProperty(), ontology);
// remove self-disjoint
disjoints.remove(entity.asOWLObjectProperty());
row.add(
getObjectCell(
disjoints,
Expand Down
21 changes: 17 additions & 4 deletions robot-core/src/main/java/org/obolibrary/robot/export/Row.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ public void addToWorkbook(Workbook wb, List<Column> columns, String split) {

String value;
String comment = null;
CellStyle style = wb.createCellStyle();
Font font = wb.createFont();
CellStyle style = null;
Font font = null;
if (cell != null) {
List<String> values = cell.getDisplayValues();
if (values.size() > 1) {
Expand All @@ -109,20 +109,34 @@ public void addToWorkbook(Workbook wb, List<Column> columns, String split) {
}

if (cellColor != null) {
if (style == null) {
style = wb.createCellStyle();
}
style.setFillForegroundColor(cellColor.getIndex());
}

FillPatternType cellPattern = cell.getCellPattern();
if (cellColor != null && cellPattern == null) {
cellPattern = FillPatternType.SOLID_FOREGROUND;
}

if (cellPattern != null) {
if (style == null) {
style = wb.createCellStyle();
}
style.setFillPattern(cellPattern);
}

IndexedColors fontColor = cell.getFontColor();
if (fontColor != null) {
if (style == null) {
style = wb.createCellStyle();
}
if (font == null) {
font = wb.createFont();
}
font.setColor(fontColor.getIndex());
style.setFont(font);
}

// Maybe get a comment or null
Expand All @@ -135,8 +149,7 @@ public void addToWorkbook(Workbook wb, List<Column> columns, String split) {
// Add value to cell
xlsxCell.setCellValue(value);

// Add style to cell
style.setFont(font);
// Add style to cell, null is OK
xlsxCell.setCellStyle(style);

// Maybe add a comment
Expand Down
207 changes: 207 additions & 0 deletions robot-core/src/test/java/org/obolibrary/robot/ExportOperationTest.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
package org.obolibrary.robot;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.junit.Test;
import org.obolibrary.robot.export.Table;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.model.AxiomType;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLClass;
import org.semanticweb.owlapi.model.OWLEntity;
import org.semanticweb.owlapi.model.OWLObjectProperty;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyManager;
import org.semanticweb.owlapi.model.OWLSubClassOfAxiom;
import org.semanticweb.owlapi.model.parameters.Imports;
import org.semanticweb.owlapi.util.DefaultPrefixManager;

/**
* Tests ExportOperation.
Expand Down Expand Up @@ -53,4 +66,198 @@ public void testExportToXLSX() throws Exception {
v2 = r2.getCell(1).getStringCellValue();
assert (v2.equals("simple:test1"));
}

/**
* Test exporting to Excel with > 64,000 exported records.
*
* @throws Exception on any problem
*/
@Test
public void testLargeExcelExport() throws Exception {

// how many many axioms to create
int axiomCount = 64002;

IOHelper ioHelper = new IOHelper();
ioHelper.addPrefix(
"simple", "https://github.com/ontodev/robot/robot-core/src/test/resources/simple.owl#");

DefaultPrefixManager pfm = ioHelper.getPrefixManager();

OWLOntologyManager owlm = OWLManager.createOWLOntologyManager();
OWLOntology ontology = owlm.createOntology();

// add axiomCount subclass axioms to ontology
// first the super class
OWLClass superClass = CoreTest.dataFactory.getOWLClass("simple:super", pfm);

// then all the subs and axioms
for (int i = 0; i < axiomCount; i++) {
OWLClass subClass = CoreTest.dataFactory.getOWLClass("simple:sub_" + i, pfm);
OWLSubClassOfAxiom subAxiom =
CoreTest.dataFactory.getOWLSubClassOfAxiom(subClass, superClass);
owlm.addAxiom(ontology, subAxiom);
}

// export just the classes and their subclasses
List<String> columns = Arrays.asList("ID", "SubClass Of [ID]");
Map<String, String> options = ExportOperation.getDefaultOptions();
options.put("include", "classes");

// Create the table and render it as a Workbook
Table t = ExportOperation.createExportTable(ontology, ioHelper, columns, options);
Workbook wb = t.asWorkbook("|");

// get the first sheet
Sheet s = wb.getSheetAt(0);

// There should be same number of rows as subclass axioms + 1 for the header row
assert (s.getLastRowNum() == ontology.getAxiomCount(AxiomType.SUBCLASS_OF) + 1);
}

/**
* Test exporting all named headings using simple ontology.
*
* @throws Exception on any problem
*/
@Test
public void testExportNamedHeadingsSimple() throws Exception {
OWLOntology ontology = loadOntology("/simple.owl");
IOHelper ioHelper = new IOHelper();
ioHelper.addPrefix(
"simple", "https://github.com/ontodev/robot/robot-core/src/test/resources/simple.owl#");

// every named header
List<String> columns =
Arrays.asList(
"ID",
"LABEL",
"IRI",
"CURIE",
"Type",
"SYNONYMS",
"SUBCLASSES",
"SubClass Of",
"SubProperty Of",
"Equivalent Class",
"Equivalent Property",
"Disjoint With",
"Domain",
"Range");

// export everything
Map<String, String> options = ExportOperation.getDefaultOptions();
options.put("include", "classes individuals properties");

// Create the table and render it as a Workbook
Table t = ExportOperation.createExportTable(ontology, ioHelper, columns, options);
Workbook wb = t.asWorkbook("|");

Sheet s = wb.getSheetAt(0);
// There should be three rows (0, 1, 2)
assert (s.getLastRowNum() == 3);

// Validate header
// should match size and label
org.apache.poi.ss.usermodel.Row header = s.getRow(0);

short minColIx = header.getFirstCellNum();
short maxColIx = header.getLastCellNum();
int numCol = maxColIx - minColIx;
// same width
assert (numCol == columns.size());

// column header labels should match
for(short colIx=minColIx; colIx<maxColIx; colIx++) {
Cell cell = header.getCell(colIx);
if(cell == null) {
continue;
}
String foundHeader = cell.getStringCellValue();
String expectedHeader = columns.get(colIx);
assert (foundHeader.equals(expectedHeader));
}

}

/**
* Test exporting all named headings and object properties seen in the all-axioms ontology.
*
* @throws Exception on any problem
*/
@Test
public void testExportNamedHeadingsAllAxioms() throws Exception {
OWLOntology ontology = loadOntology("/axioms.owl");
Set<OWLEntity> signature = ontology.getSignature();
// remove datatypes
signature.removeAll(ontology.getDatatypesInSignature());
int entityCount = signature.size();

Set<OWLObjectProperty> properties = ontology.getObjectPropertiesInSignature(Imports.EXCLUDED);

IOHelper ioHelper = new IOHelper();
ioHelper.addPrefix(
"ax", "https://http://robot.obolibrary.org/export_test/");

// every named header
List<String> columns = new ArrayList<String>();

List<String> hdrLabels = Arrays.asList(
"ID",
"LABEL",
"Type",
"IRI",
"CURIE",
"SYNONYMS",
"SUBCLASSES",
"SubClass Of",
"SubProperty Of",
"Equivalent Class",
"Equivalent Property",
"Disjoint With",
"Domain",
"Range");

columns.addAll(hdrLabels);

//add all the object properties to the header
for(OWLObjectProperty op : properties) {
String shrt = ioHelper.getPrefixManager().getShortForm(op.getIRI());
columns.add(shrt);
}

// export everything
Map<String, String> options = ExportOperation.getDefaultOptions();
options.put("include", "classes individuals properties");

// Create the table and render it as a Workbook
Table t = ExportOperation.createExportTable(ontology, ioHelper, columns, options);
Workbook wb = t.asWorkbook("|");

Sheet s = wb.getSheetAt(0);
// There should be same number of rows as class,properties and instances in signature
assert (s.getLastRowNum() == entityCount);

// Validate header
// should match size and label
org.apache.poi.ss.usermodel.Row header = s.getRow(0);

short minColIx = header.getFirstCellNum();
short maxColIx = header.getLastCellNum();
int numCol = maxColIx - minColIx;
// should be same width
assert (numCol == columns.size());

// column header labels should match workbook
for(short colIx=minColIx; colIx<maxColIx; colIx++) {
Cell cell = header.getCell(colIx);
if(cell == null) {
continue;
}
String foundHeader = cell.getStringCellValue();
String expectedHeader = columns.get(colIx);
assert (foundHeader.equals(expectedHeader));
}

}
}
Loading