SmartDataAnalytics / Sparqlify

Sparql -> SQL Rewriter enabling virtual RDB -> RDF mappings
http://aksw.org/Projects/Sparqlify
123 stars 13 forks source link

Error using blank nodes in RestrictionImpl #29

Closed patrickwestphal closed 10 years ago

patrickwestphal commented 11 years ago

When using blank nodes in one of the Nodes (gv, sv, pv, ov) in code like

Set<Clause> clauses = new HashSet<Clause>();
clauses.add(new Clause(new E_Equals(new ExprVar(g), NodeValue.makeNode(gv))));
clauses.add(new Clause(new E_Equals(new ExprVar(s), NodeValue.makeNode(sv))));
clauses.add(new Clause(new E_Equals(new ExprVar(p), NodeValue.makeNode(pv))));
clauses.add(new Clause(new E_Equals(new ExprVar(o), NodeValue.makeNode(ov))));

I get this trace:

java.lang.RuntimeException: Should not happen
    at org.aksw.sparqlify.restriction.RestrictionImpl.getNodeType(RestrictionImpl.java:234)
    at org.aksw.sparqlify.restriction.RestrictionImpl.stateNode(RestrictionImpl.java:243)
    at org.aksw.sparqlify.database.Clause.deriveRestrictionEquals(Clause.java:66)
    at org.aksw.sparqlify.database.Clause.deriveRestrictionEquals(Clause.java:57)
    at org.aksw.sparqlify.database.Clause.<init>(Clause.java:41)
    at org.aksw.sparqlify.database.Clause.<init>(Clause.java:32)
...

The following changes work for me but I don't know if they really solve a problem or just make an error not to appear:

diff --git a/sparqlify-core/src/main/java/org/aksw/sparqlify/restriction/RdfTermType.java b/sparqlify-core/src/main/java/org/aksw/sparqlify/restriction/RdfTermType.java
index c667012..4749a21 100644
--- a/sparqlify-core/src/main/java/org/aksw/sparqlify/restriction/RdfTermType.java
+++ b/sparqlify-core/src/main/java/org/aksw/sparqlify/restriction/RdfTermType.java
@@ -8,7 +8,7 @@ package org.aksw.sparqlify.restriction;
  */
 public enum RdfTermType {
        UNKNOWN,
-       //BLANK,
+       BLANK,
        URI, // TODO This should probably be resource (i.e. uri + blank node)
        LITERAL,
        //PLAIN_LITERAL,
diff --git a/sparqlify-core/src/main/java/org/aksw/sparqlify/restriction/RestrictionImpl.java b/sparqlify-core/src/main/java/org/aksw/sparqlify/restriction/RestrictionImpl.java
index 1b733c7..061a465 100644
--- a/sparqlify-core/src/main/java/org/aksw/sparqlify/restriction/RestrictionImpl.java
+++ b/sparqlify-core/src/main/java/org/aksw/sparqlify/restriction/RestrictionImpl.java
@@ -230,6 +230,8 @@ public class RestrictionImpl
                        return RdfTermType.URI;
                } else if(node.isLiteral()) {
                        return RdfTermType.LITERAL;
+               } else if(node.isBlank()) {
+                       return RdfTermType.BLANK;
                } else {
                        throw new RuntimeException("Should not happen");
                }
patrickwestphal commented 10 years ago

Committed the patch mentioned in the previous comment.