afs commented on code in PR #1637:
URL: https://github.com/apache/jena/pull/1637#discussion_r1032766946
##########
jena-shex/src/main/java/org/apache/jena/shex/parser/javacc/ParseException.java:
##########
@@ -83,7 +78,7 @@ public ParseException(String message) {
/**
* This is the last token that has been consumed successfully. If
* this object has been created due to a parse error, the token
- * following this token will (therefore) be the first error token.
+ * followng this token will (therefore) be the first error token.
Review Comment:
typo - "following"
##########
jena-shex/src/main/java/org/apache/jena/shex/expressions/TripleExpression.java:
##########
@@ -18,16 +18,43 @@
package org.apache.jena.shex.expressions;
-public abstract class TripleExpression implements ShexPrintable {
+import org.apache.jena.graph.Triple;
+import org.apache.jena.shex.sys.ValidationContext;
+
+import java.util.List;
+import java.util.Set;
+
+public abstract class TripleExpression implements ShexPrintable {
// tripleExpr = EachOf | OneOf | TripleConstraint | tripleExprRef
//cardinality, semActs, annotation.
// [shex] annotations
// [shex] semanticActions
+ private List<SemAct> semActs;
+
+ protected TripleExpression(List<SemAct> semActs) {
+ this.semActs = semActs;
+ }
+
+ public List<SemAct> getSemActs() {
+ return semActs;
+ }
+
+ public void setSemActs(List<SemAct> semActs) { // needed for ShExC
parser's late binding of SemActs to EachOf
+ this.semActs = semActs;
+ }
- protected TripleExpression() {}
+// public void setSemActs(List<SemAct> semActs) {
+// this.semActs = semActs;
Review Comment:
Remove
##########
jena-shex/src/main/java/org/apache/jena/shex/eval/ShapeEvalEachOf.java:
##########
@@ -97,7 +97,7 @@ else if ( partitions.isEmpty() )
}
// This partition works.
if ( success )
- return true;
+ return eachOf.testSemanticActions(vCxt, matchables);
Review Comment:
Correct the comment on L99.
##########
jena-shex/src/main/java/org/apache/jena/shex/Plugin.java:
##########
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.shex;
+
+import org.apache.jena.shex.sys.SysShex;
+
+import java.util.List;
Review Comment:
Remove unused imports.
There are about 10 of them across the PR.
##########
jena-shex/src/main/java/org/apache/jena/shex/semact/TestSemanticActionPlugin.java:
##########
@@ -0,0 +1,120 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.shex.semact;
+
+import org.apache.jena.graph.Node;
+import org.apache.jena.graph.Triple;
+import org.apache.jena.shex.ShexSchema;
+import org.apache.jena.shex.expressions.SemAct;
+import org.apache.jena.shex.expressions.ShapeExpression;
+import org.apache.jena.shex.expressions.TripleExpression;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+interface ExtractVar {
+ String run (String str);
+}
+
+public class TestSemanticActionPlugin implements SemanticActionPlugin {
+ static String SemActIri = "http://shex.io/extensions/Test/";
+ static Pattern ParsePattern = Pattern.compile("^ *(fail|print)
*\\((\\\"(?:(?:[^\\\\\\\"]|\\\\[^\\\"])+)\\\"|[spo])\\) *$");
+ // tic Pattern ParsePattern = Pattern.compile("^ *(fail|print)
*\\((\\\"(?:(?:[^\\\\\\\"]|\\\\[^\\\"])+)\\\"|[spo])\\) *$");
Review Comment:
Remove unused
##########
jena-shex/src/main/java/org/apache/jena/shex/sys/ValidationContext.java:
##########
@@ -18,45 +18,93 @@
package org.apache.jena.shex.sys;
-import java.util.ArrayDeque;
-import java.util.Deque;
-import java.util.List;
+import java.util.*;
import org.apache.jena.atlas.lib.InternalErrorException;
import org.apache.jena.atlas.lib.Pair;
import org.apache.jena.graph.Graph;
import org.apache.jena.graph.Node;
+import org.apache.jena.graph.Triple;
import org.apache.jena.shex.*;
+import org.apache.jena.shex.expressions.ShapeExpression;
import org.apache.jena.shex.expressions.TripleExpression;
+import org.apache.jena.shex.semact.SemanticActionPlugin;
-/** Context for a validation and collector of the results. */
+/**
+ * Context for a validation and collector of the results.
+ */
public class ValidationContext {
private final ShexSchema shapes;
private final Graph data;
private boolean verbose = false;
private boolean seenReportEntry = false;
+ private ValidationContext parentCtx = null;
+ private Map<String, SemanticActionPlugin> semActPluginIndex;
// <data node, shape>
private Deque<Pair<Node, ShexShape>> inProgress = new ArrayDeque<>();
private final ShexReport.Builder reportBuilder = ShexReport.create();
+ @Deprecated
public static ValidationContext create(ValidationContext vCxt) {
// Fresh ShexReport.Builder
- return new ValidationContext(vCxt.data, vCxt.shapes, vCxt.inProgress);
+ return new ValidationContext(vCxt, vCxt.data, vCxt.shapes,
vCxt.inProgress, vCxt.semActPluginIndex);
+ }
+
+ /**
+ * Creates a new validation context with the current one as its parent
context.
+ * Initializes the new context with the state of the parent context.
+ *
+ * @return
Review Comment:
Remove or add the type because `@return` on its own is a javadoc warning.
##########
jena-shex/src/main/java/org/apache/jena/shex/sys/SysShex.java:
##########
@@ -36,13 +43,33 @@ public class SysShex {
// Node used for FOCUS in a shape map.
public static Node focusNode = NodeFactory.createExt("|focus|");
+ private static Map<String, SemanticActionPlugin> semActPluginIndex;
+
+ public static void registerSemActPlugin(String uri, SemanticActionPlugin
plugin) {
+ semActPluginIndex.put(uri, plugin);
+ }
+
// This is thread-safe.
- private static ShexValidator systemValiditor = new ShexValidatorImpl();
+ private static ShexValidator systemValiditor;
/** Set the current system-wide {@link ShexValidator}. */
public static void set(ShexValidator validator) { systemValiditor =
validator; }
public static ShexValidator get() {
return systemValiditor;
}
+
+ static {
+ semActPluginIndex = new ConcurrentHashMap<>();
+ systemValiditor = new ShexValidatorImpl(semActPluginIndex);
+ }
+
+ public static ShexValidator getNew(Collection<SemanticActionPlugin> pz) {
+ Map iriToPlugin = new ConcurrentHashMap();
Review Comment:
`Map` needs generics. `ConcurrentHashMap` needs `<>`
##########
jena-shex/src/main/java/org/apache/jena/shex/parser/ParserShExC.java:
##########
@@ -632,6 +641,48 @@ protected void numericFacetLength(String facetKind, int
length, int line, int co
addNodeConstraint(numLength);
}
+ protected SemAct crackSemanticAction(String iriAndCode, int line, int
column) {
+ // e.g. % <http://shex.io/extensions/Test/> { print(s) %}
+ // or % ex:Test { print(s) %}
+ // or %<http://shex.io/extensions/Test/>%
+
+ // Trim leading '%' and ws and trim trailing '%}'
+ String whitespaces = " \t\n\r\f";
+ int startOfIri = 1; // get past '%'
+ for (; whitespaces.indexOf(iriAndCode.charAt(startOfIri)) != -1;
++startOfIri)
Review Comment:
It adds clarity.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]