Skip to content

Commit

Permalink
Rename addLabels() to addEntities()
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesaoverton committed Nov 29, 2023
1 parent 0de578c commit 54139f8
Showing 1 changed file with 86 additions and 81 deletions.
167 changes: 86 additions & 81 deletions robot-core/src/main/java/org/obolibrary/robot/Template.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public Template(@Nonnull String name, @Nonnull List<List<String>> rows) throws E

// Add the contents of the tableRows
addTable(rows);
addLabels();
addEntities();
createParser();
}

Expand Down Expand Up @@ -203,7 +203,7 @@ public Template(@Nonnull String name, @Nonnull List<List<String>> rows, IOHelper

// Add the contents of the tableRows
addTable(rows);
addLabels();
addEntities();
createParser();
}

Expand Down Expand Up @@ -237,7 +237,7 @@ public Template(@Nonnull String name, @Nonnull List<List<String>> rows, OWLOntol

// Add the contents of the tableRows
addTable(rows);
addLabels();
addEntities();
createParser();
}

Expand Down Expand Up @@ -276,7 +276,7 @@ public Template(

// Add the contents of the tableRows
addTable(rows);
addLabels();
addEntities();
createParser();
}

Expand Down Expand Up @@ -320,7 +320,7 @@ public Template(

// Add the contents of the tableRows
addTable(rows);
addLabels();
addEntities();
createParser();
parser.setOWLEntityChecker(this.checker);
}
Expand Down Expand Up @@ -557,99 +557,104 @@ private void addTable(List<List<String>> 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<String> 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<String> 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);
}
}

Expand Down

0 comments on commit 54139f8

Please sign in to comment.