Skip to content

Commit

Permalink
[Upd] Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
blcham committed Aug 2, 2023
1 parent 2cf8a42 commit 1124d6d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
Expand Up @@ -9,6 +9,7 @@
import cz.cvut.spipes.engine.VariablesBinding;
import cz.cvut.spipes.exception.ValidationConstraintFailedException;
import cz.cvut.spipes.util.JenaUtils;
import cz.cvut.spipes.util.QueryUtils;
import org.apache.jena.atlas.lib.NotImplemented;
import org.apache.jena.ontology.OntModel;
import org.apache.jena.query.*;
Expand Down Expand Up @@ -306,9 +307,9 @@ protected String getQueryComment(org.topbraid.spin.model.Query query) {
if (query.getComment() != null) {
return query.getComment();
}
String comment = query.toString().split(System.lineSeparator())[0];
if (comment.matches("\\s*#.*")) {
return comment.split("\\s*#\\s*", 2)[1];
String comment = QueryUtils.getQueryComment(query.toString());
if (comment != null) {
return comment;
}
// Resource obj = query.getPropertyResourceValue(RDFS.comment);
// if (obj == null) {
Expand Down
27 changes: 14 additions & 13 deletions s-pipes-core/src/main/java/cz/cvut/spipes/util/QueryUtils.java
@@ -1,25 +1,18 @@
package cz.cvut.spipes.util;


import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.LinkedList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.stream.Collectors;
import org.apache.jena.query.ARQ;
import org.apache.jena.query.ParameterizedSparqlString;
import org.apache.jena.query.Query;
import org.apache.jena.query.QueryExecution;
import org.apache.jena.query.QueryExecutionFactory;
import org.apache.jena.query.QuerySolution;
import org.apache.jena.query.ResultSet;
import org.apache.jena.query.*;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.RDFNode;
import org.apache.jena.sparql.mgt.Explain;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.regex.Matcher;
import java.util.stream.Collectors;

public class QueryUtils {

private static final Logger LOG = LoggerFactory.getLogger(QueryUtils.class);
Expand Down Expand Up @@ -176,4 +169,12 @@ private interface QueryExecutor<T> {
T execQuery(QueryExecution execution);
}

public static String getQueryComment(String query) {
String comment = query.split(System.lineSeparator())[0];
if (comment.matches("\\s*#.*")) {
return comment.split("\\s*#\\s*", 2)[1];
}
return null;
}

}

0 comments on commit 1124d6d

Please sign in to comment.