Skip to content

Commit

Permalink
Automate test skipping for unsupported queries
Browse files Browse the repository at this point in the history
  • Loading branch information
LakshyAAAgrawal committed Jun 6, 2021
1 parent 3b245f6 commit bd0d741
Show file tree
Hide file tree
Showing 23 changed files with 151 additions and 12 deletions.
5 changes: 4 additions & 1 deletion src/main/java/com/KRacR/s2c/CreateCypher.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ public String visitLiteral(Literal l) {
this.label,
l.getDatatypeURI(),
l.getLexicalForm(),
l.getLexicalForm()
(l.getLexicalForm() +
(l.getDatatypeURI().equals("http://www.w3.org/2001/XMLSchema#string")?
"":
"^^"+l.getDatatypeURI()))
)
);
}
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/KRacR/s2c/QueryNotSupportedException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.KRacR.s2c;

public class QueryNotSupportedException extends Exception {

public QueryNotSupportedException(String string) {
super(string);
}

}
74 changes: 70 additions & 4 deletions src/main/java/com/KRacR/s2c/SparqlAlgebraToCypherVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public class SparqlAlgebraToCypherVisitor implements OpVisitor {
private Map<String, Object> Cypher_to_sparql_variable_map;
private int blank_node_num = 0;
private Map<Node_Blank, Var> Sparql_blank_node_to_var_map;
private boolean isQueryConversionSuccesful = true;
private String conversionErrors = "";

public SparqlAlgebraToCypherVisitor() {
cypher = new String();
Expand All @@ -70,6 +72,7 @@ public SparqlAlgebraToCypherVisitor() {
@Override
public void visit(OpBGP opBGP) {
// TODO Auto-generated method stub
// TODO Instead of handling opTriple in this function, handle it in its visitor
System.out.println("In opBGP\n" + opBGP.toString());
java.util.Iterator<Triple> it = opBGP.getPattern().iterator();
while(it.hasNext()) {
Expand Down Expand Up @@ -160,162 +163,216 @@ protected String create_or_get_variable(Var allocated_var) {
public void visit(OpQuadPattern quadPattern){
// TODO Auto-generated method stub
System.out.println("In quadPattern\n" + quadPattern.toString());
this.isQueryConversionSuccesful = false;
this.conversionErrors += "Unsupported Algebra type OpQuadPattern\n";
}

@Override
public void visit(OpQuadBlock quadBlock) {
// TODO Auto-generated method stub
System.out.println("In quadBlock\n" + quadBlock.toString());
this.isQueryConversionSuccesful = false;
this.conversionErrors += "Unsupported Algebra type OpQuadBlock\n";
}

@Override
public void visit(OpTriple opTriple) {
// TODO Auto-generated method stub
System.out.println("In opTriple\n" + opTriple.toString());
this.isQueryConversionSuccesful = false;
this.conversionErrors += "Unsupported Algebra type OpTriple\n";
}

@Override
public void visit(OpQuad opQuad) {
// TODO Auto-generated method stub
System.out.println("In opQuad\n" + opQuad.toString());
this.isQueryConversionSuccesful = false;
this.conversionErrors += "Unsupported Algebra type OpQuad\n";
}

@Override
public void visit(OpPath opPath) {
// TODO Auto-generated method stub
System.out.println("In opPath\n" + opPath.toString());
this.isQueryConversionSuccesful = false;
this.conversionErrors += "Unsupported Algebra type OpPath\n";
}

@Override
public void visit(OpFind opFind) {
// TODO Auto-generated method stub
System.out.println("In opFind\n" + opFind.toString());
this.isQueryConversionSuccesful = false;
this.conversionErrors += "Unsupported Algebra type OpFind\n";
}

@Override
public void visit(OpTable opTable) {
// TODO Auto-generated method stub
System.out.println("In opTable\n" + opTable.toString());
this.isQueryConversionSuccesful = false;
this.conversionErrors += "Unsupported Algebra type OpTable\n";
}

@Override
public void visit(OpNull opNull) {
// TODO Auto-generated method stub
System.out.println("In opNull\n" + opNull.toString());
this.isQueryConversionSuccesful = false;
this.conversionErrors += "Unsupported Algebra type OpNull\n";
}

@Override
public void visit(OpProcedure opProc) {
// TODO Auto-generated method stub
System.out.println("In opProc\n" + opProc.toString());
this.isQueryConversionSuccesful = false;
this.conversionErrors += "Unsupported Algebra type OpProcedure\n";
}

@Override
public void visit(OpPropFunc opPropFunc) {
// TODO Auto-generated method stub
System.out.println("In opPropFunc\n" + opPropFunc.toString());
this.isQueryConversionSuccesful = false;
this.conversionErrors += "Unsupported Algebra type OpPropFunc\n";
}

@Override
public void visit(OpFilter opFilter) {
// TODO Auto-generated method stub
System.out.println("In opFilter\n" + opFilter.toString());
this.isQueryConversionSuccesful = false;
this.conversionErrors += "Unsupported Algebra type OpFilter\n";
}

@Override
public void visit(OpGraph opGraph) {
// TODO Auto-generated method stub
System.out.println("In opGraph\n" + opGraph.toString());
this.isQueryConversionSuccesful = false;
this.conversionErrors += "Unsupported Algebra type OpGraph\n";
}

@Override
public void visit(OpService opService) {
// TODO Auto-generated method stub
System.out.println("In opService\n" + opService.toString());
this.isQueryConversionSuccesful = false;
this.conversionErrors += "Unsupported Algebra type OpService\n";
}

@Override
public void visit(OpDatasetNames dsNames) {
// TODO Auto-generated method stub
System.out.println("In dsNames\n" + dsNames.toString());
this.isQueryConversionSuccesful = false;
this.conversionErrors += "Unsupported Algebra type OpDatasetNames\n";
}

@Override
public void visit(OpLabel opLabel) {
// TODO Auto-generated method stub
System.out.println("In opLabel\n" + opLabel.toString());
this.isQueryConversionSuccesful = false;
this.conversionErrors += "Unsupported Algebra type OpLabel\n";
}

@Override
public void visit(OpAssign opAssign) {
// TODO Auto-generated method stub
System.out.println("In opAssign\n" + opAssign.toString());
this.isQueryConversionSuccesful = false;
this.conversionErrors += "Unsupported Algebra type OpAssign\n";
}

@Override
public void visit(OpExtend opExtend) {
// TODO Auto-generated method stub
System.out.println("In opExtend\n" + opExtend.toString());
this.isQueryConversionSuccesful = false;
this.conversionErrors += "Unsupported Algebra type OpExtend\n";
}

@Override
public void visit(OpJoin opJoin) {
// TODO Auto-generated method stub
System.out.println("In opJoin\n" + opJoin.toString());
this.isQueryConversionSuccesful = false;
this.conversionErrors += "Unsupported Algebra type OpJoin\n";
}

@Override
public void visit(OpLeftJoin opLeftJoin) {
// TODO Auto-generated method stub
System.out.println("In opLeftJoin\n" + opLeftJoin.toString());
this.isQueryConversionSuccesful = false;
this.conversionErrors += "Unsupported Algebra type OpLeftJoin\n";
}

@Override
public void visit(OpUnion opUnion) {
// TODO Auto-generated method stub
System.out.println("In opUnion\n" + opUnion.toString());
this.isQueryConversionSuccesful = false;
this.conversionErrors += "Unsupported Algebra type OpUnion\n";
}

@Override
public void visit(OpDiff opDiff) {
// TODO Auto-generated method stub
System.out.println("In opDiff\n" + opDiff.toString());
this.isQueryConversionSuccesful = false;
this.conversionErrors += "Unsupported Algebra type OpDiff\n";
}

@Override
public void visit(OpMinus opMinus) {
// TODO Auto-generated method stub
System.out.println("In opMinus\n" + opMinus.toString());
this.isQueryConversionSuccesful = false;
this.conversionErrors += "Unsupported Algebra type OpMinus\n";
}

@Override
public void visit(OpConditional opCondition) {
// TODO Auto-generated method stub
System.out.println("In opCondition\n" + opCondition.toString());
this.isQueryConversionSuccesful = false;
this.conversionErrors += "Unsupported Algebra type OpCondition\n";
}

@Override
public void visit(OpSequence opSequence) {
// TODO Auto-generated method stub
System.out.println("In opSequence\n" + opSequence.toString());
this.isQueryConversionSuccesful = false;
this.conversionErrors += "Unsupported Algebra type OpSequence\n";
}

@Override
public void visit(OpDisjunction opDisjunction) {
// TODO Auto-generated method stub
System.out.println("In opDisjunction\n" + opDisjunction.toString());
this.isQueryConversionSuccesful = false;
this.conversionErrors += "Unsupported Algebra type OpDisjunction\n";
}

@Override
public void visit(OpList opList) {
// TODO Auto-generated method stub
System.out.println("In opList\n" + opList.toString());
this.isQueryConversionSuccesful = false;
this.conversionErrors += "Unsupported Algebra type OpList\n";
}

@Override
public void visit(OpOrder opOrder) {
// TODO Auto-generated method stub
System.out.println("In opOrder\n" + opOrder.toString());
this.isQueryConversionSuccesful = false;
this.conversionErrors += "Unsupported Algebra type OpOrder\n";
}

@Override
Expand All @@ -335,35 +392,44 @@ public void visit(OpProject opProject) {
public void visit(OpReduced opReduced) {
// TODO Auto-generated method stub
System.out.println("In opReduced\n" + opReduced.toString());
this.isQueryConversionSuccesful = false;
this.conversionErrors += "Unsupported Algebra type OpReduced\n";
}

@Override
public void visit(OpDistinct opDistinct) {
// TODO Auto-generated method stub
System.out.println("In opDistinct\n" + opDistinct.toString());
this.isQueryConversionSuccesful = false;
this.conversionErrors += "Unsupported Algebra type OpDistinct\n";
}

@Override
public void visit(OpSlice opSlice) {
// TODO Auto-generated method stub
System.out.println("In opSlice\n" + opSlice.toString());
this.isQueryConversionSuccesful = false;
this.conversionErrors += "Unsupported Algebra type OpSlice\n";
}

@Override
public void visit(OpGroup opGroup) {
// TODO Auto-generated method stub
System.out.println("In opGroup\n" + opGroup.toString());
this.isQueryConversionSuccesful = false;
this.conversionErrors += "Unsupported Algebra type OpGroup\n";
}

@Override
public void visit(OpTopN opTop) {
// TODO Auto-generated method stub
System.out.println("In opTop\n" + opTop.toString());
this.isQueryConversionSuccesful = false;
this.conversionErrors += "Unsupported Algebra type OpTop\n";
}

public String getCypher() {
// TODO Auto-generated method stub
return cypher; //"match (n)-[e:Edge]->(r {uri:\"http://localhost/persons/Paul_Erdoes\"}) return n.uri as subject, e.uri as predicate";
public String getCypher() throws QueryNotSupportedException {
if(this.isQueryConversionSuccesful) return cypher;
else throw new QueryNotSupportedException(this.conversionErrors);
}

}
15 changes: 12 additions & 3 deletions src/main/java/com/KRacR/s2c/SparqlToCypher.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.lang.String;

import javax.ws.rs.NotSupportedException;

import org.apache.jena.query.Query;
import org.apache.jena.query.QueryFactory;
import org.apache.jena.query.QueryVisitor;
Expand Down Expand Up @@ -45,15 +47,22 @@
import org.apache.jena.sparql.core.Prologue;

public class SparqlToCypher {
public static String convert(String sparql_query) {
public static String convert(String sparql_query) throws QueryNotSupportedException {
System.out.println("------------------------------------------\nInside Sparql to Cypher Converter");
Query sq = QueryFactory.create(sparql_query);
if(!(sq.isSelectType())) throw new QueryNotSupportedException("Conversion of the following query failed:\n" + sparql_query + "\nDue to the following reason:\n" + "Describe, Construct and Ask type queries not supported");
Op op = Algebra.compile(sq);
System.out.println(sparql_query);
System.out.println(op);
//System.out.println(op);
SparqlAlgebraToCypherVisitor visitor = new SparqlAlgebraToCypherVisitor();
op.visit(visitor);
System.out.println(visitor.getCypher());
String cypher_query = null;
try {
cypher_query = visitor.getCypher();
}catch(QueryNotSupportedException qe) {
throw new QueryNotSupportedException("Conversion of the following query failed:\n" + sparql_query + "\nDue to the following reason:\n" + qe.getMessage());
}
System.out.println(cypher_query);
System.out.println("Exit Sparql to Cypher Converter\n------------------------------------------");
return visitor.getCypher();
}
Expand Down
Loading

0 comments on commit bd0d741

Please sign in to comment.