Skip to content

Commit 09162b6

Browse files
Merge pull request #1211 from ontodev/raw-iris-in-templates
Treat raw IRI as an OWLClass in logical template cells
2 parents 9d7bc48 + b82e88b commit 09162b6

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

robot-core/src/main/java/org/obolibrary/robot/TemplateHelper.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,16 @@ protected static OWLClassExpression tryParse(
991991
// If we have a checker, try to get the class by label
992992
// This allows class labels with single quotes
993993
expr = checker.getOWLClass(content, false);
994+
if (expr == null) {
995+
// If not found by label, is it just an HTTP IRI?
996+
if (content.startsWith("http")) {
997+
IRI iri = IRI.create(content);
998+
if (iri != null) {
999+
// If so, create a new class for this IRI.
1000+
expr = checker.getOWLClass(content, true);
1001+
}
1002+
}
1003+
}
9941004
}
9951005
if (expr == null) {
9961006
// If not found by label, try to parse

robot-core/src/test/java/org/obolibrary/robot/TemplateHelperTest.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ public void testGetClassExpressions() throws Exception {
128128
ManchesterOWLSyntaxClassExpressionParser parser =
129129
new ManchesterOWLSyntaxClassExpressionParser(dataFactory, checker);
130130

131+
// Check CURIE
131132
String template = "C part_of some %";
132133
String value = "obo:UBERON_0000467";
133134
Set<OWLClassExpression> expressions =
@@ -148,6 +149,32 @@ public void testGetClassExpressions() throws Exception {
148149
for (OWLClassExpression expr : expressions) {
149150
assertEquals(exprMatch.toString(), expr.toString());
150151
}
152+
153+
// Check raw HTTP IRI
154+
value = "http://purl.obolibrary.org/obo/UBERON_0000467";
155+
expressions = TemplateHelper.getClassExpressions("", parser, template, value, 0, 0);
156+
if (expressions.size() != 1) {
157+
fail(String.format("Expected exactly 1 expression, got %d", expressions.size()));
158+
}
159+
for (OWLClassExpression expr : expressions) {
160+
assertEquals(exprMatch.toString(), expr.toString());
161+
}
162+
163+
// Check that undeclared prefix fails
164+
try {
165+
value = "UNKNOWN:1234";
166+
expressions = TemplateHelper.getClassExpressions("", parser, template, value, 0, 0);
167+
fail("CURIE with undeclared prefix should not be parsed as Manchester expression");
168+
} catch (Exception e) {
169+
}
170+
171+
// Check that gibberish fails
172+
try {
173+
value = "http.purl.obolibrary.org/obo/UBERON_0000467";
174+
expressions = TemplateHelper.getClassExpressions("", parser, template, value, 0, 0);
175+
fail("Gibberish value should not be parsed as Manchester expression");
176+
} catch (Exception e) {
177+
}
151178
}
152179

153180
/**

0 commit comments

Comments
 (0)