Skip to content

Commit

Permalink
[#263] Refactor RDFNode to string to separate utils class
Browse files Browse the repository at this point in the history
  • Loading branch information
palagdan committed Aug 20, 2024
1 parent 2db708f commit 75fcb0b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cz.cvut.spipes.engine;

import cz.cvut.spipes.util.RDFNodeUtils;
import org.apache.jena.query.QuerySolution;
import org.apache.jena.query.QuerySolutionMap;
import org.apache.jena.rdf.model.*;
Expand Down Expand Up @@ -184,24 +185,15 @@ public String toString() {
.stream()
.collect(Collectors.toMap(
Map.Entry::getKey,
e -> toString(e.getValue())
e -> RDFNodeUtils.toString(e.getValue())
))
.toString();
}

private static String toString(RDFNode node) {
if (node.isLiteral()) {
return "\"" + node.asLiteral().getLexicalForm() + "\"";
} else if (node.isURIResource() || node.isResource()) {
return "<" + node.asResource().getURI() + ">";
} else {
return node.toString();
}
}

public String toTruncatedString() {
return binding.asMap().entrySet().stream()
.map(e -> new AbstractMap.SimpleEntry<>(e.getKey(), getTruncatedValue(toString(e.getValue())))).
.map(e -> new AbstractMap.SimpleEntry<>(e.getKey(), getTruncatedValue(RDFNodeUtils.toString(e.getValue())))).
collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)).toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import cz.cvut.spipes.exception.ValidationConstraintFailedException;
import cz.cvut.spipes.util.JenaUtils;
import cz.cvut.spipes.util.QueryUtils;
import cz.cvut.spipes.util.RDFNodeUtils;
import org.apache.jena.atlas.lib.NotImplemented;
import org.apache.jena.ontology.OntModel;
import org.apache.jena.query.*;
Expand Down Expand Up @@ -270,7 +271,7 @@ private void checkConstraints(Model model, QuerySolution bindings, List<Resource
for (Iterator<String> it = solution.varNames(); it.hasNext(); ) {
String varName = it.next();
RDFNode value = solution.get(varName);
evidenceMap.put(varName, value.toString());
evidenceMap.put(varName, RDFNodeUtils.toString(value));
}
evidences.add(evidenceMap);
}
Expand Down
16 changes: 16 additions & 0 deletions s-pipes-core/src/main/java/cz/cvut/spipes/util/RDFNodeUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package cz.cvut.spipes.util;

import org.apache.jena.rdf.model.RDFNode;

public class RDFNodeUtils {

public static String toString(RDFNode node) {
if (node.isLiteral()) {
return "\"" + node.asLiteral().getLexicalForm() + "\"";
} else if (node.isURIResource() || node.isResource()) {
return "<" + node.asResource().getURI() + ">";
} else {
return node.toString();
}
}
}

0 comments on commit 75fcb0b

Please sign in to comment.