From df0c429e8ae0c37d24fb937854fc1bbb10fa68cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20R=C3=B6der?= Date: Fri, 8 Nov 2024 13:24:41 +0100 Subject: [PATCH] Fixed a bug in the tokenizer that limited the parser's ability to parse exists statements that are followed by a negated class. --- .../cel/expression/parse/CEParser.java | 10 ++++++++++ .../cel/expression/parse/Tokenizer.java | 1 + .../cel/expression/parse/CEParserTest.java | 14 ++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/src/main/java/org/dice_research/cel/expression/parse/CEParser.java b/src/main/java/org/dice_research/cel/expression/parse/CEParser.java index cd4ae24..e8556e3 100644 --- a/src/main/java/org/dice_research/cel/expression/parse/CEParser.java +++ b/src/main/java/org/dice_research/cel/expression/parse/CEParser.java @@ -10,6 +10,16 @@ import org.dice_research.cel.expression.NamedClass; import org.dice_research.cel.expression.SimpleQuantifiedRole; +/** + * + * WARNING: This parser cannot parse {@code ∃r.A} correctly since the + * tokenizer has no chance to identify the dot as separator of the names (which + * could also be IRIs). Hence, it will be parser as a single role name + * {@code r.A}. + * + * @author Michael Röder (michael.roeder@uni-paderborn.de) + * + */ public class CEParser { public ClassExpression parse(String expressionString) throws CEParserException { diff --git a/src/main/java/org/dice_research/cel/expression/parse/Tokenizer.java b/src/main/java/org/dice_research/cel/expression/parse/Tokenizer.java index 1bc49f6..15a1777 100644 --- a/src/main/java/org/dice_research/cel/expression/parse/Tokenizer.java +++ b/src/main/java/org/dice_research/cel/expression/parse/Tokenizer.java @@ -79,6 +79,7 @@ protected boolean newStmtFollows(String substring) { switch (substring.charAt(0)) { case '(': // falls through case ')': + case '¬': case '∃': case '∀': case '⊔': diff --git a/src/test/java/org/dice_research/cel/expression/parse/CEParserTest.java b/src/test/java/org/dice_research/cel/expression/parse/CEParserTest.java index 20d401b..fa245e8 100644 --- a/src/test/java/org/dice_research/cel/expression/parse/CEParserTest.java +++ b/src/test/java/org/dice_research/cel/expression/parse/CEParserTest.java @@ -34,6 +34,20 @@ public static List parameters() { testCases.add(new Object[] { new SimpleQuantifiedRole(true, "http://example.org/r", false, NamedClass.TOP) }); testCases.add(new Object[] { new SimpleQuantifiedRole(true, "http://example.org/r", true, NamedClass.TOP) }); + // Exists r A + testCases.add(new Object[] { new SimpleQuantifiedRole(true, "r", false, new NamedClass("http://example.org/A", true)) }); + testCases.add(new Object[] { new SimpleQuantifiedRole(true, "r", true, new NamedClass("http://example.org/A", true)) }); + testCases.add(new Object[] { + new SimpleQuantifiedRole(true, "http://example.org/r", false, new NamedClass("http://example.org/A", true)) }); + testCases.add(new Object[] { + new SimpleQuantifiedRole(true, "http://example.org/r", true, new NamedClass("http://example.org/A", true)) }); + testCases.add(new Object[] { new SimpleQuantifiedRole(true, "r", false, new NamedClass("http://example.org/A", false)) }); + testCases.add(new Object[] { new SimpleQuantifiedRole(true, "r", true, new NamedClass("http://example.org/A", false)) }); + testCases.add(new Object[] { + new SimpleQuantifiedRole(true, "http://example.org/r", false, new NamedClass("http://example.org/A", false)) }); + testCases.add(new Object[] { + new SimpleQuantifiedRole(true, "http://example.org/r", true, new NamedClass("http://example.org/A", false)) }); + // Forall r BOTTOM testCases.add(new Object[] { new SimpleQuantifiedRole(false, "r", false, NamedClass.BOTTOM) }); testCases.add(new Object[] { new SimpleQuantifiedRole(false, "r", true, NamedClass.BOTTOM) });