Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pushed Jena version to 5.0.0 and updated Caching library #177

Merged
merged 6 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/maven-test-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<ver.jena>4.10.0</ver.jena>
<ver.jena>5.0.0</ver.jena>
<ver.junit>4.13.2</ver.junit>
<ver.slf4j>1.7.36</ver.slf4j>
<ver.log4j2>2.20.0</ver.log4j2>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -44,10 +45,8 @@
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) {
Node[] nodes = new Node[args.size()];
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/org/topbraid/jenax/util/JenaUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
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.GraphMemFactory;
import org.apache.jena.graph.Node;
import org.apache.jena.graph.compose.MultiUnion;
import org.apache.jena.ontology.OntModel;
Expand Down Expand Up @@ -78,6 +78,7 @@
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;
Expand Down Expand Up @@ -317,7 +318,7 @@ public static Model createDefaultModel() {
* @return a new memory graph
*/
public static Graph createMemoryGraph() {
return Factory.createDefaultGraph();
return GraphMemFactory.createDefaultGraph();
}


Expand Down Expand Up @@ -1240,7 +1241,7 @@ public static void sort(List<Resource> nodes) {
Collections.sort(nodes, new Comparator<Resource>() {
@Override
public int compare(Resource o1, Resource o2) {
return NodeUtils.compareRDFTerms(o1.asNode(), o2.asNode());
return NodeCmp.compareRDFTerms(o1.asNode(), o2.asNode());
}
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/topbraid/jenax/util/JenaUtilHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@

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;
import org.apache.jena.ontology.OntModel;
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
Expand Down Expand Up @@ -72,7 +72,7 @@ public MultiUnion createMultiUnion(Graph[] graphs) {
* @return the default Graph
*/
public Graph createDefaultGraph() {
return Factory.createDefaultGraph();
return GraphFactory.createDefaultGraph();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: Should this be a call to `JenaUtil.createDefaultGraph()?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason JenaUtil.createDefaultGraph() is calling the helper class, causing a stack overflow cycle

This is what there is in JenaUtil.
public static Graph createDefaultGraph() { return helper.createDefaultGraph(); }
Maybe this needs to be changed?

}


Expand Down
6 changes: 0 additions & 6 deletions src/main/java/org/topbraid/shacl/arq/SHACLARQFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,6 @@ protected void addParameters(SHParameterizable parameterizable) {
}
}


@Override
public void build(String uri, ExprList args) {
}


@Override
public org.apache.jena.sparql.function.Function create(String uri) {
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -106,11 +110,6 @@ public SHACLSPARQLARQFunction(SHSPARQLFunction shaclFunction) {

addParameters(shaclFunction);
}


@Override
public void build(String uri, ExprList args) {
}


@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -79,37 +78,33 @@ public String getKeyIfEnabledFor(Graph graph) {
}

private static final int capacity = 10000;
private Cache<Object,Object> cache = CacheBuilder.
newBuilder().
maximumSize(capacity).
build();

private Cache<Object, Object> 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);
}


// Legacy version with Function parameter
public Object getOrComputeObject(Object key, Function<Object,Object> function) {
return getOrComputeObject(key, () -> function.apply(key));
}


public Object getOrComputeObject(Object key, Callable<Object> 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) {
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/org/topbraid/shacl/util/SHACLUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ public static List<SHNodeShape> getAllShapesAtClassOrShape(Resource clsOrShape)
String key = OntologyOptimizations.get().getKeyIfEnabledFor(clsOrShape.getModel().getGraph());
if(key != null) {
key += ".getAllShapesAtClassOrShape(" + clsOrShape + ")";
return (List<SHNodeShape>) OntologyOptimizations.get().getOrComputeObject(key, () -> {
return (List<SHNodeShape>) OntologyOptimizations.get().getOrComputeObject(key, (cacheKey) -> {
List<SHNodeShape> results = new LinkedList<SHNodeShape>();
addAllShapesAtClassOrShape(clsOrShape, results, new HashSet<Resource>());
return results;
Expand All @@ -515,8 +515,9 @@ public static List<SHNodeShape> getAllShapesAtClassOrShape(Resource clsOrShape)
return results;
}
}





private static void addAllShapesAtClassOrShape(Resource clsOrShape, List<SHNodeShape> results, Set<Resource> reached) {
addDirectShapesAtClassOrShape(clsOrShape, results);
reached.add(clsOrShape);
Expand Down
Loading