diff --git a/robot-core/src/main/java/org/obolibrary/robot/Template.java b/robot-core/src/main/java/org/obolibrary/robot/Template.java index 21aeb8d51..d95ec8135 100644 --- a/robot-core/src/main/java/org/obolibrary/robot/Template.java +++ b/robot-core/src/main/java/org/obolibrary/robot/Template.java @@ -173,7 +173,7 @@ public Template(@Nonnull String name, @Nonnull List> rows) throws E // Add the contents of the tableRows addTable(rows); - addLabels(); + addEntities(); createParser(); } @@ -203,7 +203,7 @@ public Template(@Nonnull String name, @Nonnull List> rows, IOHelper // Add the contents of the tableRows addTable(rows); - addLabels(); + addEntities(); createParser(); } @@ -237,7 +237,7 @@ public Template(@Nonnull String name, @Nonnull List> rows, OWLOntol // Add the contents of the tableRows addTable(rows); - addLabels(); + addEntities(); createParser(); } @@ -276,7 +276,7 @@ public Template( // Add the contents of the tableRows addTable(rows); - addLabels(); + addEntities(); createParser(); } @@ -320,7 +320,7 @@ public Template( // Add the contents of the tableRows addTable(rows); - addLabels(); + addEntities(); createParser(); parser.setOWLEntityChecker(this.checker); } @@ -557,99 +557,104 @@ private void addTable(List> rows) throws Exception { } } - /** Add the labels from the rows of the template to the QuotedEntityChecker. */ - private void addLabels() { + /** Add the entities from the rows of the template to the QuotedEntityChecker. */ + private void addEntities() { for (List row : tableRows) { - String id = null; - try { - id = row.get(idColumn); - } catch (IndexOutOfBoundsException e) { - // ignore - } + addEntity(row); + } + } - if (id == null) { - continue; - } + /** Add the entity from this row of the template to the QuotedEntityChecker. */ + private void addEntity(List row) { + String id = null; + try { + id = row.get(idColumn); + } catch (IndexOutOfBoundsException e) { + // ignore + } + + if (id == null) { + return; + } + + String label = null; + try { + label = row.get(labelColumn); + } catch (IndexOutOfBoundsException e) { + // ignore + } - String label = null; + String type = null; + if (typeColumn != -1) { try { - label = row.get(labelColumn); + type = row.get(typeColumn); } catch (IndexOutOfBoundsException e) { // ignore } + } + if (type == null || type.trim().isEmpty()) { + type = "class"; + } - String type = null; - if (typeColumn != -1) { - try { - type = row.get(typeColumn); - } catch (IndexOutOfBoundsException e) { - // ignore - } - } - if (type == null || type.trim().isEmpty()) { - type = "class"; - } - - IRI iri = ioHelper.createIRI(id); - if (iri == null) { - iri = IRI.create(id); - } + IRI iri = ioHelper.createIRI(id); + if (iri == null) { + iri = IRI.create(id); + } - // Try to resolve a CURIE - IRI typeIRI = ioHelper.createIRI(type); + // Try to resolve a CURIE + IRI typeIRI = ioHelper.createIRI(type); - // Set to IRI string or to type string - String typeOrIRI = type; - if (typeIRI != null) { - typeOrIRI = typeIRI.toString(); - } + // Set to IRI string or to type string + String typeOrIRI = type; + if (typeIRI != null) { + typeOrIRI = typeIRI.toString(); + } - // Check against builtin types (ignore case), otherwise treat as individual - OWLEntity entity; - String lowerCaseType = typeOrIRI.toLowerCase(); - switch (lowerCaseType) { - case "": - case "http://www.w3.org/2002/07/owl#class": - case "class": - entity = dataFactory.getOWLEntity(EntityType.CLASS, iri); - break; + // Check against builtin types (ignore case), otherwise treat as individual + OWLEntity entity; + String lowerCaseType = typeOrIRI.toLowerCase(); + switch (lowerCaseType) { + case "": + case "http://www.w3.org/2002/07/owl#class": + case "class": + entity = dataFactory.getOWLEntity(EntityType.CLASS, iri); + break; - case "http://www.w3.org/2002/07/owl#objectproperty": - case "object property": - entity = dataFactory.getOWLEntity(EntityType.OBJECT_PROPERTY, iri); - break; + case "http://www.w3.org/2002/07/owl#objectproperty": + case "object property": + entity = dataFactory.getOWLEntity(EntityType.OBJECT_PROPERTY, iri); + break; - case "http://www.w3.org/2002/07/owl#dataproperty": - case "data property": - entity = dataFactory.getOWLEntity(EntityType.DATA_PROPERTY, iri); - break; + case "http://www.w3.org/2002/07/owl#dataproperty": + case "data property": + entity = dataFactory.getOWLEntity(EntityType.DATA_PROPERTY, iri); + break; - case "http://www.w3.org/2002/07/owl#annotationproperty": - case "annotation property": - entity = dataFactory.getOWLEntity(EntityType.ANNOTATION_PROPERTY, iri); - break; + case "http://www.w3.org/2002/07/owl#annotationproperty": + case "annotation property": + entity = dataFactory.getOWLEntity(EntityType.ANNOTATION_PROPERTY, iri); + break; - case "http://www.w3.org/2002/07/owl#datatype": - case "datatype": - entity = dataFactory.getOWLEntity(EntityType.DATATYPE, iri); - break; + case "http://www.w3.org/2002/07/owl#datatype": + case "datatype": + entity = dataFactory.getOWLEntity(EntityType.DATATYPE, iri); + break; - case "http://www.w3.org/2002/07/owl#individual": - case "individual": - case "http://www.w3.org/2002/07/owl#namedindividual": - case "named individual": - default: - // Assume type is an individual (checked later) - entity = dataFactory.getOWLEntity(EntityType.NAMED_INDIVIDUAL, iri); - break; - } + case "http://www.w3.org/2002/07/owl#individual": + case "individual": + case "http://www.w3.org/2002/07/owl#namedindividual": + case "named individual": + default: + // Assume type is an individual (checked later) + entity = dataFactory.getOWLEntity(EntityType.NAMED_INDIVIDUAL, iri); + break; + } - if (id != null) { - checker.add(entity, id); - } - if (label != null) { - checker.add(entity, label); - } + if (id != null) { + checker.add(entity, id); + } + if (label != null) { + checker.add(entity, label); } }