<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Wilted buttercup, grey skies, and geek &#187; Java</title>
	<atom:link href="http://mmt.me.uk/blog/tag/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://mmt.me.uk/blog</link>
	<description>Mischa’s ramblings on the interweb</description>
	<lastBuildDate>Fri, 20 Aug 2010 14:28:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>4store and Dan Hanley&#8217;s client libgs</title>
		<link>http://mmt.me.uk/blog/2009/12/13/4store-java/</link>
		<comments>http://mmt.me.uk/blog/2009/12/13/4store-java/#comments</comments>
		<pubDate>Sun, 13 Dec 2009 20:19:22 +0000</pubDate>
		<dc:creator>Mischa Tuffield</dc:creator>
				<category><![CDATA[4store]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[SPARQL]]></category>

		<guid isPermaLink="false">http://mmt.me.uk/blog/?p=130</guid>
		<description><![CDATA[Find below step by step instructions on how to talk to a 4store KB via the SPARQL-Procotol in Java, using Dan Hanley&#8217;s 4store client libs. First of all you need to have the following installed : 4store A java compiler (i have Sun&#8217;s Java SDK 1.6.x installed on my laptop) Maven (to compile Dan Hanley&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>Find below step by step instructions on how to talk to a <a href="http://4store.org/">4store</a> KB via the <a href="http://www.w3.org/TR/rdf-sparql-protocol/">SPARQL-Procotol</a> in Java, using <a href="http://github.com/danhanley/4store-java-client">Dan Hanley&#8217;s 4store client libs</a>.</p>
<p>First of all you need to have the following installed :<br />
4store<br />
A java compiler (i have<a href="http://java.sun.com/javase/downloads/widget/jdk6.jsp"> Sun&#8217;s Java SDK 1.6.x</a> installed on my laptop)<br />
<a href="http://maven.apache.org/">Maven</a> (to compile Dan Hanley&#8217;s 4store client libs). </p>
<p>I have all of the code needed for this example placed on my site here : <a href="http://mmt.me.uk/examples/4store-java-query-example/">http://mmt.me.uk/examples/4store-java-query-example/</a>  feel free to grab and use it as you wish.</p>
<p>First of all, I should say that I have had to patch the 4store-client-library, as it seems to chomp all of the carriage returns at the end of the lines (&#8220;\n&#8221;).  This is fine you are using the <a href="http://www.w3.org/TR/rdf-sparql-XMLres/">SPARQL-XML-RESULT format</a>, by I am a tad lazy and much prefer working with the <a href="http://en.wikipedia.org/wiki/Delimiter-separated_values">tsv</a> format: tsv requires line breaks.</p>
<p>The git diff of my patch looks like so (and again yes it is a tad dirty) :<br />
<code><br />
diff --git a/src/main/java/uk/co/magus/fourstore/client/Store.java b/src/main/java/uk/co/magus/fourstore/clie<br />
index 6652874..097be43 100644<br />
--- a/src/main/java/uk/co/magus/fourstore/client/Store.java<br />
+++ b/src/main/java/uk/co/magus/fourstore/client/Store.java<br />
@@ -349,7 +349,7 @@ public class Store {<br />
                String response = "";<br />
                String str;<br />
                while (null != ((str = in.readLine()))) {<br />
-                       response += str;<br />
+                       response += str+"\n";<br />
                }<br />
                in.close();<br />
                return response;<br />
~<br />
~<br />
</code></p>
<p>This above <a href="http://mmt.me.uk/examples/4store-java-query-example/patch.txt">patch</a> allows me to make use of the TSV output as needed. The patch can be grabbed from here : <a href="http://mmt.me.uk/examples/4store-java-query-example/patch.txt">http://mmt.me.uk/examples/4store-java-query-example/patch.txt</a>.</p>
<p>Ok, now that I have built the <a href="http://mmt.me.uk/examples/4store-java-query-example/4store-client-1.0.jar">4store-client.jar</a> file with my patch using the instructions in the <a href="http://github.com/danhanley/4store-java-client">git repo</a>. I create an example RDF file, and some example java code which will query the 4store KB. All the files can be found on my site <a href="http://mmt.me.uk/examples/4store-java-query-example/">http://mmt.me.uk/examples/4store-java-query-example/</a>.</p>
<p>These are the steps which I have taken to get this little demo up and running :<br />
<strong>1. Create 4store KB called <em>lame</em> </strong><br />
<code><br />
4s-backend-setup --node 0 --cluster 1 --segments 2 lame<br />
</code></p>
<p><strong>2. Start <em>lame</em>&#8216;s backend (i.e. start the KB)</strong><br />
<code><br />
4s-backend lame<br />
</code></p>
<p><strong>3. Import the <a href="http://mmt.me.uk/examples/4store-java-query-example/example.rdf">example.rdf</a> file into <em>lame</em>&#8216;s backend (i.e. start the KB)</strong><br />
<code><br />
4s-import lame example.rdf<br />
</code></p>
<p><strong>4. Start HTTPD for the KB named <em>lame</em></strong><br />
<code><br />
4s-httpd -s -1 lame<br />
</code></p>
<p><strong>And then I need to compile the <a href="http://mmt.me.uk/examples/4store-java-query-example/exampleQuery.java">exampleQuery</a> code I knocked together</strong><br />
<code><br />
javac -cp 4store-client-1.0.jar exampleQuery.java<br />
</code></p>
<p><strong>Finally, I run the code like so : </strong><br />
<code><br />
java -cp 4store-client-1.0.jar:. exampleQuery<br />
</code></p>
<p><strong>Resulting in the following output: </strong><br />
<code><br />
Am about to query a sparql endpoint<br />
A user name is:"Bob"<br />
A user name is:"Alice"<br />
</code></p>
<p>I hope this helps!</p>
]]></content:encoded>
			<wfw:commentRss>http://mmt.me.uk/blog/2009/12/13/4store-java/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
