Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
hmottestad committed Sep 24, 2024
1 parent 9c8a4f2 commit 347a8c5
Show file tree
Hide file tree
Showing 20 changed files with 110 additions and 1,850 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
import java.util.function.Supplier;
import java.util.stream.Collectors;

import org.apache.commons.text.StringEscapeUtils;
import org.eclipse.rdf4j.common.iteration.CloseableIteration;
import org.eclipse.rdf4j.sail.SailConnection;
import org.eclipse.rdf4j.sail.SailException;
import org.eclipse.rdf4j.sail.shacl.ast.Shape;
import org.eclipse.rdf4j.sail.shacl.ast.planNodes.PlanNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.eclipse.rdf4j.model.IRI;
import org.eclipse.rdf4j.model.Model;
import org.eclipse.rdf4j.model.Resource;
import org.eclipse.rdf4j.model.Statement;
import org.eclipse.rdf4j.model.vocabulary.SHACL;
import org.eclipse.rdf4j.query.BindingSet;
import org.eclipse.rdf4j.query.algebra.TupleExpr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ public String getId() {

@Override
public String toString() {
return "EqualsJoin{" + "useAsFilter=" + useAsFilter + '}';
return "EqualsJoinValue{" +
"useAsFilter=" + useAsFilter +
'}';
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ public void getPlanAsGraphvizDot(StringBuilder stringBuilder) {

@Override
public String toString() {
return "ExternalFilterByPredicate{" + "filterOnPredicates="
+ Arrays.toString(filterOnPredicates.stream().map(Formatter::prefix).toArray())
return "FilterByPredicate{" + "filterOnPredicates="
+ Formatter.prefix(filterOnPredicates)
+ '}';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,9 @@ public int hashCode() {

@Override
public String toString() {
return "ExternalPredicateObjectFilter{" + "filterOnObject=" + PlanNode.prefix(filterOnObject)
return "FilterByPredicateObject{" + "filterOnObject=" + Formatter.prefix(filterOnObject)
+ ", filterOnPredicate="
+ PlanNode.prefix(filterOnPredicate) + ", filterOn=" + filterOn + ", returnMatching="
+ Formatter.prefix(filterOnPredicate) + ", filterOn=" + filterOn + ", returnMatching="
+ returnMatching + '}';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ boolean checkTuple(Reference t) {
return connection.hasStatement(null, null, target, true, dataGraph);
}

@Override
public String toString() {
return "ExternalFilterTargetIsObject{" + '}';
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@ boolean checkTuple(Reference t) {

}

@Override
public String toString() {
return "ExternalFilterTargetIsSubject{}";
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,76 @@
*******************************************************************************/
package org.eclipse.rdf4j.sail.shacl.ast.planNodes;

import java.util.Arrays;
import java.util.List;
import java.util.Set;

import org.eclipse.rdf4j.model.IRI;
import org.eclipse.rdf4j.model.Namespace;
import org.eclipse.rdf4j.model.Value;
import org.eclipse.rdf4j.model.impl.SimpleNamespace;
import org.eclipse.rdf4j.model.vocabulary.AFN;
import org.eclipse.rdf4j.model.vocabulary.APF;
import org.eclipse.rdf4j.model.vocabulary.CONFIG;
import org.eclipse.rdf4j.model.vocabulary.DASH;
import org.eclipse.rdf4j.model.vocabulary.DC;
import org.eclipse.rdf4j.model.vocabulary.DCAT;
import org.eclipse.rdf4j.model.vocabulary.DCTERMS;
import org.eclipse.rdf4j.model.vocabulary.DOAP;
import org.eclipse.rdf4j.model.vocabulary.EARL;
import org.eclipse.rdf4j.model.vocabulary.FN;
import org.eclipse.rdf4j.model.vocabulary.FOAF;
import org.eclipse.rdf4j.model.vocabulary.GEO;
import org.eclipse.rdf4j.model.vocabulary.GEOF;
import org.eclipse.rdf4j.model.vocabulary.HYDRA;
import org.eclipse.rdf4j.model.vocabulary.LDP;
import org.eclipse.rdf4j.model.vocabulary.LIST;
import org.eclipse.rdf4j.model.vocabulary.LOCN;
import org.eclipse.rdf4j.model.vocabulary.ODRL2;
import org.eclipse.rdf4j.model.vocabulary.ORG;
import org.eclipse.rdf4j.model.vocabulary.OWL;
import org.eclipse.rdf4j.model.vocabulary.PROV;
import org.eclipse.rdf4j.model.vocabulary.RDF;
import org.eclipse.rdf4j.model.vocabulary.RDF4J;
import org.eclipse.rdf4j.model.vocabulary.RDFS;
import org.eclipse.rdf4j.model.vocabulary.ROV;
import org.eclipse.rdf4j.model.vocabulary.RSX;
import org.eclipse.rdf4j.model.vocabulary.SD;
import org.eclipse.rdf4j.model.vocabulary.SESAME;
import org.eclipse.rdf4j.model.vocabulary.SESAMEQNAME;
import org.eclipse.rdf4j.model.vocabulary.SHACL;
import org.eclipse.rdf4j.model.vocabulary.SKOS;
import org.eclipse.rdf4j.model.vocabulary.SKOSXL;
import org.eclipse.rdf4j.model.vocabulary.SP;
import org.eclipse.rdf4j.model.vocabulary.SPIF;
import org.eclipse.rdf4j.model.vocabulary.SPIN;
import org.eclipse.rdf4j.model.vocabulary.SPINX;
import org.eclipse.rdf4j.model.vocabulary.SPL;
import org.eclipse.rdf4j.model.vocabulary.TIME;
import org.eclipse.rdf4j.model.vocabulary.VANN;
import org.eclipse.rdf4j.model.vocabulary.VCARD4;
import org.eclipse.rdf4j.model.vocabulary.VOID;
import org.eclipse.rdf4j.model.vocabulary.WGS84;
import org.eclipse.rdf4j.model.vocabulary.XSD;

public class Formatter {

public static String prefix(Set<? extends Value> set) {
if (set.size() == 1) {
return prefix(set.iterator().next());
}

return Arrays.toString(set.stream().map(Formatter::prefix).toArray());
}

public static String prefix(List<? extends Value> list) {
if (list.size() == 1) {
return prefix(list.iterator().next());
}

return Arrays.toString(list.stream().map(Formatter::prefix).toArray());
}

public static String prefix(Value in) {

if (in == null) {
Expand All @@ -36,12 +91,51 @@ public static String prefix(Value in) {
String namespace = ((IRI) in).getNamespace();

List<Namespace> namespaces = List.of(
AFN.NS,
APF.NS,
CONFIG.NS,
DASH.NS,
DC.NS,
DCAT.NS,
DCTERMS.NS,
DOAP.NS,
EARL.NS,
FN.NS,
FOAF.NS,
GEO.NS,
GEOF.NS,
HYDRA.NS,
LDP.NS,
LIST.NS,
LOCN.NS,
ODRL2.NS,
ORG.NS,
OWL.NS,
PROV.NS,
RDF.NS,
RDF4J.NS,
RDFS.NS,
ROV.NS,
RSX.NS,
SD.NS,
SESAME.NS,
SESAMEQNAME.NS,
SHACL.NS,
FOAF.NS,
DCAT.NS,
SKOS.NS,
SKOSXL.NS,
SP.NS,
SPIF.NS,
SPIN.NS,
SPINX.NS,
SPL.NS,
TIME.NS,
VANN.NS,
VCARD4.NS,
VOID.NS,
WGS84.NS,
XSD.NS,
new SimpleNamespace("http://example.com/ns#", "ex"),
XSD.NS
new SimpleNamespace("http://example.com/ns/", "ex")
);

for (Namespace ns : namespaces) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public void getPlanAsGraphvizDot(StringBuilder stringBuilder) {

@Override
public String toString() {
return "GroupByCountFilter";
return "GroupByFilter";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ public String getId() {

@Override
public String toString() {
return "InnerJoin(" + left.toString() + " : " + right.toString() + ")";
return "InnerJoin";
}

private String leadingSpace() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,13 @@

package org.eclipse.rdf4j.sail.shacl.ast.planNodes;

import java.util.Arrays;
import java.util.Set;

import org.eclipse.rdf4j.common.iteration.CloseableIteration;
import org.eclipse.rdf4j.model.IRI;
import org.eclipse.rdf4j.model.Resource;
import org.eclipse.rdf4j.model.Value;
import org.eclipse.rdf4j.model.vocabulary.FOAF;
import org.eclipse.rdf4j.model.vocabulary.RDF;

/**
* @author Håvard Mikkelsen Ottestad
*/
public interface PlanNode {

static String prefix(Set<Resource> filterOnObject) {
if (filterOnObject.size() == 1) {
return prefix(filterOnObject.iterator().next());
}

return Arrays.toString(filterOnObject.stream().map(PlanNode::prefix).toArray());
}

static String prefix(Value value) {
return Formatter.prefix(value);
}

CloseableIteration<? extends ValidationTuple> iterator();

int depth();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

package org.eclipse.rdf4j.sail.shacl.ast.planNodes;

import java.util.Arrays;
import java.util.Objects;
import java.util.Set;

Expand Down Expand Up @@ -113,7 +112,7 @@ public String getId() {
@Override
public String toString() {
return "SetFilterNode{" + "targetNodeList="
+ Arrays.toString(targetNodeList.stream().map(Formatter::prefix).toArray()) + ", index=" + index
+ Formatter.prefix(targetNodeList) + ", index=" + index
+ ", returnValid=" + returnValid + '}';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public String getId() {

@Override
public String toString() {
return "ModifyValidationTuple";
return "TupleMapper";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

package org.eclipse.rdf4j.sail.shacl.ast.planNodes;

import java.util.Arrays;
import java.util.Objects;
import java.util.Set;

Expand All @@ -37,8 +36,7 @@ boolean checkTuple(Reference t) {

@Override
public String toString() {
return "ValueInFilter{" + "valueSet=" + Arrays.toString(valueSet.stream().map(Formatter::prefix).toArray())
+ '}';
return "ValueInFilter{" + "valueSet=" + Formatter.prefix(valueSet) + '}';
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public String getId() {

@Override
public String toString() {
return "ValuesBackedNode{" + "values=" + values + '}';
return "ValuesBackedNode{" + "values=" + Formatter.prefix(values) + '}';
}

@Override
Expand Down
Loading

0 comments on commit 347a8c5

Please sign in to comment.