diff --git a/robot-core/src/main/java/org/obolibrary/robot/TemplateHelper.java b/robot-core/src/main/java/org/obolibrary/robot/TemplateHelper.java index 1127a576f..1c5e8efa2 100644 --- a/robot-core/src/main/java/org/obolibrary/robot/TemplateHelper.java +++ b/robot-core/src/main/java/org/obolibrary/robot/TemplateHelper.java @@ -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 diff --git a/robot-core/src/test/java/org/obolibrary/robot/TemplateHelperTest.java b/robot-core/src/test/java/org/obolibrary/robot/TemplateHelperTest.java index da68ce884..5d97f63af 100644 --- a/robot-core/src/test/java/org/obolibrary/robot/TemplateHelperTest.java +++ b/robot-core/src/test/java/org/obolibrary/robot/TemplateHelperTest.java @@ -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 expressions = @@ -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) { + } } /**