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

Bump org.apache.jena:apache-jena-libs from 4.10.0 to 5.2.0 #547

Merged
13 changes: 6 additions & 7 deletions admin-ui/src/main/java/eu/knowledge/engine/admin/AdminUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.rdf.model.SimpleSelector;
import org.apache.jena.shared.PrefixMapping;
import org.apache.jena.sparql.graph.PrefixMappingMem;
import org.apache.jena.sparql.lang.arq.ParseException;
Expand Down Expand Up @@ -184,9 +183,9 @@ public BindingSet handleChangedKnowledgeBaseKnowledge(ReactExchangeInfo ei) {
// - delete all old data about that knowledge base
// - insert the *new* data about that knowledge base

Resource kb = model.query(new SimpleSelector(null, RDF.type, Vocab.KNOWLEDGE_BASE)).listSubjects().next();
String query = String.format("DELETE { %s } WHERE { %s FILTER (?kb = <%s>) } ",
this.metaGraphPattern.getPattern(), this.metaGraphPattern.getPattern(), kb.toString());
Resource kb = model.listSubjectsWithProperty(RDF.type, Vocab.KNOWLEDGE_BASE).next();
String query = String.format("DELETE { %s } WHERE { %s FILTER (?kb = <%s>) } ", this.metaGraphPattern.getPattern(), this.metaGraphPattern.getPattern(), kb.toString());

UpdateRequest updateRequest = UpdateFactory.create(query);
UpdateAction.execute(updateRequest, this.model);

Expand Down Expand Up @@ -215,9 +214,9 @@ public BindingSet handleRemovedKnowledgeBaseKnowledge(ReactExchangeInfo ei) {
// - extract the knowledge base that this message is about
// - delete all old data about that knowledge base

Resource kb = model.query(new SimpleSelector(null, RDF.type, Vocab.KNOWLEDGE_BASE)).listSubjects().next();
String query = String.format("DELETE { %s } WHERE { %s FILTER (?kb = <%s>) } ",
this.metaGraphPattern.getPattern(), this.metaGraphPattern.getPattern(), kb.toString());
Resource kb = model.listSubjectsWithProperty(RDF.type, Vocab.KNOWLEDGE_BASE).next();
String query = String.format("DELETE { %s } WHERE { %s FILTER (?kb = <%s>) } ", this.metaGraphPattern.getPattern(), this.metaGraphPattern.getPattern(), kb.toString());

UpdateRequest updateRequest = UpdateFactory.create(query);
UpdateAction.execute(updateRequest, this.model);

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>apache-jena-libs</artifactId>
<version>4.10.0</version>
<version>5.2.0</version>
<type>pom</type>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,28 @@
import java.util.Map;

import org.apache.jena.graph.Node;
import org.apache.jena.graph.Node_Concrete;

import org.apache.jena.sparql.core.Var;
import org.apache.jena.sparql.graph.PrefixMappingZero;
import org.apache.jena.sparql.sse.SSE;
import org.apache.jena.sparql.util.FmtUtils;

import eu.knowledge.engine.reasoner.api.Binding;

public class Binding extends HashMap<Var, Node_Concrete> {
public class Binding extends HashMap<Var, Node> {

private static final long serialVersionUID = 2381462612239850018L;

public Binding() {
super();
}

public Binding(Var variable, Node_Concrete lit) {
public Binding(Var variable, Node lit) {
super();
this.put(variable, lit);
}

public Binding(String variable, String val) {
this(Var.alloc(variable), (Node_Concrete) SSE.parseNode(val));
this(Var.alloc(variable), (Node) SSE.parseNode(val));
}

public Binding(Binding b) {
Expand All @@ -48,13 +46,13 @@ public Node get(String variable) {
}

public Node put(String variable, String val) {
return this.put(Var.alloc(variable), (Node_Concrete) SSE.parseNode(val));
return this.put(Var.alloc(variable), (Node) SSE.parseNode(val));
}

public Map<String, String> toMap() {

Map<String, String> result = new HashMap<String, String>();
for (Map.Entry<Var, Node_Concrete> entry : this.entrySet()) {
for (Map.Entry<Var, Node> entry : this.entrySet()) {
// TODO: Util function that does the stringForNode without prefixes
result.put(entry.getKey().getName(), FmtUtils.stringForNode(entry.getValue(), new PrefixMappingZero()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.util.Set;

import org.apache.jena.graph.Node;
import org.apache.jena.graph.Node_Concrete;
import org.apache.jena.sparql.core.Var;
import org.apache.jena.sparql.graph.PrefixMappingZero;
import org.apache.jena.sparql.sse.SSE;
Expand All @@ -20,7 +19,7 @@
*/
public class TripleVarBinding {

private Map<TripleNode, Node_Concrete> tripleVarMapping;
private Map<TripleNode, Node> tripleVarMapping;

/**
* Optimize the getVarValue method.
Expand Down Expand Up @@ -57,7 +56,7 @@ public TripleVarBinding(Set<TriplePattern> aGraphPattern, Binding aBinding) {

public TripleVarBinding(TripleVarBinding b) {
this();
for (Map.Entry<TripleNode, Node_Concrete> entry : b.tripleVarMapping.entrySet()) {
for (Map.Entry<TripleNode, Node> entry : b.tripleVarMapping.entrySet()) {
this.put(entry.getKey(), entry.getValue());
}

Expand All @@ -66,23 +65,23 @@ public TripleVarBinding(TripleVarBinding b) {
}
}

public Set<Map.Entry<TripleNode, Node_Concrete>> entrySet() {
public Set<Map.Entry<TripleNode, Node>> entrySet() {
return tripleVarMapping.entrySet();
}

public Set<TripleNode> getTripleVars() {
return tripleVarMapping.keySet();
}

public void put(TripleNode aTripleVar, Node_Concrete aLiteral) {
public void put(TripleNode aTripleVar, Node aLiteral) {
assert aTripleVar.node.isVariable();
tripleVarMapping.put(aTripleVar, aLiteral);
variableTripleVarMapping.put((Var) aTripleVar.node, aTripleVar);
}

public void put(TripleNode aTripleVar, String aLiteral) {
assert aTripleVar.node.isVariable();
tripleVarMapping.put(aTripleVar, (Node_Concrete) SSE.parseNode(aLiteral));
tripleVarMapping.put(aTripleVar, (Node) SSE.parseNode(aLiteral));
variableTripleVarMapping.put((Var) aTripleVar.node, aTripleVar);
}

Expand All @@ -97,7 +96,7 @@ public void put(TripleNode aTripleVar, String aLiteral) {
public Binding toBinding() {

Binding b = new Binding();
for (Map.Entry<TripleNode, Node_Concrete> entry : this.tripleVarMapping.entrySet()) {
for (Map.Entry<TripleNode, Node> entry : this.tripleVarMapping.entrySet()) {
assert entry.getKey().node.isVariable();
b.put((Var) entry.getKey().node, entry.getValue());
}
Expand All @@ -111,7 +110,7 @@ public Binding toBinding() {
public boolean isConflicting(TripleVarBinding tvb) {

Node l;
for (Map.Entry<TripleNode, Node_Concrete> e : this.tripleVarMapping.entrySet()) {
for (Map.Entry<TripleNode, Node> e : this.tripleVarMapping.entrySet()) {
assert e.getKey().node.isVariable();
l = tvb.getVarValue((Var) e.getKey().node);

Expand All @@ -126,15 +125,15 @@ public boolean isConflicting(TripleVarBinding tvb) {
* We assume all occurrences of a var have the same literal, we just return the
* first one found.
*
* @param var
* @param variable
* @return
*/
public Node_Concrete getVarValue(Var variable) {
public Node getVarValue(Var variable) {
TripleNode tripleVar = this.variableTripleVarMapping.get(variable);
return this.get(tripleVar);
}

public Node_Concrete get(TripleNode key) {
public Node get(TripleNode key) {
return this.tripleVarMapping.get(key);
}

Expand Down Expand Up @@ -196,7 +195,7 @@ public String toString() {
StringBuilder sb = new StringBuilder();
String prefix = "";
sb.append("{");
for (Map.Entry<TripleNode, Node_Concrete> entry : this.tripleVarMapping.entrySet()) {
for (Map.Entry<TripleNode, Node> entry : this.tripleVarMapping.entrySet()) {
sb.append(prefix).append(entry.getKey().node).append("=")
.append(FmtUtils.stringForNode(entry.getValue(), new PrefixMappingZero()));
prefix = ",";
Expand Down Expand Up @@ -228,7 +227,7 @@ public TripleVarBinding merge(TripleVarBinding otherB) {
return b;
}

private void putAll(Map<TripleNode, Node_Concrete> aTripleVarMapping) {
private void putAll(Map<TripleNode, Node> aTripleVarMapping) {

for (TripleNode tv : aTripleVarMapping.keySet()) {
assert tv.node.isVariable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import java.util.concurrent.ConcurrentHashMap;

import org.apache.jena.graph.Node;
import org.apache.jena.graph.Node_Concrete;
import org.apache.jena.sparql.core.Var;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -153,7 +152,7 @@ public String toString() {
/**
* Simply the union between the two bindingsets. Does nothing complex for now.
*
* @param gbs
* @param aGraphBindingSet
* @return
*/
public TripleVarBindingSet merge(TripleVarBindingSet aGraphBindingSet) {
Expand Down Expand Up @@ -232,18 +231,18 @@ public TripleVarBindingSet translate(Set<TriplePattern> graphPattern, Set<Match>
&& !fromB.get(fromTVar).equals(toBVarValue)) {
skip = true; // conflict, so skip
}
} else if (fromTNode.node instanceof Var && toTNode.node instanceof Node_Concrete) {
} else if (fromTNode.node instanceof Var && toTNode.node instanceof Node && toTNode.node.isConcrete() ) {
var fromTVar = new TripleNode(fromTriple, (Var) fromTNode.node, fromTNode.nodeIdx);
if (fromB.containsKey(fromTVar) && !fromB.get(fromTVar).equals(toTNode.node)) {
skip = true; // conflict, so skip
}
} else if (fromTNode.node instanceof Node_Concrete && toTNode.node instanceof Var) {
} else if (fromTNode.node instanceof Node && fromTNode.node.isConcrete() && toTNode.node instanceof Var) {
var toTVar = new TripleNode(toTriple, (Var) toTNode.node, toTNode.nodeIdx);
if (toB.containsVar((Var) toTVar.node)
&& !toB.getVarValue((Var) toTVar.node).equals(fromTNode.node)) {
skip = true;
} else if (!toB.containsVar((Var) toTVar.node)) {
toB.put(toTVar, (Node_Concrete) fromTNode.node);
toB.put(toTVar, (Node) fromTNode.node);
}
}
}
Expand Down Expand Up @@ -332,9 +331,9 @@ public void printDebuggingTable() {
Set<TripleNode> nodes = tvb.getTripleNodes(tp);
if (!nodes.isEmpty()) {

Node_Concrete subject = null;
Node_Concrete predicate = null;
Node_Concrete object = null;
Node subject = null;
Node predicate = null;
Node object = null;

for (TripleNode tn : nodes) {
if (tn.nodeIdx == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import java.util.Set;

import org.apache.jena.graph.Node;
import org.apache.jena.graph.Node_Concrete;

import eu.knowledge.engine.reasoner.BaseRule;
import eu.knowledge.engine.reasoner.api.TripleNode;
Expand Down Expand Up @@ -160,9 +159,9 @@ public void printDebuggingTable() {
Set<TripleNode> nodes = tvb.getTripleNodes(tp);
if (!nodes.isEmpty()) {

Node_Concrete subject = null;
Node_Concrete predicate = null;
Node_Concrete object = null;
Node subject = null;
Node predicate = null;
Node object = null;

for (TripleNode tn : nodes) {
if (tn.nodeIdx == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void test() throws InterruptedException, ExecutionException, ParseExcepti

Model m = ModelFactory.createDefaultModel();
for (Binding binding : results2) {
m.add(m.asStatement(new Triple(binding.get("s"), binding.get("p"), binding.get("o"))));
m.add(m.asStatement(Triple.create(binding.get("s"), binding.get("p"), binding.get("o"))));
}

// Model m = Util.generateModel(new TriplePattern(genericTriple), results2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,11 @@
import java.util.Set;

import org.apache.jena.graph.Node;
import org.apache.jena.graph.Node_Concrete;
import org.apache.jena.sparql.graph.PrefixMappingZero;
import org.apache.jena.sparql.sse.SSE;
import org.apache.jena.sparql.util.FmtUtils;
import org.junit.jupiter.api.Test;

import eu.knowledge.engine.reasoner.api.Binding;
import eu.knowledge.engine.reasoner.api.BindingSet;
import eu.knowledge.engine.reasoner.api.TriplePattern;
import eu.knowledge.engine.reasoner.api.TripleNode;
import eu.knowledge.engine.reasoner.api.TripleVarBinding;
import eu.knowledge.engine.reasoner.api.TripleVarBindingSet;

public class BindingTest {

Expand All @@ -28,7 +21,7 @@ public void testGraphPatternBindingSets() {
TriplePattern t1 = new TriplePattern("?a <type> <Sensor>");
TriplePattern t2 = new TriplePattern("?a <hasVal> ?b");
TripleVarBinding tb1 = new TripleVarBinding();
tb1.put(new TripleNode(t1, "?a", 0), (Node_Concrete) SSE.parseNode("<sensor1>"));
tb1.put(new TripleNode(t1, "?a", 0), (Node) SSE.parseNode("<sensor1>"));

TripleVarBinding tb2 = new TripleVarBinding();
tb2.put(new TripleNode(t2, "?b", 2), "22");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public static Model generateModel(TriplePattern tp, BindingSet variableBindings)
newNodes[i] = newN;
}

m.add(m.asStatement(new Triple(newNodes[0], newNodes[1], newNodes[2])));
m.add(m.asStatement(Triple.create(newNodes[0], newNodes[1], newNodes[2])));
}
return m;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package eu.knowledge.engine.smartconnector.api;

import com.fasterxml.jackson.core.format.MatchStrength;

/**
* A {@link KnowledgeInteraction} represents an agreement about the exchange of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;

import org.apache.jena.graph.Node_Concrete;
import org.apache.jena.graph.Node;
import org.apache.jena.sparql.core.TriplePath;
import org.apache.jena.sparql.core.Var;
import org.apache.jena.sparql.graph.PrefixMappingZero;
Expand Down Expand Up @@ -294,7 +294,7 @@ protected BindingSet translateBindingSetFrom(eu.knowledge.engine.reasoner.api.Bi

for (eu.knowledge.engine.reasoner.api.Binding b : bs) {
newB = new Binding();
for (Map.Entry<Var, Node_Concrete> entry : b.entrySet()) {
for (Map.Entry<Var, Node> entry : b.entrySet()) {
newB.put(entry.getKey().getName(), FmtUtils.stringForNode(entry.getValue(), context));
}
newBS.add(newB);
Expand All @@ -305,7 +305,7 @@ protected BindingSet translateBindingSetFrom(eu.knowledge.engine.reasoner.api.Bi
/**
* Translate bindingset from the ke bindingset to the reasoner bindingset.
*
* @param bs a ke bindingset
* @param someBindings a ke bindingset
Copy link
Collaborator

Choose a reason for hiding this comment

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

😃

* @return a reasoner bindingset
*/
protected eu.knowledge.engine.reasoner.api.BindingSet translateBindingSetTo(BindingSet someBindings) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public static Model generateModel(GraphPattern graphPattern, BindingSet variable
newNodes[i] = newN;
}

m.add(m.asStatement(new Triple(newNodes[0], newNodes[1], newNodes[2])));
m.add(m.asStatement(Triple.create(newNodes[0], newNodes[1], newNodes[2])));
}
}
return m;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.apache.jena.datatypes.xsd.XSDDatatype;
import org.apache.jena.graph.Node;
import org.apache.jena.graph.NodeFactory;
import org.apache.jena.graph.Node_Concrete;
import org.apache.jena.graph.Node;
import org.apache.jena.sparql.core.Var;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -41,7 +41,7 @@ void testTypedLiteral() {

eu.knowledge.engine.reasoner.api.BindingSet bsR = new eu.knowledge.engine.reasoner.api.BindingSet();
eu.knowledge.engine.reasoner.api.Binding bR = new eu.knowledge.engine.reasoner.api.Binding();
bR.put(varNodeVersion, (Node_Concrete) literalNodeVersion);
bR.put(varNodeVersion, (Node) literalNodeVersion);
bsR.add(bR);
BindingSet otherBS = rp.testerFrom(bsR);
assertEquals(literalStringVersion, otherBS.iterator().next().get(varStringVersion));
Expand Down
Loading