Permalink
Browse files

rfe10452: support N-Quads responses in the Java client

<release-note>
rfe10452: support N-Quads responses in the Java client

With this change, the Java client now supports N-Quads responses from the
server.  The property -Dcom.franz.agraph.http.defaultRDFFormat=NQUADS can
now be used to configure the client to request N-Quads format by default
for RDF statement responses; when this property is not present, the default
format is TriX.  The method AGHttpRepoClient#setPreferredRDFFormat() can
also be used to override the default RDFFormat on a per connection basis.
</release-note>

'make prepush' passes (default still uses TriX)
'make -Dcom.franz.agraph.http.defaultRDFFormat=NQUADS prepush' passes
'ant tutorial' runs (default still using TriX)
'ant  -Dcom.franz.agraph.http.defaultRDFFormat=NQUADS tutorial' runs
A small events test passes with both TriX and NQUADS, using options:
--catalog java-tutorial --load 2 --query 2 --time 1 --size 10000
'make javadoc' runs clean

Performance:

The default RDFFormat of the client is still TriX.  When using the
option -Dcom.franz.agraph.http.defaultRDFFormat=NQUADS with make
prepush, ant tutorial, and a small events test, the performance is
comparable to marginally faster; if the performance on larger tests
is also comparable or faster, the default may be changed to NQUADS
in future.

Change-Id: I3d22315f5e3b12f7e7d901ee99cdf110a647b5a7
Reviewed-on: https://gerrit.franz.com:9080/1391
Reviewed-by: John O'Rourke <jor@franz.com>
Reviewed-by: Ahmon Dancy <dancy@franz.com>
Tested-by: Kevin Layer <layer@franz.com>
  • Loading branch information...
1 parent 1de745e commit 3b58e048847716cf2803f27bc9a7ccabfbff9820 Bill Millar committed with dklayer Apr 15, 2011
View
@@ -171,7 +171,7 @@
noindex="false"
nonavbar="false"
notree="false"
- packagenames="com.franz.agraph.jena,com.franz.util,com.franz.agraph.repository"
+ packagenames="com.franz.agraph.jena,com.franz.agraph.repository,com.franz.openrdf.rio.nquads,com.franz.util"
source="1.6"
sourcepath="src"
splitindex="true"
@@ -62,6 +62,7 @@
import com.franz.agraph.repository.AGCustomStoredProcException;
import com.franz.agraph.repository.AGQuery;
+import com.franz.agraph.repository.AGRDFFormat;
import com.franz.util.Closeable;
/**
@@ -107,7 +108,7 @@ public static void setDefaultSessionLifetime(int lifetimeInSeconds)
// TODO: choose proper defaults
private TupleQueryResultFormat preferredTQRFormat = TupleQueryResultFormat.SPARQL;
private BooleanQueryResultFormat preferredBQRFormat = BooleanQueryResultFormat.TEXT;
- private RDFFormat preferredRDFFormat = RDFFormat.TRIX;
+ private RDFFormat preferredRDFFormat = getDefaultRDFFormat();
private AGHTTPClient client;
private Repository repo;
@@ -188,11 +189,45 @@ public void setPreferredBQRFormat(
this.preferredBQRFormat = preferredBQRFormat;
}
+ /**
+ * Gets the default RDFFormat to use in making requests that
+ * return RDF statements; the format should support contexts.
+ *
+ * Gets System property com.franz.agraph.http.defaultRDFFormat
+ * (NQUADS and TRIX are currently supported), defaults to TRIX
+ * if the property is not present, and returns the corresponding
+ * RDFFormat.
+ *
+ * @return an RDFFormat, either NQUADS or TRIX
+ */
+ public RDFFormat getDefaultRDFFormat() {
+ RDFFormat format = System.getProperty("com.franz.agraph.http.defaultRDFFormat","TRIX").equalsIgnoreCase("NQUADS") ? AGRDFFormat.NQUADS : RDFFormat.TRIX;
+ logger.debug("Defaulting to " + format.getDefaultMIMEType() + " for requests that return RDF statements.");
+ return format;
+ }
+
+ /**
+ * Gets the RDFFormat to use in making requests that return
+ * RDF statements.
+ *
+ * Defaults to the format returned by {@link getDefaultRDFFormat()}
+ *
+ * @return an RDFFormat, either NQUADS or TRIX
+ */
public RDFFormat getPreferredRDFFormat() {
return preferredRDFFormat;
}
+ /**
+ * Sets the RDFFormat to use in making requests that return
+ * RDF statements; the format should support contexts.
+ *
+ * AGRDFFormat.NQUADS and RDFFormat.TRIX are currently supported.
+ * Defaults to the format returned by {@link getDefaultRDFFormat()}
+ *
+ */
public void setPreferredRDFFormat(RDFFormat preferredRDFFormat) {
+ logger.debug("Defaulting to " + preferredRDFFormat.getDefaultMIMEType() + " for requests that return RDF statements.");
this.preferredRDFFormat = preferredRDFFormat;
}
@@ -149,10 +149,7 @@ public void handleResponse(HttpMethod method) throws IOException, RepositoryExce
String mimeType = getResponseMIMEType(method);
try {
if (rdfhandler != null) {
- RDFFormat format = RDFFormat.forMIMEType(mimeType, RDFFormat.TRIX);
- // TODO:
- // .matchMIMEType(mimeType,
- // rdfFormats);
+ RDFFormat format = RDFFormat.forMIMEType(mimeType);
RDFParser parser = Rio.createParser(format, repository.getValueFactory());
parser.setPreserveBNodeIDs(true);
parser.setRDFHandler(rdfhandler);
@@ -12,7 +12,6 @@
import org.openrdf.query.QueryEvaluationException;
import org.openrdf.repository.RepositoryException;
import org.openrdf.repository.RepositoryResult;
-import org.openrdf.rio.RDFFormat;
import org.openrdf.rio.RDFHandler;
import org.openrdf.rio.RDFHandlerException;
import org.openrdf.rio.helpers.StatementCollector;
@@ -77,8 +76,8 @@ public void evaluate(RDFHandler handler) throws QueryEvaluationException,
RDFHandlerException {
try {
conn.getHttpRepoClient().evalFreetextQuery(pattern, expression, index, sorted, limit, offset,
- new AGResponseHandler(conn.getRepository(), handler,
- RDFFormat.TRIX));
+ new AGResponseHandler(conn.getRepository(), handler,
+ conn.getHttpRepoClient().getPreferredRDFFormat()));
} catch (RepositoryException e) {
throw new QueryEvaluationException(e);
}
@@ -0,0 +1,7 @@
+org.openrdf.rio.n3.N3ParserFactory
+org.openrdf.rio.ntriples.NTriplesParserFactory
+org.openrdf.rio.rdfxml.RDFXMLParserFactory
+org.openrdf.rio.trig.TriGParserFactory
+org.openrdf.rio.trix.TriXParserFactory
+org.openrdf.rio.turtle.TurtleParserFactory
+com.franz.openrdf.rio.nquads.NQuadsParserFactory
@@ -0,0 +1,7 @@
+org.openrdf.rio.n3.N3WriterFactory
+org.openrdf.rio.ntriples.NTriplesWriterFactory
+org.openrdf.rio.rdfxml.RDFXMLWriterFactory
+org.openrdf.rio.trig.TriGWriterFactory
+org.openrdf.rio.trix.TriXWriterFactory
+org.openrdf.rio.turtle.TurtleWriterFactory
+com.franz.openrdf.rio.nquads.NQuadsWriterFactory
@@ -0,0 +1,30 @@
+/******************************************************************************
+** 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 com.franz.openrdf.rio.nquads;
+
+import org.openrdf.rio.RDFFormat;
+import org.openrdf.rio.RDFParserRegistry;
+
+import java.nio.charset.Charset;
+
+/**
+ * An {@link RDFFormat} for N-Quads.
+ *
+ */
+public class NQuadsFormat extends RDFFormat {
+ public static NQuadsFormat NQUADS = new NQuadsFormat();
+
+ static {
+ RDFParserRegistry.getInstance().add(new NQuadsParserFactory());
+ }
+
+ private NQuadsFormat() {
+ super("N-Quads", "text/x-nquads", Charset.forName("US-ASCII"), "nq", true, true);
+
+ }
+}
Oops, something went wrong.

0 comments on commit 3b58e04

Please sign in to comment.