Skip to content

Commit

Permalink
Merge pull request #1211 from ontodev/raw-iris-in-templates
Browse files Browse the repository at this point in the history
Treat raw IRI as an OWLClass in logical template cells
  • Loading branch information
jamesaoverton authored Oct 29, 2024
2 parents 9d7bc48 + b82e88b commit 09162b6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
10 changes: 10 additions & 0 deletions robot-core/src/main/java/org/obolibrary/robot/TemplateHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,16 @@ protected static OWLClassExpression tryParse(
// If we have a checker, try to get the class by label
// This allows class labels with single quotes
expr = checker.getOWLClass(content, false);
if (expr == null) {
// If not found by label, is it just an HTTP IRI?
if (content.startsWith("http")) {
IRI iri = IRI.create(content);
if (iri != null) {
// If so, create a new class for this IRI.
expr = checker.getOWLClass(content, true);
}
}
}
}
if (expr == null) {
// If not found by label, try to parse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public void testGetClassExpressions() throws Exception {
ManchesterOWLSyntaxClassExpressionParser parser =
new ManchesterOWLSyntaxClassExpressionParser(dataFactory, checker);

// Check CURIE
String template = "C part_of some %";
String value = "obo:UBERON_0000467";
Set<OWLClassExpression> expressions =
Expand All @@ -148,6 +149,32 @@ public void testGetClassExpressions() throws Exception {
for (OWLClassExpression expr : expressions) {
assertEquals(exprMatch.toString(), expr.toString());
}

// Check raw HTTP IRI
value = "http://purl.obolibrary.org/obo/UBERON_0000467";
expressions = TemplateHelper.getClassExpressions("", parser, template, value, 0, 0);
if (expressions.size() != 1) {
fail(String.format("Expected exactly 1 expression, got %d", expressions.size()));
}
for (OWLClassExpression expr : expressions) {
assertEquals(exprMatch.toString(), expr.toString());
}

// Check that undeclared prefix fails
try {
value = "UNKNOWN:1234";
expressions = TemplateHelper.getClassExpressions("", parser, template, value, 0, 0);
fail("CURIE with undeclared prefix should not be parsed as Manchester expression");
} catch (Exception e) {
}

// Check that gibberish fails
try {
value = "http.purl.obolibrary.org/obo/UBERON_0000467";
expressions = TemplateHelper.getClassExpressions("", parser, template, value, 0, 0);
fail("Gibberish value should not be parsed as Manchester expression");
} catch (Exception e) {
}
}

/**
Expand Down

0 comments on commit 09162b6

Please sign in to comment.