Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

bug19798: Illegal resource in Jena reified statememts

<release-note>
bug19798: Illegal resource in Jena reified statememts

Previously, the Jena adapter's createReifiedStatement method
could create reified statements containing illegal blank node
ids that were based on generated UUIDs, manifesting in invalid
part errors from the server.  With this change, these reified
statements are now created using legal resources.  AGGraphMaker
instances can now be created with a specified ReificationStyle
(the default style is ReificationStyle.Minimal).
</release-note>

Added AGReifierTest and ReifiedStatementTests.
make prepush passes.
ant jena-compliance-tests passes.

Change-Id: I0636a5830793f12396141bb4b7a992e85fb7bf9a
Reviewed-on: https://gerrit.franz.com:9080/1597
Reviewed-by: Ahmon Dancy <dancy@franz.com>
Reviewed-by: John O'Rourke <jor@franz.com>
Tested-by: Kevin Layer <layer@franz.com>
  • Loading branch information...
commit b304c16e8e597fd623d6dcd1905217889f43241a 1 parent 014b158
Bill Millar authored dklayer committed
View
6 .classpath
@@ -4,11 +4,11 @@
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="lib/junit-4.8.1.jar" sourcepath="lib/junit-4.8.1-src.jar"/>
<classpathentry kind="lib" path="lib/commons-cli-1.2.jar"/>
- <classpathentry kind="lib" path="lib/jena-2.6.2/arq-2.8.1.jar" sourcepath="lib/jena-2.6.2/src/arq-2.8.1-sources.jar"/>
+ <classpathentry kind="lib" path="lib/jena-2.6.2/arq-2.8.1.jar" sourcepath="lib/jena-2.6.2/arq-2.8.1-sources.jar"/>
<classpathentry kind="lib" path="lib/jena-2.6.2/icu4j-3.4.4.jar"/>
<classpathentry kind="lib" path="lib/jena-2.6.2/iri-0.7.jar"/>
- <classpathentry kind="lib" path="lib/jena-2.6.2/jena-2.6.2-tests.jar" sourcepath="lib/jena-2.6.2/src/jena-2.6.2-test-sources.jar"/>
- <classpathentry kind="lib" path="lib/jena-2.6.2/jena-2.6.2.jar" sourcepath="lib/jena-2.6.2/src/jena-2.6.2-sources.jar"/>
+ <classpathentry kind="lib" path="lib/jena-2.6.2/jena-2.6.2-tests.jar" sourcepath="lib/jena-2.6.2/jena-2.6.2-test-sources.jar"/>
+ <classpathentry kind="lib" path="lib/jena-2.6.2/jena-2.6.2.jar" sourcepath="lib/jena-2.6.2/jena-2.6.2-sources.jar"/>
<classpathentry kind="lib" path="lib/jena-2.6.2/lucene-core-2.3.1.jar"/>
<classpathentry kind="lib" path="lib/jena-2.6.2/stax-api-1.0.1.jar"/>
<classpathentry kind="lib" path="lib/jena-2.6.2/wstx-asl-3.2.9.jar"/>
View
100 src/com/franz/agraph/jena/AGGraph.java
@@ -30,15 +30,22 @@
import com.hp.hpl.jena.graph.Graph;
import com.hp.hpl.jena.graph.GraphUtil;
import com.hp.hpl.jena.graph.Node;
+import com.hp.hpl.jena.graph.Reifier;
import com.hp.hpl.jena.graph.TransactionHandler;
import com.hp.hpl.jena.graph.Triple;
import com.hp.hpl.jena.graph.TripleMatch;
import com.hp.hpl.jena.graph.impl.GraphBase;
+import com.hp.hpl.jena.graph.impl.ReifierFragmentHandler;
+import com.hp.hpl.jena.graph.impl.ReifierFragmentsMap;
+import com.hp.hpl.jena.graph.impl.ReifierTripleMap;
+import com.hp.hpl.jena.graph.impl.SimpleReifier;
import com.hp.hpl.jena.shared.AddDeniedException;
import com.hp.hpl.jena.shared.DeleteDeniedException;
import com.hp.hpl.jena.shared.PrefixMapping;
+import com.hp.hpl.jena.shared.ReificationStyle;
import com.hp.hpl.jena.util.iterator.ClosableIterator;
import com.hp.hpl.jena.util.iterator.ExtendedIterator;
+import com.hp.hpl.jena.util.iterator.NullIterator;
/**
* Implements the Jena Graph interface for AllegroGraph.
@@ -57,6 +64,7 @@
protected String entailmentRegime = "false";
AGGraph(AGGraphMaker maker, Node graphNode) {
+ super(maker.getReificationStyle());
this.maker = maker;
this.graphNode = graphNode;
conn = maker.getRepositoryConnection();
@@ -66,6 +74,7 @@
}
AGGraph(AGGraphMaker maker, Resource context, Resource... contexts) {
+ super(maker.getReificationStyle());
this.maker = maker;
this.graphNode = null;
this.conn = maker.getRepositoryConnection();
@@ -248,4 +257,95 @@ protected int graphBaseSize() {
return size;
}
+ @Override
+ protected Reifier constructReifier() {
+ if (!style.intercepts() && !style.conceals()) {
+ return new SimpleReifier( this, new EmptyReifierTripleMap(), new EmptyReifierFragmentsMap(), style );
+ } else {
+ return new SimpleReifier( this, style );
+ }
+ }
+
+ class EmptyReifierTripleMap implements ReifierTripleMap {
+
+ @Override
+ public Triple getTriple(Node tag) {
+ return null;
+ }
+
+ @Override
+ public boolean hasTriple(Triple t) {
+ return false;
+ }
+
+ @Override
+ public Triple putTriple(Node key, Triple value) {
+ return null;
+ }
+
+ @Override
+ public void removeTriple(Node key) {
+ }
+
+ @Override
+ public void removeTriple(Node key, Triple value) {
+ }
+
+ @Override
+ public void removeTriple(Triple triple) {
+ }
+
+ @Override
+ public ExtendedIterator<Triple> find(TripleMatch m) {
+ return NullIterator.instance();
+ }
+
+ @Override
+ public int size() {
+ return 0;
+ }
+
+ @Override
+ public ExtendedIterator<Node> tagIterator() {
+ return NullIterator.instance();
+ }
+
+ @Override
+ public ExtendedIterator<Node> tagIterator(Triple t) {
+ return NullIterator.instance();
+ }
+
+ @Override
+ public void clear() {
+ }
+
+ }
+
+ class EmptyReifierFragmentsMap implements ReifierFragmentsMap {
+
+ @Override
+ public ExtendedIterator<Triple> find(TripleMatch m) {
+ return NullIterator.instance();
+ }
+
+ @Override
+ public int size() {
+ return 0;
+ }
+
+ @Override
+ public ReifierFragmentHandler getFragmentHandler(Triple fragment) {
+ return null;
+ }
+
+ @Override
+ public boolean hasFragments(Node tag) {
+ return false;
+ }
+
+ @Override
+ public void clear() {
+ }
+
+ }
}
View
9 src/com/franz/agraph/jena/AGGraphMaker.java
@@ -35,6 +35,7 @@
public class AGGraphMaker implements GraphMaker, Closeable {
private AGRepositoryConnection conn;
+ private ReificationStyle style;
private AGGraph defaultGraph;
// TODO make this persistent?
@@ -42,8 +43,14 @@
public AGGraphMaker(AGRepositoryConnection conn) {
this.conn = conn;
+ this.style = ReificationStyle.Minimal;
}
+ public AGGraphMaker(AGRepositoryConnection conn, ReificationStyle style) {
+ this.conn = conn;
+ this.style = style;
+ }
+
public AGRepositoryConnection getRepositoryConnection() {
return conn;
}
@@ -99,7 +106,7 @@ private String absUriFromString(String name) {
@Override
public ReificationStyle getReificationStyle() {
- return ReificationStyle.Minimal;
+ return style;
}
@Override
View
84 src/com/franz/agraph/jena/AGModel.java
@@ -19,9 +19,13 @@
import com.franz.agraph.repository.AGRDFFormat;
import com.franz.agraph.repository.AGValueFactory;
import com.franz.util.Closeable;
+import com.hp.hpl.jena.graph.Triple;
import com.hp.hpl.jena.rdf.model.AnonId;
import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.Property;
+import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.rdf.model.Resource;
+import com.hp.hpl.jena.rdf.model.Statement;
import com.hp.hpl.jena.rdf.model.impl.ModelCom;
/**
@@ -77,4 +81,84 @@ public Resource createResource() {
BNode blank = vf.createBNode();
return createResource(new AnonId(blank.stringValue()));
}
+
+
+ /*
+ * Override methods involving StatementImpls,
+ * instead using AGStatements.
+ */
+
+ @Override
+ public AGModel add( Statement [] statements ) {
+ getBulkUpdateHandler().add( AGStatement.asTriples( statements ) );
+ return this;
+ }
+
+ @Override
+ public AGModel remove( Statement [] statements ) {
+ getBulkUpdateHandler().delete( AGStatement.asTriples( statements ) );
+ return this;
+ }
+
+ @Override
+ public AGStatement createStatement(Resource r, Property p, RDFNode o) {
+ return new AGStatement(r, p, o, this );
+ }
+
+ @Override
+ public Statement asStatement( Triple t ) {
+ return AGStatement.toStatement( t, this );
+ }
+
+ /*
+ * Override Reification methods
+ */
+
+ /**
+ A mapper that maps modes to their corresponding ReifiedStatement objects. This
+ cannot be static: getRS cannot be static, because the mapping is model-specific.
+ protected final Map1<QuerySolution, ReifiedStatement> mapToRS = new Map1<QuerySolution, ReifiedStatement>()
+ {
+ public ReifiedStatement map1( QuerySolution result ) {
+ return getRS( result.get("s").asNode() );
+ }
+ };
+ */
+
+ /**
+ Answer a ReifiedStatement that is based on the given node.
+ @param n the node which represents the reification (and is bound to some triple t)
+ @return a ReifiedStatement associating the resource of n with the statement of t.
+ private ReifiedStatement getRS( Node n ) {
+ return ReifiedStatementImpl.createExistingReifiedStatement( this, n );
+ }
+ */
+
+
+ /**
+ @return an iterator which delivers all the ReifiedStatements in this model
+ public RSIterator listReifiedStatements() {
+ String queryString = "SELECT ?s WHERE {?s a rdf:Statement .}";
+ AGQuery sparql = AGQueryFactory.create(queryString);
+ QueryExecution qe = AGQueryExecutionFactory.create(sparql, this);
+ ResultSet results;
+ try {
+ results = qe.execSelect();
+ } finally {
+ qe.close();
+ }
+ return new RSIteratorImpl(new NiceIterator<QuerySolution>().andThen(results).mapWith(mapToRS));
+ }
+ */
+
+ /**
+ @return an iterator each of whose elements is a ReifiedStatement in this
+ model such that it's getStatement().equals( st )
+ public RSIterator listReifiedStatements( final Statement st ) {
+ Filter<ReifiedStatement> f = new Filter<ReifiedStatement>() {public boolean accept(ReifiedStatement rs) {return rs.getStatement().equals(st);};};
+ return new RSIteratorImpl(listReifiedStatements().filterKeep(f));
+ }
+ */
+
+
}
View
53 src/com/franz/agraph/jena/AGStatement.java
@@ -0,0 +1,53 @@
+package com.franz.agraph.jena;
+
+import com.hp.hpl.jena.graph.Triple;
+import com.hp.hpl.jena.rdf.model.Property;
+import com.hp.hpl.jena.rdf.model.RDFNode;
+import com.hp.hpl.jena.rdf.model.ReifiedStatement;
+import com.hp.hpl.jena.rdf.model.Resource;
+import com.hp.hpl.jena.rdf.model.Statement;
+import com.hp.hpl.jena.rdf.model.impl.PropertyImpl;
+import com.hp.hpl.jena.rdf.model.impl.ResourceImpl;
+import com.hp.hpl.jena.rdf.model.impl.StatementImpl;
+
+public class AGStatement extends StatementImpl {
+
+ public AGStatement(Resource subject, Property predicate, RDFNode object) {
+ super(subject, predicate, object);
+ }
+
+ public AGStatement(Resource subject, Property predicate, RDFNode object,
+ AGModel model) {
+ super(subject, predicate, object, model);
+ }
+
+ @Override
+ public AGModel getModel() {
+ return (AGModel)super.getModel();
+ }
+
+ private static long reifiedStatementId = 0;
+
+ /**
+ create a ReifiedStatement corresponding to this Statement
+ */
+ @Override
+ public synchronized ReifiedStatement createReifiedStatement() {
+ reifiedStatementId++;
+ return createReifiedStatement("urn:x-agraph:reifiedStatement"+reifiedStatementId);
+ }
+
+ /**
+ * create a Statement from the triple _t_ in the enhanced graph _eg_. The
+ * Statement has subject, predicate, and object corresponding to those of
+ * _t_.
+ */
+ public static Statement toStatement( Triple t, AGModel eg )
+ {
+ Resource s = new ResourceImpl( t.getSubject(), eg );
+ Property p = new PropertyImpl( t.getPredicate(), eg );
+ RDFNode o = createObject( t.getObject(), eg );
+ return new AGStatement( s, p, o, eg );
+ }
+
+}
View
114 src/test/AGReifierTest.java
@@ -0,0 +1,114 @@
+/******************************************************************************
+** Copyright (c) 2008-2011 Franz Inc.
+** All rights reserved. This program and the accompanying materials
+** are made available under the terms of the Eclipse Public License v1.0
+** which accompanies this distribution, and is available at
+** http://www.eclipse.org/legal/epl-v10.html
+******************************************************************************/
+
+package test;
+
+import junit.extensions.TestSetup;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.openrdf.repository.RepositoryException;
+
+import com.franz.agraph.jena.AGGraphMaker;
+import com.franz.agraph.repository.AGCatalog;
+import com.franz.agraph.repository.AGRepository;
+import com.franz.agraph.repository.AGRepositoryConnection;
+import com.franz.agraph.repository.AGServer;
+import com.hp.hpl.jena.graph.Graph;
+import com.hp.hpl.jena.graph.GraphMaker;
+import com.hp.hpl.jena.graph.test.AbstractTestReifier;
+import com.hp.hpl.jena.shared.ReificationStyle;
+
+public class AGReifierTest extends AbstractTestReifier {
+
+ public static String SERVER_URL = System.getProperty(
+ "com.franz.agraph.test.serverURL", "http://localhost:10035");
+ public static String CATALOG_ID = System.getProperty(
+ "com.franz.agraph.test.catalogID", "/");
+ public static String REPOSITORY_ID = System.getProperty(
+ "com.franz.agraph.test.repositoryID", "testRepo");
+ public static String USERNAME = System.getProperty(
+ "com.franz.agraph.test.username", "test");
+ public static String PASSWORD = System.getProperty(
+ "com.franz.agraph.test.password", "xyzzy");
+
+ protected static AGRepositoryConnection conn = null;
+ protected static AGGraphMaker maker = null;
+
+ private static int graphId = 0;
+
+
+ public AGReifierTest(String name) {
+ super(name);
+ }
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite();
+ suite.addTestSuite(AGReifierTest.class);
+
+ TestSetup wrapper = new TestSetup(suite) {
+ protected void setUp() {
+ setUpOnce();
+ }
+
+ protected void tearDown() {
+ tearDownOnce();
+ }
+ };
+
+ return wrapper;
+ }
+
+ public static void setUpOnce() {
+ AGServer server = new AGServer(SERVER_URL, USERNAME, PASSWORD);
+ AGCatalog catalog = server.getRootCatalog();
+ try {
+ catalog.deleteRepository(REPOSITORY_ID);
+ AGRepository repo = catalog.createRepository(REPOSITORY_ID);
+ repo.initialize();
+ conn = repo.getConnection();
+ maker = new AGGraphMaker(conn);
+ } catch (RepositoryException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public void setUp() {
+ try {
+ conn.clear();
+ } catch (RepositoryException e) {
+ throw new RuntimeException("Unable to clear connection.");
+ }
+ }
+
+ public static void tearDownOnce() {
+ try {
+ conn.close();
+ } catch (RepositoryException e) {
+ throw new RuntimeException("Unable to close connection.");
+ }
+ }
+
+ @Override
+ public Graph getGraph() {
+ Graph graph = maker.createGraph("http://named" + graphId);
+ graphId++;
+ return graph;
+ }
+
+
+ @Override
+ public Graph getGraph(ReificationStyle style) {
+ GraphMaker maker = new AGGraphMaker(conn,style);
+ Graph graph = maker.createGraph("http://named" + graphId);
+ graphId++;
+ return graph;
+ }
+
+}
View
166 src/test/ReifiedStatementTest.java
@@ -0,0 +1,166 @@
+package test;
+
+import org.junit.Test;
+import org.openrdf.model.URI;
+
+import com.franz.agraph.jena.AGGraph;
+import com.franz.agraph.jena.AGGraphMaker;
+import com.franz.agraph.jena.AGModel;
+import com.franz.agraph.repository.AGCatalog;
+import com.franz.agraph.repository.AGRepository;
+import com.franz.agraph.repository.AGRepositoryConnection;
+import com.franz.agraph.repository.AGServer;
+import com.hp.hpl.jena.rdf.model.Literal;
+import com.hp.hpl.jena.rdf.model.Property;
+import com.hp.hpl.jena.rdf.model.RSIterator;
+import com.hp.hpl.jena.rdf.model.ReifiedStatement;
+import com.hp.hpl.jena.rdf.model.Resource;
+import com.hp.hpl.jena.rdf.model.ResourceFactory;
+import com.hp.hpl.jena.rdf.model.Statement;
+import com.hp.hpl.jena.rdf.model.StmtIterator;
+import com.hp.hpl.jena.shared.ReificationStyle;
+import com.hp.hpl.jena.vocabulary.RDF;
+
+public class ReifiedStatementTest extends AGAbstractTest {
+
+ @Test
+ public void test1() throws Exception {
+
+ AGServer server = new AGServer(findServerUrl(), username(), password());
+ AGCatalog catalog = server.getRootCatalog();
+ catalog.deleteRepository("foo");
+ AGRepository myRepository = catalog.createRepository("foo");
+ myRepository.initialize();
+ AGRepositoryConnection conn = myRepository.getConnection();
+
+ AGGraphMaker maker = new AGGraphMaker(conn, ReificationStyle.Standard);
+
+ AGGraph graph = maker.getGraph();
+ AGModel model = new AGModel(graph);
+ String exns = "http://example.org/people/";
+ model.setNsPrefix("ex", exns);
+ // Create index1
+ Property fullname = model.createProperty(exns + "fullname");
+
+ conn.createFreetextIndex("index1", new URI[] { conn.getValueFactory()
+ .createURI(exns + "fullname") });
+ // Create parts of person resources.
+ Resource alice = model.createResource(exns + "alice1");
+ Resource carroll = model.createResource(exns + "carroll");
+ Resource persontype = model.createResource(exns + "Person");
+ Literal alicename = model.createLiteral("Alice B. Toklas");
+ Literal lewisCarroll = model.createLiteral("Lewis Carroll");
+ // Create parts of book resources.
+ Resource book = model.createResource(exns + "book1");
+ Resource booktype = model.createResource(exns + "Book");
+ Property booktitle = model.createProperty(exns + "title");
+ Property author = model.createProperty(exns + "author");
+ Literal wonderland = model.createLiteral("Alice in Wonderland");
+ // Add Alice B. Toklas triples
+ model.add(alice, RDF.type, persontype);
+ Statement stmt = model.createStatement(alice, fullname, alicename);
+ //model.add(stmt);
+
+ // reify statement [http://example.org/people/alice1,
+ // http://example.org/people/fullname, "Alice B. Toklas"]
+ ReifiedStatement rs = stmt.createReifiedStatement();
+ rs.addProperty(ResourceFactory.createProperty("urn:foo:fooProperty"),
+ "FOOBAR");
+ // Add Alice in Wonderland triples
+ model.add(book, RDF.type, booktype);
+ model.add(book, booktitle, wonderland);
+ model.add(book, author, carroll);
+ // Add Lewis Carroll triples
+ model.add(carroll, RDF.type, persontype);
+ model.add(carroll, fullname, lewisCarroll);
+ // Check triples
+
+ StmtIterator statements = model.listStatements();
+ try {
+ while (statements.hasNext()) {
+ System.out.println(statements.next());
+ }
+ } finally {
+ statements.close();
+ }
+
+ System.out.println("\nN-TRIPLE output:");
+ model.write(System.out, "N-TRIPLE");
+ long l = model.size();
+ System.out.println("Number of stmts: " + l);
+ }
+
+ @Test
+ public void test2() throws Exception {
+
+ AGServer server = new AGServer(findServerUrl(), username(), password());
+ AGCatalog catalog = server.getRootCatalog();
+ catalog.deleteRepository("foo");
+ AGRepository myRepository = catalog.createRepository("foo");
+ myRepository.initialize();
+ AGRepositoryConnection conn = myRepository.getConnection();
+
+ AGGraphMaker maker = new AGGraphMaker(conn,ReificationStyle.Standard);
+
+ AGGraph graph = maker.getGraph();
+ AGModel model = new AGModel(graph);
+ String exns = "http://example.org/people/";
+ model.setNsPrefix("ex", exns);
+ // Create index1
+ Property fullname = model.createProperty(exns + "fullname");
+
+ conn.createFreetextIndex("index1", new URI[] { conn.getValueFactory()
+ .createURI(exns + "fullname") });
+ // Create parts of person resources.
+ Resource alice = model.createResource(exns + "alice1");
+ Resource carroll = model.createResource(exns + "carroll");
+ Resource persontype = model.createResource(exns + "Person");
+ Literal alicename = model.createLiteral("Alice B. Toklas");
+ Literal lewisCarroll = model.createLiteral("Lewis Carroll");
+ // Create parts of book resources.
+ Resource book = model.createResource(exns + "book1");
+ Resource booktype = model.createResource(exns + "Book");
+ Property booktitle = model.createProperty(exns + "title");
+ Property author = model.createProperty(exns + "author");
+ Literal wonderland = model.createLiteral("Alice in Wonderland");
+ // Add Alice B. Toklas triples
+ model.add(alice, RDF.type, persontype);
+ Statement stmt = model.createStatement(alice, fullname, alicename);
+ //model.add(stmt);
+
+ // reify statement [http://example.org/people/alice1,
+ // http://example.org/people/fullname, "Alice B. Toklas"]
+ ReifiedStatement rs = stmt.createReifiedStatement();
+ rs.addProperty(ResourceFactory.createProperty("urn:foo:fooProperty"),
+ "FOOBAR");
+ // Add Alice in Wonderland triples
+ model.add(book, RDF.type, booktype);
+ model.add(book, booktitle, wonderland);
+ model.add(book, author, carroll);
+ // Add Lewis Carroll triples
+ model.add(carroll, RDF.type, persontype);
+ model.add(carroll, fullname, lewisCarroll);
+
+ StmtIterator statements = model.listStatements();
+ try {
+ while (statements.hasNext()) {
+ System.out.println(statements.next());
+ }
+ } finally {
+ statements.close();
+ }
+
+ // try to get the reification triple:
+ System.out.println("Reified Statements:");
+ RSIterator iter = stmt.listReifiedStatements();
+ while (iter.hasNext()) {
+ ReifiedStatement rs1 = iter.next();
+ System.out.println(rs1);
+
+ System.out.println("listProperties:");
+ StmtIterator iter1 = rs1.listProperties();
+ while (iter1.hasNext()) {
+ System.out.println(iter1.next());
+ }
+ }
+ }}
Please sign in to comment.
Something went wrong with that request. Please try again.