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

Refactor RDFNode to string to separate utils class #264

Merged
merged 1 commit into from
Aug 21, 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
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();
}
}
}
Loading