From 47dd0a7edae6cf06f89e8eb5662540e5648c3e23 Mon Sep 17 00:00:00 2001 From: Jeremy Debattista Date: Sun, 26 May 2024 12:22:52 +0200 Subject: [PATCH 1/5] Pushed Jena version to 5.0.0 --- pom.xml | 2 +- .../org/topbraid/jenax/functions/AbstractFunction.java | 5 ++--- src/main/java/org/topbraid/jenax/util/JenaUtil.java | 7 ++++--- src/main/java/org/topbraid/jenax/util/JenaUtilHelper.java | 4 ++-- src/main/java/org/topbraid/shacl/arq/SHACLARQFunction.java | 1 - .../shacl/arq/functions/SHACLSPARQLARQFunction.java | 6 +++++- 6 files changed, 14 insertions(+), 11 deletions(-) diff --git a/pom.xml b/pom.xml index 98dc9ff6..6f3712e2 100644 --- a/pom.xml +++ b/pom.xml @@ -68,7 +68,7 @@ UTF-8 - 4.10.0 + 5.0.0 4.13.2 1.7.36 2.20.0 diff --git a/src/main/java/org/topbraid/jenax/functions/AbstractFunction.java b/src/main/java/org/topbraid/jenax/functions/AbstractFunction.java index c1a51cb5..432fef06 100644 --- a/src/main/java/org/topbraid/jenax/functions/AbstractFunction.java +++ b/src/main/java/org/topbraid/jenax/functions/AbstractFunction.java @@ -31,6 +31,7 @@ import org.apache.jena.sparql.function.Function; import org.apache.jena.sparql.function.FunctionEnv; import org.apache.jena.sparql.sse.SSE; +import org.apache.jena.sparql.util.Context; import org.apache.jena.sparql.util.FmtUtils; import org.topbraid.jenax.statistics.ExecStatistics; import org.topbraid.jenax.statistics.ExecStatisticsManager; @@ -44,9 +45,7 @@ public abstract class AbstractFunction implements Function { @Override - public void build(String uri, ExprList args) { - } - + public void build(String var1, ExprList var2, Context var3){} @Override public NodeValue exec(Binding binding, ExprList args, String uri, FunctionEnv env) { diff --git a/src/main/java/org/topbraid/jenax/util/JenaUtil.java b/src/main/java/org/topbraid/jenax/util/JenaUtil.java index b092f064..d380c99b 100644 --- a/src/main/java/org/topbraid/jenax/util/JenaUtil.java +++ b/src/main/java/org/topbraid/jenax/util/JenaUtil.java @@ -29,7 +29,6 @@ import java.util.function.BiFunction; import org.apache.jena.enhanced.EnhGraph; -import org.apache.jena.graph.Factory; import org.apache.jena.graph.Graph; import org.apache.jena.graph.Node; import org.apache.jena.graph.compose.MultiUnion; @@ -72,12 +71,14 @@ import org.apache.jena.sparql.expr.NodeValue; import org.apache.jena.sparql.expr.nodevalue.NodeFunctions; import org.apache.jena.sparql.function.FunctionEnv; +import org.apache.jena.sparql.graph.GraphFactory; import org.apache.jena.sparql.graph.NodeTransform; import org.apache.jena.sparql.syntax.syntaxtransform.ElementTransform; import org.apache.jena.sparql.syntax.syntaxtransform.ElementTransformSubst; import org.apache.jena.sparql.syntax.syntaxtransform.ExprTransformNodeElement; import org.apache.jena.sparql.syntax.syntaxtransform.QueryTransformOps; import org.apache.jena.sparql.util.Context; +import org.apache.jena.sparql.util.NodeCmp; import org.apache.jena.sparql.util.NodeFactoryExtra; import org.apache.jena.sparql.util.NodeUtils; import org.apache.jena.util.iterator.ExtendedIterator; @@ -317,7 +318,7 @@ public static Model createDefaultModel() { * @return a new memory graph */ public static Graph createMemoryGraph() { - return Factory.createDefaultGraph(); + return GraphFactory.createDefaultGraph(); } @@ -1240,7 +1241,7 @@ public static void sort(List nodes) { Collections.sort(nodes, new Comparator() { @Override public int compare(Resource o1, Resource o2) { - return NodeUtils.compareRDFTerms(o1.asNode(), o2.asNode()); + return NodeCmp.compareRDFTerms(o1.asNode(), o2.asNode()); } }); } diff --git a/src/main/java/org/topbraid/jenax/util/JenaUtilHelper.java b/src/main/java/org/topbraid/jenax/util/JenaUtilHelper.java index 801a8e92..472aad57 100644 --- a/src/main/java/org/topbraid/jenax/util/JenaUtilHelper.java +++ b/src/main/java/org/topbraid/jenax/util/JenaUtilHelper.java @@ -18,7 +18,6 @@ import java.util.Iterator; -import org.apache.jena.graph.Factory; import org.apache.jena.graph.Graph; import org.apache.jena.graph.compose.MultiUnion; import org.apache.jena.mem.GraphMemBase; @@ -26,6 +25,7 @@ import org.apache.jena.ontology.OntModelSpec; import org.apache.jena.rdf.model.Model; import org.apache.jena.rdf.model.ModelFactory; +import org.apache.jena.sparql.graph.GraphFactory; /** * This is an extension point for the SPIN library @@ -72,7 +72,7 @@ public MultiUnion createMultiUnion(Graph[] graphs) { * @return the default Graph */ public Graph createDefaultGraph() { - return Factory.createDefaultGraph(); + return GraphFactory.createDefaultGraph(); } diff --git a/src/main/java/org/topbraid/shacl/arq/SHACLARQFunction.java b/src/main/java/org/topbraid/shacl/arq/SHACLARQFunction.java index 4be99e60..733bd7da 100644 --- a/src/main/java/org/topbraid/shacl/arq/SHACLARQFunction.java +++ b/src/main/java/org/topbraid/shacl/arq/SHACLARQFunction.java @@ -103,7 +103,6 @@ protected void addParameters(SHParameterizable parameterizable) { } - @Override public void build(String uri, ExprList args) { } diff --git a/src/main/java/org/topbraid/shacl/arq/functions/SHACLSPARQLARQFunction.java b/src/main/java/org/topbraid/shacl/arq/functions/SHACLSPARQLARQFunction.java index cb076778..943fb2e6 100644 --- a/src/main/java/org/topbraid/shacl/arq/functions/SHACLSPARQLARQFunction.java +++ b/src/main/java/org/topbraid/shacl/arq/functions/SHACLSPARQLARQFunction.java @@ -29,6 +29,7 @@ import org.apache.jena.sparql.expr.ExprEvalException; import org.apache.jena.sparql.expr.ExprList; import org.apache.jena.sparql.expr.NodeValue; +import org.apache.jena.sparql.util.Context; import org.topbraid.jenax.util.ARQFactory; import org.topbraid.jenax.util.DatasetWithDifferentDefaultModel; import org.topbraid.jenax.util.JenaUtil; @@ -54,7 +55,10 @@ public class SHACLSPARQLARQFunction extends SHACLARQFunction { private org.apache.jena.query.Query arqQuery; private String queryString; - + + @Override + public void build(String var1, ExprList var2, Context var3) { + } /** * Constructs a new SHACLSPARQLARQFunction based on a given sh:ConstraintComponent From 18c221383c5a2544b366a7b9386f8dc94a98bdf4 Mon Sep 17 00:00:00 2001 From: Jeremy Debattista Date: Sun, 26 May 2024 12:25:29 +0200 Subject: [PATCH 2/5] Used benmanes caffeine for failing Cache and CacheBuilder classes and methods --- .../jenax/functions/AbstractFunction.java | 2 +- .../shacl/optimize/OntologyOptimizations.java | 47 +++++++++---------- .../org/topbraid/shacl/util/SHACLUtil.java | 7 +-- 3 files changed, 26 insertions(+), 30 deletions(-) diff --git a/src/main/java/org/topbraid/jenax/functions/AbstractFunction.java b/src/main/java/org/topbraid/jenax/functions/AbstractFunction.java index 432fef06..4c86259d 100644 --- a/src/main/java/org/topbraid/jenax/functions/AbstractFunction.java +++ b/src/main/java/org/topbraid/jenax/functions/AbstractFunction.java @@ -46,7 +46,7 @@ public abstract class AbstractFunction implements Function { @Override public void build(String var1, ExprList var2, Context var3){} - + @Override public NodeValue exec(Binding binding, ExprList args, String uri, FunctionEnv env) { Node[] nodes = new Node[args.size()]; diff --git a/src/main/java/org/topbraid/shacl/optimize/OntologyOptimizations.java b/src/main/java/org/topbraid/shacl/optimize/OntologyOptimizations.java index a1a92e00..8a22c5a9 100644 --- a/src/main/java/org/topbraid/shacl/optimize/OntologyOptimizations.java +++ b/src/main/java/org/topbraid/shacl/optimize/OntologyOptimizations.java @@ -16,23 +16,22 @@ */ package org.topbraid.shacl.optimize; -import com.github.jsonldjava.shaded.com.google.common.cache.Cache; -import com.github.jsonldjava.shaded.com.google.common.cache.CacheBuilder; +import com.github.benmanes.caffeine.cache.Caffeine; +import com.github.benmanes.caffeine.cache.Cache; + import java.util.ArrayList; import java.util.List; -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutionException; import java.util.function.Function; import org.apache.jena.graph.Graph; import org.apache.jena.graph.Node; import org.apache.jena.rdf.model.Model; import org.topbraid.jenax.util.ARQFactory; -import org.topbraid.jenax.util.ExceptionUtil; import org.topbraid.jenax.util.JenaUtil; import org.topbraid.shacl.engine.ShapesGraph; import org.topbraid.shacl.engine.ShapesGraphFactory; + /** * A singleton managing Ontology-based optimizations, to be used (for example) with OptimizedMultiUnions. * The contract is that such optimization Objects need to register themselves so that they can @@ -79,19 +78,25 @@ public String getKeyIfEnabledFor(Graph graph) { } private static final int capacity = 10000; - - private Cache cache = CacheBuilder. - newBuilder(). - maximumSize(capacity). - build(); - - + + private Cache cache = Caffeine + .newBuilder() + .maximumSize(capacity) + .build(); + + public ClassMetadata getClassMetadata(Node cls, Graph graph, String graphKey) { Object cacheKey = ClassMetadata.createKey(cls, graphKey); - return (ClassMetadata) getOrComputeObject(cacheKey, () -> new ClassMetadata(cls, graphKey)); + + ClassMetadata cachedMetadata = (ClassMetadata) getOrComputeObject(cacheKey, (key) -> { + return new ClassMetadata((Node) key, graphKey); + }); + + return cachedMetadata; } - - + + + public Object getObject(Object key) { return cache.getIfPresent(key); } @@ -99,17 +104,7 @@ public Object getObject(Object key) { // Legacy version with Function parameter public Object getOrComputeObject(Object key, Function function) { - return getOrComputeObject(key, () -> function.apply(key)); - } - - - public Object getOrComputeObject(Object key, Callable callable) { - try { - return cache.get(key, callable); - } catch (ExecutionException ex) { - log.error("Failed to populate OntologyOptimizations with key " + key, ex); - throw ExceptionUtil.throwUnchecked(ex); - } + return cache.get(key, function); } public ShapesGraph getCachableShapesGraph(String uri) { diff --git a/src/main/java/org/topbraid/shacl/util/SHACLUtil.java b/src/main/java/org/topbraid/shacl/util/SHACLUtil.java index f1a46505..7c76945a 100644 --- a/src/main/java/org/topbraid/shacl/util/SHACLUtil.java +++ b/src/main/java/org/topbraid/shacl/util/SHACLUtil.java @@ -503,7 +503,7 @@ public static List getAllShapesAtClassOrShape(Resource clsOrShape) String key = OntologyOptimizations.get().getKeyIfEnabledFor(clsOrShape.getModel().getGraph()); if(key != null) { key += ".getAllShapesAtClassOrShape(" + clsOrShape + ")"; - return (List) OntologyOptimizations.get().getOrComputeObject(key, () -> { + return (List) OntologyOptimizations.get().getOrComputeObject(key, (cacheKey) -> { List results = new LinkedList(); addAllShapesAtClassOrShape(clsOrShape, results, new HashSet()); return results; @@ -515,8 +515,9 @@ public static List getAllShapesAtClassOrShape(Resource clsOrShape) return results; } } - - + + + private static void addAllShapesAtClassOrShape(Resource clsOrShape, List results, Set reached) { addDirectShapesAtClassOrShape(clsOrShape, results); reached.add(clsOrShape); From 8d30d053155d3f3718db9228cf3d37a8f51cc536 Mon Sep 17 00:00:00 2001 From: Jeremy Debattista Date: Mon, 27 May 2024 10:48:15 +0200 Subject: [PATCH 3/5] Resolved comments from andy --- src/main/java/org/topbraid/jenax/util/JenaUtil.java | 4 ++-- src/main/java/org/topbraid/shacl/arq/SHACLARQFunction.java | 5 ----- .../topbraid/shacl/arq/functions/SHACLSPARQLARQFunction.java | 5 ----- 3 files changed, 2 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/topbraid/jenax/util/JenaUtil.java b/src/main/java/org/topbraid/jenax/util/JenaUtil.java index d380c99b..2c85e7fd 100644 --- a/src/main/java/org/topbraid/jenax/util/JenaUtil.java +++ b/src/main/java/org/topbraid/jenax/util/JenaUtil.java @@ -30,6 +30,7 @@ import org.apache.jena.enhanced.EnhGraph; import org.apache.jena.graph.Graph; +import org.apache.jena.graph.GraphMemFactory; import org.apache.jena.graph.Node; import org.apache.jena.graph.compose.MultiUnion; import org.apache.jena.ontology.OntModel; @@ -71,7 +72,6 @@ import org.apache.jena.sparql.expr.NodeValue; import org.apache.jena.sparql.expr.nodevalue.NodeFunctions; import org.apache.jena.sparql.function.FunctionEnv; -import org.apache.jena.sparql.graph.GraphFactory; import org.apache.jena.sparql.graph.NodeTransform; import org.apache.jena.sparql.syntax.syntaxtransform.ElementTransform; import org.apache.jena.sparql.syntax.syntaxtransform.ElementTransformSubst; @@ -318,7 +318,7 @@ public static Model createDefaultModel() { * @return a new memory graph */ public static Graph createMemoryGraph() { - return GraphFactory.createDefaultGraph(); + return GraphMemFactory.createDefaultGraph(); } diff --git a/src/main/java/org/topbraid/shacl/arq/SHACLARQFunction.java b/src/main/java/org/topbraid/shacl/arq/SHACLARQFunction.java index 733bd7da..a751ff58 100644 --- a/src/main/java/org/topbraid/shacl/arq/SHACLARQFunction.java +++ b/src/main/java/org/topbraid/shacl/arq/SHACLARQFunction.java @@ -102,11 +102,6 @@ protected void addParameters(SHParameterizable parameterizable) { } } - - public void build(String uri, ExprList args) { - } - - @Override public org.apache.jena.sparql.function.Function create(String uri) { return this; diff --git a/src/main/java/org/topbraid/shacl/arq/functions/SHACLSPARQLARQFunction.java b/src/main/java/org/topbraid/shacl/arq/functions/SHACLSPARQLARQFunction.java index 943fb2e6..5201e444 100644 --- a/src/main/java/org/topbraid/shacl/arq/functions/SHACLSPARQLARQFunction.java +++ b/src/main/java/org/topbraid/shacl/arq/functions/SHACLSPARQLARQFunction.java @@ -110,11 +110,6 @@ public SHACLSPARQLARQFunction(SHSPARQLFunction shaclFunction) { addParameters(shaclFunction); } - - - @Override - public void build(String uri, ExprList args) { - } @Override From 168da3e1d6909285a19ffbc061b8042856687bfd Mon Sep 17 00:00:00 2001 From: Jeremy Debattista <143829654+jerdebsp@users.noreply.github.com> Date: Thu, 12 Dec 2024 12:07:23 +0100 Subject: [PATCH 4/5] Update java version --- .github/workflows/maven-test-pr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/maven-test-pr.yml b/.github/workflows/maven-test-pr.yml index c2d826f6..7484b415 100644 --- a/.github/workflows/maven-test-pr.yml +++ b/.github/workflows/maven-test-pr.yml @@ -12,7 +12,7 @@ jobs: - name: Set up JDK uses: actions/setup-java@8df1039502a15bceb9433410b1a100fbe190c53b # v4.5.0 with: - java-version: "11" + java-version: "17" distribution: "temurin" - name: Test with Maven From 03a4bf217c323842c6047f3bd8525165d74acb40 Mon Sep 17 00:00:00 2001 From: Jeremy Debattista <143829654+jerdebsp@users.noreply.github.com> Date: Thu, 12 Dec 2024 12:08:28 +0100 Subject: [PATCH 5/5] Update java to 17 --- .github/workflows/docker-image.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 8665a113..4a56c718 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -25,10 +25,10 @@ jobs: include: - package: "x86_64" platform: linux/amd64 - base: eclipse-temurin:11-alpine + base: eclipse-temurin:17-alpine - package: "arm64" platform: linux/arm64 - base: amazoncorretto:11-alpine3.18-jdk + base: amazoncorretto:17-alpine3.18-jdk steps: - name: lowercase image name