clerezza-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From enrid...@apache.org
Subject git commit: CLEREZZA-865 Correct binding of bnodes via skolemization
Date Wed, 15 Jan 2014 00:10:37 GMT
Updated Branches:
  refs/heads/master f30ebdf5d -> 9929bc04e


CLEREZZA-865 Correct binding of bnodes via skolemization


Project: http://git-wip-us.apache.org/repos/asf/clerezza/repo
Commit: http://git-wip-us.apache.org/repos/asf/clerezza/commit/9929bc04
Tree: http://git-wip-us.apache.org/repos/asf/clerezza/tree/9929bc04
Diff: http://git-wip-us.apache.org/repos/asf/clerezza/diff/9929bc04

Branch: refs/heads/master
Commit: 9929bc04e53ef156a9720e689c47735d0e15ba85
Parents: f30ebdf
Author: enridaga <enridaga@apache.org>
Authored: Wed Jan 15 00:10:24 2014 +0000
Committer: enridaga <enridaga@apache.org>
Committed: Wed Jan 15 00:10:24 2014 +0000

----------------------------------------------------------------------
 .../rdf/virtuoso/storage/VirtuosoMGraph.java    | 61 ++++++++++++++++----
 .../java/rdf/virtuoso/storage/RdfIOTest.java    |  1 -
 .../virtuoso/storage/VirtuosoMGraphTest.java    |  8 ++-
 3 files changed, 57 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/clerezza/blob/9929bc04/clerezza-virtuoso/rdf.virtuoso.storage/src/main/java/rdf/virtuoso/storage/VirtuosoMGraph.java
----------------------------------------------------------------------
diff --git a/clerezza-virtuoso/rdf.virtuoso.storage/src/main/java/rdf/virtuoso/storage/VirtuosoMGraph.java
b/clerezza-virtuoso/rdf.virtuoso.storage/src/main/java/rdf/virtuoso/storage/VirtuosoMGraph.java
index 04df4ba..879256c 100644
--- a/clerezza-virtuoso/rdf.virtuoso.storage/src/main/java/rdf/virtuoso/storage/VirtuosoMGraph.java
+++ b/clerezza-virtuoso/rdf.virtuoso.storage/src/main/java/rdf/virtuoso/storage/VirtuosoMGraph.java
@@ -145,25 +145,60 @@ public class VirtuosoMGraph extends AbstractMGraph implements MGraph,
 		String virtSubject = toVirtSubject(subject);
 		String virtPredicate = toVirtPredicate(predicate);
 		String virtObject = toVirtObject(object);
-		sb.append("SPARQL SELECT ?SUBJECT ?PREDICATE ?OBJECT WHERE { GRAPH <")
-				.append(this.getName()).append("> { ")
-				.append(" ?SUBJECT ?PREDICATE ?OBJECT ");
+//		
+//		sb.append("SPARQL SELECT ?SUBJECT ?PREDICATE ?OBJECT WHERE { GRAPH <")
+//				.append(this.getName()).append("> { ")
+//				.append(" ?SUBJECT ?PREDICATE ?OBJECT ");
+//		if (virtSubject != null) {
+//			sb.append(". FILTER( ").append("?SUBJECT = ").append(virtSubject)
+//					.append(") ");
+//		}
+//		if (virtPredicate != null) {
+//			sb.append(". FILTER( ").append("?PREDICATE = ")
+//					.append(virtPredicate).append(") ");
+//		}
+//		if (virtObject != null) {
+//			sb.append(". FILTER( ").append("?OBJECT = ").append(virtObject)
+//					.append(") ");
+//		}
+		
+		sb.append("SPARQL SELECT ");
 		if (virtSubject != null) {
-			sb.append(". FILTER( ").append("?SUBJECT = ").append(virtSubject)
-					.append(") ");
+			sb.append(" ").append(virtSubject).append(" as ?subject");
+		}else{
+			sb.append(" ?subject ");
 		}
 		if (virtPredicate != null) {
-			sb.append(". FILTER( ").append("?PREDICATE = ")
-					.append(virtPredicate).append(") ");
+			sb.append(" ").append(virtPredicate).append(" as ?predicate");
+		}else{
+			sb.append(" ?predicate ");
 		}
 		if (virtObject != null) {
-			sb.append(". FILTER( ").append("?OBJECT = ").append(virtObject)
-					.append(") ");
+			sb.append(" ").append(virtObject).append(" as ?object");
+		}else{
+			sb.append(" ?object ");
+		}
+		sb.append(" WHERE { GRAPH <").append(this.getName()).append("> { ");
+		if (virtSubject != null) {
+			sb.append(" ").append(virtSubject).append(" ");
+		}else{
+			sb.append(" ?subject ");
+		}
+		if (virtPredicate != null) {
+			sb.append(" ").append(virtPredicate).append(" ");
+		}else{
+			sb.append(" ?predicate ");
 		}
+		if (virtObject != null) {
+			sb.append(" ").append(virtObject).append(" ");
+		}else{
+			sb.append(" ?object ");
+		}
+		
 		sb.append(" } } ");
 
 		String sql = sb.toString();
-		logger.debug("Executing SQL: {}", sql);
+		logger.info("Executing SQL: {}", sql);
 		Statement st;
 		try {
 			readLock.lock();
@@ -228,9 +263,11 @@ public class VirtuosoMGraph extends AbstractMGraph implements MGraph,
 			};
 		} catch (VirtuosoException e) {
 			logger.error("ERROR while executing statement", e);
+			logger.error(" executing SQL: {}", sql);
 			throw new RuntimeException(e);
 		} catch (SQLException e) {
 			logger.error("ERROR while executing statement", e);
+			logger.error(" executing SQL: {}", sql);
 			throw new RuntimeException(e);
 		}
 	}
@@ -378,7 +415,9 @@ public class VirtuosoMGraph extends AbstractMGraph implements MGraph,
 		BNode bnode = bnodesMap.get(virtbnode);
 		if (bnode == null) {
 			bnode = new BNode();
-			bnodesMap.put(virtbnode.replaceFirst("nodeID://", "_:"), bnode);
+			// skolemize so we get it in future queries
+			//bnodesMap.put(virtbnode.replaceFirst("nodeID://", "_:"), bnode);
+			bnodesMap.put(new StringBuilder().append('<').append(virtbnode).append('>').toString(),
bnode);
 		}
 		// Subject is BNode
 		return bnode;

http://git-wip-us.apache.org/repos/asf/clerezza/blob/9929bc04/clerezza-virtuoso/rdf.virtuoso.storage/src/test/java/rdf/virtuoso/storage/RdfIOTest.java
----------------------------------------------------------------------
diff --git a/clerezza-virtuoso/rdf.virtuoso.storage/src/test/java/rdf/virtuoso/storage/RdfIOTest.java
b/clerezza-virtuoso/rdf.virtuoso.storage/src/test/java/rdf/virtuoso/storage/RdfIOTest.java
index ef73b2b..71ada50 100644
--- a/clerezza-virtuoso/rdf.virtuoso.storage/src/test/java/rdf/virtuoso/storage/RdfIOTest.java
+++ b/clerezza-virtuoso/rdf.virtuoso.storage/src/test/java/rdf/virtuoso/storage/RdfIOTest.java
@@ -228,5 +228,4 @@ public class RdfIOTest {
 		// bnodes cannot be equals!
 		Assert.assertNotSame(read, new TripleImpl(subject, predicate, object));
 	}
-	
 }

http://git-wip-us.apache.org/repos/asf/clerezza/blob/9929bc04/clerezza-virtuoso/rdf.virtuoso.storage/src/test/java/rdf/virtuoso/storage/VirtuosoMGraphTest.java
----------------------------------------------------------------------
diff --git a/clerezza-virtuoso/rdf.virtuoso.storage/src/test/java/rdf/virtuoso/storage/VirtuosoMGraphTest.java
b/clerezza-virtuoso/rdf.virtuoso.storage/src/test/java/rdf/virtuoso/storage/VirtuosoMGraphTest.java
index 1bc8396..d210bc1 100644
--- a/clerezza-virtuoso/rdf.virtuoso.storage/src/test/java/rdf/virtuoso/storage/VirtuosoMGraphTest.java
+++ b/clerezza-virtuoso/rdf.virtuoso.storage/src/test/java/rdf/virtuoso/storage/VirtuosoMGraphTest.java
@@ -23,6 +23,7 @@ import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
+import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
 import java.util.Iterator;
@@ -151,7 +152,7 @@ public class VirtuosoMGraphTest {
 
 
 	@Test
-	public void testFilterSubjectBnode() {
+	public void testFilterSubjectBnode() throws VirtuosoException, SQLException, ClassNotFoundException
{
 		log.info("testFilterSubjectBnode(); Test filter(s,null,null)");
 		if (TestUtils.SKIP) {
 			log.warn("SKIPPED");
@@ -190,9 +191,14 @@ public class VirtuosoMGraphTest {
 			}
 			assertEquals(t.getPredicate(), predicate);
 		}
+		Statement st = TestUtils.getConnection().createStatement();
+		boolean has = st.execute("SPARQL SELECT ?SUBJECT ?PREDICATE ?OBJECT WHERE { GRAPH <VirtuosoMGraphTest>
{  ?SUBJECT ?PREDICATE ?OBJECT . FILTER( ?SUBJECT = <nodeID://b10076>) . FILTER( ?PREDICATE
= <http://property/name>) . FILTER( ?OBJECT = <nodeID://b10077>)  } } ");
+		assertTrue(has);
+		//rs.close();
 		assertTrue(found);
 		
 		assertNotNull(t);
+		log.info("{} {} {}", new Object[]{t.getSubject(), t.getPredicate(), t.getObject()});
 		
 		//NonLiteral s = t.getSubject();
 		it = mgraph.filter(t.getSubject(), predicate, t.getObject());


Mime
View raw message