Skip to content

Commit

Permalink
rfe8812: Jena Graph compliance tests
Browse files Browse the repository at this point in the history
Added AGGraphTest to exercise 57 tests for Jena Graph compliance,
along with supporting code changes that allow 55 of them to pass.
The remaining 2 tests will be addressed in a future commit.

Tests added for:  AGGraphTest for rfe8812
make test-suite run? no
make prepush run? yes (in agraph-java-client)
  • Loading branch information
Bill Millar authored and dancyatfranz committed Feb 18, 2010
1 parent f221c48 commit 2de6ef7
Show file tree
Hide file tree
Showing 26 changed files with 846 additions and 22 deletions.
11 changes: 11 additions & 0 deletions src/com/franz/agraph/jena/AGBulkUpdateHandler.java
Expand Up @@ -17,6 +17,7 @@

import com.franz.agraph.repository.AGValueFactory;
import com.hp.hpl.jena.graph.BulkUpdateHandler;
import com.hp.hpl.jena.graph.Graph;
import com.hp.hpl.jena.graph.Triple;
import com.hp.hpl.jena.graph.impl.SimpleBulkUpdateHandler;

Expand Down Expand Up @@ -63,4 +64,14 @@ protected void delete(List<Triple> triples, boolean notify) {
if (notify)
manager.notifyDeleteList(graph, triples);
}

@Override
public void removeAll() {
try {
graph.getConnection().clear(graph.getGraphContext());
notifyRemoveAll();
} catch (RepositoryException e) {
throw new RuntimeException(e);
}
}
}
12 changes: 12 additions & 0 deletions src/com/franz/agraph/jena/AGCapabilities.java
@@ -0,0 +1,12 @@
package com.franz.agraph.jena;

import com.hp.hpl.jena.graph.Capabilities;
import com.hp.hpl.jena.graph.impl.AllCapabilities;

public class AGCapabilities extends AllCapabilities implements Capabilities {

@Override
// TODO: "true" would require support for D-entailment
public boolean handlesLiteralTyping() { return false; }

}
69 changes: 61 additions & 8 deletions src/com/franz/agraph/jena/AGGraph.java
Expand Up @@ -8,6 +8,8 @@

package com.franz.agraph.jena;

import java.util.ArrayList;

import org.openrdf.http.protocol.UnauthorizedException;
import org.openrdf.model.Resource;
import org.openrdf.model.Statement;
Expand All @@ -21,7 +23,9 @@
import com.franz.agraph.repository.AGValueFactory;
import com.franz.util.Closeable;
import com.hp.hpl.jena.graph.BulkUpdateHandler;
import com.hp.hpl.jena.graph.Capabilities;
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.TransactionHandler;
import com.hp.hpl.jena.graph.Triple;
Expand All @@ -30,6 +34,7 @@
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.util.iterator.ClosableIterator;
import com.hp.hpl.jena.util.iterator.ExtendedIterator;

public class AGGraph extends GraphBase implements Graph, Closeable {
Expand Down Expand Up @@ -59,6 +64,12 @@ Node getGraphNode() {
return graphNode;
}

public String getGraphName() {
if (graphNode == null)
return "default-graph";
return graphNode.toString();
}

Resource getGraphContext() {
return context;
}
Expand All @@ -67,15 +78,22 @@ AGRepositoryConnection getConnection() {
return conn;
}

@Override
public void close() {
}
//@Override
//public void close() {
//}

@Override
public BulkUpdateHandler getBulkUpdateHandler() {
return new AGBulkUpdateHandler(this);
}

@Override
public Capabilities getCapabilities()
{
if (capabilities == null) capabilities = new AGCapabilities();
return capabilities;
}

@Override
public PrefixMapping getPrefixMapping() {
return new AGPrefixMapping(this);
Expand All @@ -86,12 +104,38 @@ public TransactionHandler getTransactionHandler() {
return new AGTransactionHandler(this);
}

@Override
/*@Override
public String toString() {
if (graphNode == null)
return "default-graph";
return graphNode.toString();
}
}*/
@Override
public String toString()
{ return toString(getGraphName()+(closed ? " (closed) " : " (size: " + graphBaseSize() + ")."),this); }

/**
Answer a human-consumable representation of <code>that</code>. The
string <code>prefix</code> will appear near the beginning of the string. Nodes
may be prefix-compressed using <code>that</code>'s prefix-mapping. This
default implementation will display all the triples exposed by the graph (ie
including reification triples if it is Standard).
*/
public static String toString( String prefix, Graph that )
{
//PrefixMapping pm = that.getPrefixMapping();
StringBuffer b = new StringBuffer( prefix + " {" );
String gap = "";
ClosableIterator<Triple> it = GraphUtil.findAll( that );
while (it.hasNext())
{
b.append( gap );
gap = "; ";
b.append( it.next().toString() );
}
b.append( "}" );
return b.toString();
}

public Dataset getDataset() {
DatasetImpl dataset = new DatasetImpl();
Expand All @@ -114,13 +158,22 @@ public Dataset getDataset() {
protected ExtendedIterator<Triple> graphBaseFind(TripleMatch m) {
RepositoryResult<Statement> result;
try {
result = conn.getStatements(vf.asResource(m.getMatchSubject()), vf
.asURI(m.getMatchPredicate()), vf.asValue(m
// TODO: allow arbitrary values in subject and predicate positions?
Node s = m.getMatchSubject();
Node p = m.getMatchPredicate();
// quickly return no results if RDF constraints for subject and predicate
// are violated, as occurs in the Jena test suite for Graph.
if ((s!=null && s.isLiteral()) ||
(p!=null && (p.isLiteral() || p.isBlank()))) {
result = conn.createRepositoryResult(new ArrayList<Statement>());
} else {
result = conn.getStatements(vf.asResource(s), vf.asURI(p), vf.asValue(m
.getMatchObject()), inferred, context);
}
} catch (RepositoryException e) {
throw new RuntimeException(e);
}
return new AGTripleIterator(result);
return new AGTripleIterator(this, result);
}

@Override
Expand Down
13 changes: 12 additions & 1 deletion src/com/franz/agraph/jena/AGTransactionHandler.java
Expand Up @@ -4,6 +4,7 @@

import com.hp.hpl.jena.graph.TransactionHandler;
import com.hp.hpl.jena.shared.Command;
import com.hp.hpl.jena.shared.JenaException;

public class AGTransactionHandler implements TransactionHandler {

Expand Down Expand Up @@ -48,7 +49,17 @@ public void commit() {

@Override
public Object executeInTransaction(Command c) {
throw new UnsupportedOperationException(AGUnsupportedOperation.message);
try {
begin();
c.execute();
commit();
} catch (Throwable e) {
throw new JenaException(e);
}

// TODO determine what object to return here, currently the
// command is executed for side effects rather than a result.
return null;
}

@Override
Expand Down
21 changes: 14 additions & 7 deletions src/com/franz/agraph/jena/AGTripleIterator.java
Expand Up @@ -19,9 +19,12 @@
public class AGTripleIterator extends NiceIterator<Triple>
implements Closeable {

private RepositoryResult<Statement> result;
private final AGGraph graph;
private final RepositoryResult<Statement> result;
private Statement current = null;

AGTripleIterator(RepositoryResult<Statement> result) {
AGTripleIterator(AGGraph graph, RepositoryResult<Statement> result) {
this.graph = graph;
this.result = result;
}

Expand All @@ -47,7 +50,8 @@ public boolean hasNext() {
public Triple next() {
Triple tr;
try {
tr = AGNodeFactory.asTriple(result.next());
current = result.next();
tr = AGNodeFactory.asTriple(current);
} catch (RepositoryException e) {
throw new RuntimeException(e);
}
Expand All @@ -56,10 +60,13 @@ public Triple next() {

@Override
public void remove() {
try {
result.remove();
} catch (RepositoryException e) {
throw new RuntimeException(e);
if (current != null) {
Triple tr = AGNodeFactory.asTriple(current);
graph.delete(tr);
// TODO the following only removes triples from the underlying
// collection (in memory), rather than from the store.
//result.remove();
current = null;
}
}
}
Expand Up @@ -260,7 +260,7 @@ public RepositoryResult<Resource> getContextIDs()
/**
* Creates a RepositoryResult for the supplied element set.
*/
protected <E> RepositoryResult<E> createRepositoryResult(
public <E> RepositoryResult<E> createRepositoryResult(
Iterable<? extends E> elements) {
return new RepositoryResult<E>(
new CloseableIteratorIteration<E, RepositoryException>(elements
Expand Down
6 changes: 5 additions & 1 deletion src/com/franz/agraph/repository/AGValueFactory.java
Expand Up @@ -102,7 +102,7 @@ public Value asValue(Node node) {
if (node.getLiteralDatatypeURI()!=null) {
URI datatype = createURI(node.getLiteralDatatypeURI());
val = createLiteral(node.getLiteralLexicalForm(), datatype);
} else if (lang!=null && lang!="") {
} else if (lang!=null && !lang.equals("")) {
val = createLiteral(node.getLiteralLexicalForm(),lang);
} else {
// TODO
Expand Down Expand Up @@ -134,6 +134,10 @@ public URI asURI(Node node) {
uri = null;
} else if (node.isURI()) {
uri = createURI(node.getURI());
} else if (node.isBlank()) {
// TODO: research this more, seems to be needed for the test
// suite, as blank nodes appear in the predicate position
uri = createURI("http://anon/" + node.getBlankNodeLabel());
} else {
throw new IllegalArgumentException("Cannot convert Node to URI: " + node);
}
Expand Down
6 changes: 3 additions & 3 deletions src/test/AGAbstractTest.java
Expand Up @@ -72,13 +72,13 @@ private static String findServerUrl1() {

if ((host == null || host.equals("localhost")) && port == null) {
File portFile = new File("../agraph/lisp/agraph.port");
System.out.println("Reading agraph.port: " + portFile.getAbsolutePath());
try {
host = "localhost";
if (portFile.exists()) {
System.out.println("Reading agraph.port: " + portFile.getAbsolutePath());
port = readLines(portFile).get(0);
host = "localhost";
} else {
throw new RuntimeException("PortFile not found.");
port = "10035";
}
} catch (Exception e) {
throw new RuntimeException("Trying to read PortFile: " + portFile.getAbsolutePath(), e);
Expand Down

0 comments on commit 2de6ef7

Please sign in to comment.