<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-6848574</atom:id><lastBuildDate>Wed, 30 May 2012 01:29:43 +0000</lastBuildDate><category>π</category><category>JRDF</category><category>class path</category><category>Lucene</category><category>description logic</category><category>SKOS</category><category>MacBookPro</category><category>WAR</category><category>RETE</category><category>Semantic Web</category><category>storage</category><category>disk</category><category>date</category><category>Prolog</category><category>JAAS</category><category>EulerSharp</category><category>pool</category><category>audio</category><category>tragedy</category><category>job</category><category>RSS</category><category>Terrapass</category><category>HashSet</category><category>RDFS</category><category>performance</category><category>astrophotography</category><category>eclipse</category><category>scalable</category><category>Talis</category><category>OCL</category><category>notebook</category><category>Web 3.0</category><category>64 bit</category><category>InverseFunctionalPredicate</category><category>New media</category><category>semantic</category><category>RDF</category><category>CSS</category><category>logic</category><category>jdk</category><category>security</category><category>Web Services</category><category>AST</category><category>BioMOBY</category><category>JavaCC</category><category>camping</category><category>filter</category><category>CodePoint</category><category>Unicode</category><category>patent</category><category>integration</category><category>iPhone</category><category>compatibility</category><category>memory map</category><category>tracker</category><category>emissions</category><category>Muglara</category><category>interviews</category><category>SeaDragon</category><category>certificate</category><category>architecture</category><category>PhotoSynth</category><category>Spivack</category><category>Mulgara</category><category>rules</category><category>SPARQL</category><category>podcast</category><category>weaknesses</category><category>trust</category><category>303</category><category>Beaver</category><category>Closed world</category><category>classpath</category><category>CST</category><category>conference</category><category>Pellet</category><category>FOAF</category><category>3G</category><category>types</category><category>GFS</category><category>OS X</category><category>AVL</category><category>Jetty</category><category>Dopplr</category><category>IRC</category><category>Currying</category><category>layout</category><category>OWL</category><category>SSL</category><category>code</category><category>inferencing</category><category>piano</category><category>open world</category><category>social network</category><category>transitive</category><category>Graphs</category><category>idiot</category><category>REST</category><category>RLog</category><category>random</category><category>lunar</category><category>TQL</category><category>XA2</category><category>JFlex</category><category>indexing</category><category>RNG</category><category>Feynmann</category><category>whuffie</category><category>Java</category><category>Web 2.0</category><category>blog</category><category>strengths</category><category>Google</category><category>Racer</category><category>JDBC</category><category>JAR</category><category>Open Source</category><category>time</category><category>OPTIONAL</category><category>GOPHER</category><category>pragmatic</category><category>Ruby</category><category>WebOS</category><category>topaz</category><category>search</category><category>EDGE</category><category>bitchun society</category><category>numbers</category><category>TED</category><category>WiFi</category><title>Working notes</title><description>Day to day notes on what I'm doing at work</description><link>http://gearon.blogspot.com/</link><managingEditor>noreply@blogger.com (Quoll)</managingEditor><generator>Blogger</generator><openSearch:totalResults>393</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/blogspot/juiue" /><feedburner:info uri="blogspot/juiue" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:browserFriendly></feedburner:browserFriendly><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6848574.post-1581877047099833696</guid><pubDate>Wed, 23 May 2012 04:36:00 +0000</pubDate><atom:updated>2012-05-23T07:52:09.841-05:00</atom:updated><title>Clojure Lessons</title><description>&lt;p&gt;Recently I've been working with Java code in a &lt;a href="http://www.springsource.org/"&gt;Spring&lt;/a&gt; framework. I'm not a big fan of Spring, since the bean approach means that everything has a similar public face, which means that the data types don't document the system very well. The bean approach also means that most types can be plugged into most places (kind of like Lego), but just because something can be connected doesn't mean it will do anything meaningful. It can make for a confusing system. As a result, I'm not really have much fun at work.&lt;p&gt; &lt;p&gt;To get myself motivated again, I thought I'd try something fun and render a &lt;a href="http://en.wikipedia.org/wiki/Mandelbrot_set"&gt;Mandelbrot set&lt;/a&gt;. I know these are easy, but it's something I've never done for myself. I also thought it might be fun to do something with graphics on the JVM, since I'm always working on server-side code. Turned out that it &lt;em&gt;was&lt;/em&gt; fun, keeping me up much later than I ought to have been. Being tired tonight I may end up rambling a bit. It may also be why I've decided to spell "colour" the way I grew up with, rather than the US way (except in code. After all, I have to use the &lt;code&gt;Color&lt;/code&gt; class, and it's just too obtuse to have two different spellings in the same program).&lt;/p&gt; &lt;p&gt;To get my feet wet, I started with a simple Java application, with a plan to move it into Clojure. My approach gave me a class called &lt;code&gt;Complex&lt;/code&gt; that can do the basic arithmetic (trivial to write, but surprising that it's not already there), and an abstract class called &lt;code&gt;Drawing&lt;/code&gt; that does all of the Window management and just expects the implementing class to implement &lt;code&gt;paint(Graphics)&lt;/code&gt;. With that done it was easy to write a pair of functions:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;code&gt;coord2Math&lt;/code&gt; to convert a canvas coordinate into a complex number.&lt;/li&gt;&lt;li&gt;&lt;code&gt;mandelbrotColor&lt;/code&gt; to calculate a colour for a given complex number (using a logarithmic scale, since linear shows too many discontinuities in colour).&lt;/li&gt;&lt;/ul&gt;Drawing this onto a graphical context is easy in Java: &lt;pre&gt;&lt;code&gt;for (int x = 0; x &lt; gWidth; x++) {&lt;br /&gt;  for (int y = 0; y &lt; gHeight; y++) {&lt;br /&gt;    g.setColor(mandelbrotColor(coord2Math(x, y)));&lt;br /&gt;    plot(g, x, y);&lt;br /&gt;  }&lt;br /&gt;}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;(&lt;code&gt;plot(Graphics,int,int)&lt;/code&gt; is a simple function that draws one pixel at the given location).&lt;/p&gt; &lt;p&gt;A small image (300x200 pixels) on this MacBookPro takes ~360ms. A big one (1397x856) took ~11500ms. Room for improvement, but it'll do. So with a working Java implementation in hand, I turned to writing the same thing in Clojure.&lt;/p&gt; &lt;h3&gt;Clojure Graphics&lt;/h3&gt;&lt;p&gt;Initially I tried extending my &lt;code&gt;Drawing&lt;/code&gt; class using &lt;code&gt;proxy&lt;/code&gt;, with a plan of moving to an implementation completely in Clojure. However, after getting it working that way I realized that doing the entire thing in Clojure wasn't going to take much at all, so I did that straight away. The resulting code is reasonably simple and boilerplate:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;(def window-name "Mandelbrot")&lt;br /&gt;(def draw-fn)&lt;br /&gt;&lt;br /&gt;(defn new-drawing-obj []&lt;br /&gt;  (proxy [JPanel] []&lt;br /&gt;    (paint [^Graphics graphics-context]&lt;br /&gt;      (let [width (proxy-super getWidth)&lt;br /&gt;            height (proxy-super getHeight)]&lt;br /&gt;        (draw-fn graphics-context width height)))))&lt;br /&gt;&lt;br /&gt;(defn show-window []&lt;br /&gt;  (let [^JPanel drawing-obj (new-drawing-obj)&lt;br /&gt;        frame (JFrame. window-name)]&lt;br /&gt;    (.setPreferredSize drawing-obj (Dimension. default-width default-height))&lt;br /&gt;    (.add (.getContentPane frame) drawing-obj)&lt;br /&gt;    (doto frame&lt;br /&gt;      (.setDefaultCloseOperation JFrame/EXIT_ON_CLOSE)&lt;br /&gt;      (.pack)&lt;br /&gt;      (.setBackground Color/WHITE)&lt;br /&gt;      (.setVisible true))))&lt;br /&gt;&lt;br /&gt;(defn start-window []&lt;br /&gt;  (SwingUtilities/invokeLater #(show-window)))&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Calling &lt;code&gt;start-window&lt;/code&gt; sets off a thread that will run the event loop and then call the &lt;code&gt;show-window&lt;/code&gt; function. That function uses &lt;code&gt;new-drawing-obj&lt;/code&gt; to create a proxy object that handles the &lt;code&gt;paint&lt;/code&gt; event. Then it sets the size of panel, puts it into a frame (the main window), and sets up the frame for display.&lt;/p&gt; &lt;p&gt;The only thing that seems worth noting from a Clojure perspective is the proxy object returned by &lt;code&gt;new-drawing-obj&lt;/code&gt;. This is simple extension of &lt;code&gt;java.swing.JPanel&lt;/code&gt; that implements the &lt;code&gt;paint(Graphics)&lt;/code&gt; method of that class. Almost every part of the drawing can be done in an external function (&lt;code&gt;draw-fn&lt;/code&gt; here), but the width and height are obtained by calling &lt;code&gt;getWidth()&lt;/code&gt; and &lt;code&gt;getHeight()&lt;/code&gt; on the &lt;code&gt;JPanel&lt;/code&gt; object. That object isn't directly available to the &lt;code&gt;draw-fn&lt;/code&gt; function, nor is it available through a name like "this". The object is returned from the &lt;code&gt;proxy&lt;/code&gt; function, but that's out of scope for the &lt;code&gt;paint&lt;/code&gt; method to access it. The only reasonable way to access methods that are inherited in the proxy is with the &lt;code&gt;proxy-super&lt;/code&gt; function (I can think of some unreasonable ways as well, like setting a reference to the proxy, and using this reference in &lt;code&gt;paint&lt;/code&gt;. But we won't talk about that kind of abuse).&lt;/p&gt; &lt;p&gt;While I haven't shown it here, I also wanted to close my window by pressing the "q" key. This takes just a couple of lines of code, whereby a proxy for &lt;code&gt;KeyListener&lt;/code&gt; is created, and then added to the frame via &lt;code&gt;(.addKeyListener the-key-listener-proxy)&lt;/code&gt;. Compared to the equivalent code in Java, it's strikingly terse.&lt;/p&gt; &lt;h3&gt;Rendering&lt;/h3&gt;&lt;p&gt;The Java code for rendering used a pair of nested loops to generate coordinates, and then calculated the colour for each coordinate as it went. However, this imperative style of coding is something to explicitly avoid in any kind of functional programming. So the question for me at this point, was how should I think about the problem?&lt;/p&gt; &lt;p&gt;Each time the &lt;code&gt;mandelbrotColor&lt;/code&gt; was to be called, it is mapping a coordinate to a colour. This gave me my first hint. I needed to &lt;em&gt;map&lt;/em&gt; coordinates to colours. This implies calling &lt;code&gt;map&lt;/code&gt; on a seq of coordinates, and ending up with a seq of colours. (Actually, not a &lt;em&gt;seq&lt;/em&gt;, but rather a &lt;a href="http://clojure.com/blog/2012/05/08/reducers-a-library-and-model-for-collection-processing.html"&gt;&lt;em&gt;reducible&lt;/em&gt; collection&lt;/a&gt;). However, what order are the colours in? Row-by-row? That would work, but it would involve keeping a count of the offset while working over the seq, which seems onerous, particular when the required coordinates were available when the colour was calculated in the first place. So why not include the coordinates in the seq with the colour? Not only does that simplify processing, it makes the rendering of this map stateless, since any element of the seq could be rendered independently of any other.&lt;/p&gt; &lt;p&gt;Coordinates can be created as pairs of integers using a comprehension:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;  (for [x (range width) y (range height)] [x y])&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;and the calculation can be done by mapping on a function that unpacks x and y and returns a triple of these two coordinates along with the calculated colour. I'll rename x and y to "a" and "b" in the mapping function to avoid ambiguity:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;  (map (fn [[a b] [a b (mandelbrot-color (coord-2-math a b))])&lt;br /&gt;       (for [x (range width) y (range height)] [x y]))&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;So now we have a sequence of coordinates and colours, but how do these get turned into an image? Again, the form of the problem provides the solution. We have a sequence (of tuples), and we want to reduce it into a single value (an image). Reductions like this are done using &lt;code&gt;reduce&lt;/code&gt;. The first parameter for the reduction function will be the image, the second will be the next tuple to draw, and the result will be a new image with the tuple drawn in it. The &lt;code&gt;reduce&lt;/code&gt; function isn't really supposed to mutate its first parameter, but we don't want to keep the original image without the pixel to be drawn, so it works for us here. The result is the following reduction function (type hint provided to avoid reflection on the graphical context):&lt;/p&gt;&lt;pre&gt;&lt;code&gt;  (defn plot [^Graphics g [x y c]]&lt;br /&gt;    (.setColor g c)&lt;br /&gt;    (.fillRect g x y 1 1)&lt;br /&gt;    g)&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Note that the original graphics context is returned, since this is the "new" value that plot has created (i.e. the image with the pixel added to it). Also, note that the second parameter is a 3 element tuple, which is just unpacked into x y and c.&lt;/p&gt; &lt;p&gt;So now the entire render process can be given as:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;(reduce plot g&lt;br /&gt;  (map (fn [[a b] [a b (mandelbrot-color (coord-2-math a b))])&lt;br /&gt;       (for [x (range width) y (range height)] [x y])))&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This works just fine, but there were performance issues, which was the part of this process that was most interesting. The full screen render (1397x856) took ~682 seconds (up from the 11.5 seconds it took Java). Obviously there were a few things to be fixed. There is still more to do, but I'll share what I came across so far.&lt;/p&gt; &lt;h3&gt;Reflection&lt;/h3&gt;&lt;p&gt;The first thing that &lt;a href="http://objectcommando.com/blog/"&gt;@objcmdo&lt;/a&gt; suggested was to look for reflection. I planned on doing that, but thought I'd continue cleaning the program up first. The &lt;code&gt;Complex&lt;/code&gt; class was still written in Java, so I embarked on rewriting that in Clojure.&lt;/p&gt; &lt;p&gt;The easiest way to do this was to implement a protocol that describes the actions (plus, minus, times, divide, absolute value), and to then define a record (of real/imaginary) that extends the protocol. It would have been nicer than the equivalent Java, but for one thing. Java allows method overloading based on parameter types, which means that a method like &lt;code&gt;plus&lt;/code&gt; can be defined differently depending on whether it receives a &lt;code&gt;double&lt;/code&gt; value, or another &lt;code&gt;Complex&lt;/code&gt; number. My understanding is that Clojure only overloads functions based on the parameter count, meaning that different function names are required to redefine the same operation for different types. So for instance, the &lt;code&gt;plus&lt;/code&gt; functions were written in Java as:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;  public final Complex plus(Complex that) {&lt;br /&gt;    return new Complex(real + that.real, imaginary + that.imaginary);&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  public final Complex plus(double that) {&lt;br /&gt;    return new Complex(real + that, imaginary);&lt;br /&gt;  }&lt;/code&gt;&lt;/pre&gt;But in Clojure I had to give them different names: &lt;pre&gt;&lt;code&gt;  (plus [this {that-real :real, that-imaginary :imaginary}]&lt;br /&gt;        (Complex. (+ real that-real) (+ imaginary that-imaginary)))&lt;br /&gt;  (plus-dbl [this that] (Complex. (+ real that) imaginary))&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Not a big deal, but code like math manipulation looks prettier when function overloading is available.&lt;/p&gt; &lt;p&gt;It may be worth pointing out that I used the names of the operations (like "plus") instead of the symbolic operators ("+"). While the issue of function overloading would have made this awkward (&lt;code&gt;+dbl&lt;/code&gt; is no clearer than &lt;code&gt;plus-dbl&lt;/code&gt;) it has the bigger problem of clashing with functions of the same name in clojure.core. Some namespaces do this (the &lt;code&gt;*&lt;/code&gt; character is a popular one to reuse), but I don't like it. You have to explicitly reject it from your current namespace, and then you need to refer to it by its full name if you do happen to need it. Given that &lt;code&gt;Complex&lt;/code&gt; needs to manipulate internal numbers, then these original operators &lt;em&gt;are&lt;/em&gt; needed.&lt;/p&gt; &lt;p&gt;So I created my protocol containing all the operators, defined a &lt;code&gt;Complex&lt;/code&gt; record to implement it, and then I replaced all use of the original Java &lt;code&gt;Complex&lt;/code&gt; class. Once I was finished I ran it again just to make sure that I hadn't broken anything.&lt;/p&gt; &lt;p&gt;To my great surprise, the full screen render went from 682 seconds down to 112 seconds. Protocols are an efficient mechanism, but they shouldn't be &lt;em&gt;that&lt;/em&gt; good. At that point I &lt;a href="http://dictionary.reference.com/browse/realise"&gt;realised&lt;/a&gt; that I hadn't used type hints around the &lt;code&gt;Complex&lt;/code&gt; class, and that as a consequence the Clojure code had to perform reflection on the complex numbers. Just as @objcmdo had suggested.&lt;/p&gt; &lt;p&gt;Wondering what other reflection I may have missed, I tried enabling the &lt;code&gt;*warn-on-reflection*&lt;/code&gt; flag in the &lt;a href="http://en.wikipedia.org/wiki/REPL"&gt;repl&lt;/a&gt;, but no warnings were forthcoming. I suspect that this was being subverted by the fact that the code is all being run by a thread that belongs to the Swing runtime. I tried adding some other type hints, but nothing I added had any effect, meaning that the Clojure compiler was already able to figure out the types involved (or else it just wasn't in a critical piece of code).&lt;/p&gt; &lt;h3&gt;Composable Abstractions&lt;/h3&gt;&lt;p&gt;The next thing I wondered about was the map/reduce part of the algorithm. While it made for elegant programming, it was creating unnecessary tuples at every step of the way. Could these be having an impact?&lt;/p&gt; &lt;p&gt;Once you have a nice list comprehension, it's tough to break it out into an imperative-style loop. Aside from ruining the elegance of the original construct, once you've seen your way through to viewing a problem in such clear terms, it's difficult to reconceptualize it as a series of steps. Even when you do, how do you make Clojure work against itself?&lt;/p&gt; &lt;p&gt;Creating a loop without burning through resources can be done easily with tail recursion. Clojure doesn't do this automatically (since the JVM does not provide for it), but it can be emulated well with &lt;em&gt;loop/recur&lt;/em&gt;. Since I want to loop between 0 (inclusive) and the width/height (exclusive), I decremented the upper limits for convenience. Also, the &lt;code&gt;plot&lt;/code&gt; function is no longer constraint to just 2 arguments, so I changed the definition to accept all 4 arguments directly, thereby eliminating the need to construct that 3-tuple:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;(let [dwidth (dec width)&lt;br /&gt;                 dheight (dec height)]&lt;br /&gt;  (loop [x 0 y 0]&lt;br /&gt;    (let [[next-x next-y] (if (= x dwidth)&lt;br /&gt;                              (if (= y dheight)&lt;br /&gt;                                  [-1 -1]      ;; signal to terminate&lt;br /&gt;                                  [0 (inc y)])&lt;br /&gt;                              [(inc x) y])]&lt;br /&gt;      (plot g x y (mandelbrotColor (coord-2-math x y)))&lt;br /&gt;      (if (= -1 next-x)&lt;br /&gt;        :end    ;; anything can be returned here&lt;br /&gt;        (recur next-x next-y)))))&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;My word, that's ugly. The &lt;code&gt;let&lt;/code&gt; that assigns &lt;code&gt;next-x&lt;/code&gt; and &lt;code&gt;next-y&lt;/code&gt; has a nasty nested &lt;code&gt;if&lt;/code&gt; construct that increments x and resets it at the end of each row. It also returns a flag (could be any invalid number, such as the keyword &lt;code&gt;:end&lt;/code&gt;) to indicate that the loop should be terminated. The loop itself terminates by testing for the termination value and returning a value that will be ignored.&lt;/p&gt; &lt;p&gt;But it all works as intended. Now instead of creating a tuple for every coordinate, it simply iterates through each coordinate and plots the point directly, just as the Java code did. So what's the performance difference here?&lt;/p&gt; &lt;p&gt;So far, the numbers I've provided are rounded to the nearest second. Repeated runs have usually taken a similar amount of time to the ones that I've reported here. However, there is always some jitter, sometimes by several seconds. Because of this, I was unable to see any difference whatsoever between using &lt;code&gt;map/reduce&lt;/code&gt; on a &lt;code&gt;for&lt;/code&gt; comprehension, versus using &lt;code&gt;loop/recur&lt;/code&gt;.&lt;/p&gt; &lt;p&gt;That's an interesting result, since it shows that the Clojure compiler and JVM are indeed as clever as we're told, when we see that better abstractions are just as efficient as the direct approach. It's all well and good for a language to make it easy to write powerful constructs, but being able to perform more elegant code just as efficiently as more direct, imperative code that a language is really offering useful power.&lt;/p&gt; &lt;p&gt;Aside from the obvious clarity issues, the composability of the &lt;code&gt;for/map/reduce&lt;/code&gt; makes an enormous difference. Because each element in the range being mapped is completely independent, we are free to use the &lt;a href="http://clojure.github.com/clojure/clojure.core-api.html#clojure.core/pmap"&gt;&lt;code&gt;pmap&lt;/code&gt; function&lt;/a&gt; instead of &lt;code&gt;map&lt;/code&gt;. The documentation claims that this function is,&lt;/p&gt;&lt;blockquote&gt;"Only useful for computationally intensive functions where the time of f dominates the coordination overhead."&lt;/blockquote&gt;&lt;p&gt;Yup. That's us.&lt;/p&gt; &lt;p&gt;So how much does this change make for us? Using &lt;code&gt;map&lt;/code&gt; on the current code, a full screen render takes 112 seconds. Changing &lt;code&gt;map&lt;/code&gt; to &lt;code&gt;pmap&lt;/code&gt; improves it to 75 seconds. That's a 33% improvement with no work, simply because the correct abstraction was applied. That's a very powerful abstraction.&lt;/p&gt; &lt;h3&gt;Future Work&lt;/h3&gt;&lt;p&gt;(Hmmm, that makes this sound like an academic paper. Should I be drawing charts?)&lt;/p&gt;&lt;p&gt;The final result is still a long way short of the 11.5 seconds the naïve Java code renders at. The single threaded version is particularly bad, taking about 10 times as long. I don't expect Clojure to be as fast as Java, but a factor of 10 suggests that there are some obvious things that I've missed, most likely related to reflection. If I can get it down to the same order of magnitude as the Java code, then using &lt;code&gt;pmap&lt;/code&gt; could make the Clojure version faster due to being multi-threaded. Of course, Java can be multi-threaded as well, but the effort and infrastructure for doing this would be significant.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6848574-1581877047099833696?l=gearon.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://gearon.blogspot.com/2012/05/clojure-lessons.html</link><author>noreply@blogger.com (Quoll)</author><thr:total>3</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6848574.post-4564481076620223420</guid><pubDate>Sun, 04 Sep 2011 17:24:00 +0000</pubDate><atom:updated>2011-09-08T08:47:31.086-05:00</atom:updated><title /><description>&lt;h3&gt;SPARQL JSON&lt;/h3&gt; After commenting the other day that Fuseki was ignoring my request for a JSON response, I was asked to submit a bug report. It's easy to cast unsubstantiated stones in a blog, but a bug report is a different story, so I went back to confirm everything. In the process, I looked at the SPARQL 1.1 Query Results JSON Format spec (I can't find a public copy of it, so no link, sorry. UPDATE: &lt;a href="http://www.w3.org/2009/sparql/docs/json-results/json-results-lc.html"&gt;Found it&lt;/a&gt;.) and was chagrined to discover that it has its own MIME type of "application/sparql-results+json". I had been using the JSON type of "application/json", and this indeed does not work, but the corrected type does. I don't think it's a good idea to ignore "application/json" so I'll report that, but strictly speaking it's correct (at least, I think so. As Andy said to me in a back channel, I don't really know what the + is supposed to mean in the subtype). So Fuseki got it right. Sorry.&lt;br /&gt;&lt;br /&gt;When I finally get around to implementing this for Mulgara I'll try to handle both. Which reminds me... I'd better get some more SPARQL 1.1 implemented. My day job at Revelytix needs me to do some Mulgara work for a short while, so that may help get the ball rolling for me.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;separate&lt;/h3&gt; I commented the other day that I wanted a Clojure function that takes a predicate and a seq, and returns two seqs: one that matches the predicate and the other that doesn't match. I was thinking I'd build it with a &lt;code&gt;loop&lt;/code&gt; construct, to avoid recursing through the seq twice.&lt;br /&gt;&lt;br /&gt;The next day, Gary (at work) suggested the &lt;a href="http://clojuredocs.org/clojure_contrib/clojure.contrib.seq-utils/separate"&gt;separate&lt;/a&gt; function from &lt;a href="http://clojuredocs.org/clojure_contrib"&gt;Clojure Contrib&lt;/a&gt;. I know there's some good stuff in contrib, but unfortunately I've never taken the time to fully audit it.&lt;br /&gt;&lt;br /&gt;The implementation of this function is obvious:&lt;pre&gt;&lt;code&gt;(defn separate [f s]&lt;br /&gt;  [(filter f s) (filter (complement f) s)])&lt;/code&gt;&lt;/pre&gt;I was disappointed to learn that this function iterates twice, but Gary pointed out that there had been a discussion on exactly this point, and the counter argument is that this is the only way to build the results lazily. That's a reasonable point, and it is usually one of the top considerations for Clojure implementations. I don't actually have cause for complaint anyway, since the seqs I'm using are always small (being built out of query structures).&lt;br /&gt;&lt;br /&gt;This code was also a good reminder that &lt;code&gt;(complement x)&lt;/code&gt; offers a concise replacement for the alternative code:&lt;pre&gt;&lt;code&gt;  #(not x %)&lt;/code&gt;&lt;/pre&gt;By extension, it's a reminder to brush up on my idiomatic Clojure. I should finish the book &lt;a href="http://joyofclojure.com/"&gt;The Joy of Clojure&lt;/a&gt; (which is a thoroughly enjoyable read, by the way).&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6848574-4564481076620223420?l=gearon.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://gearon.blogspot.com/2011/09/sparql-json-after-commenting-other-day.html</link><author>noreply@blogger.com (Quoll)</author><thr:total>4</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6848574.post-5406101921787200874</guid><pubDate>Fri, 02 Sep 2011 01:45:00 +0000</pubDate><atom:updated>2011-09-02T01:30:04.656-05:00</atom:updated><title /><description>&lt;h3&gt;ASTs&lt;/h3&gt; 
&lt;br /&gt;After yesterday's post, I noticed that a number of references came to me via Twitter (using a &lt;a href="http://t.co/"&gt;t.co&lt;/a&gt; URL). After looking for it, I realized that I'm linked to from the &lt;a href="http://planet.clojure.in/"&gt;Planet Clojure&lt;/a&gt; page. I'm not sure why, though I guess it's because I'm working for &lt;a href="http://revelytix.com/"&gt;Revelytix&lt;/a&gt;, and we're one of the larger Clojure shops around. Only my post wasn't about Clojure - it was about JavaScript. So now I feel obligated to write something about Clojure. Besides, I'm out of practice with my writing, so it would do me good.
&lt;br /&gt;
&lt;br /&gt;So the project I spend most of my time on (for the moment) is called &lt;a href="http://revelytix.com/content/rex-ea"&gt;Rex&lt;/a&gt;. It's a &lt;a href="http://www.w3.org/standards/techs/rif#w3c_all"&gt;RIF&lt;/a&gt; based rules engine written entirely in Clojure. It does lots of things, but the basic workflow for running rules is:&lt;ol&gt;&lt;li&gt;Parse the rules out of the rule file and into a &lt;a href="http://en.wikipedia.org/wiki/Concrete_syntax_tree"&gt;Concrete Syntax Tree&lt;/a&gt;.  We can parse the RIF XML format, the RIF Presentation Syntax, and the &lt;a href="http://www.w3.org/TR/2011/NOTE-rif-in-rdf-20110512/"&gt;RIF RDF format&lt;/a&gt;, and we plan on doing others.&lt;/li&gt;&lt;li&gt;Run a set of transformations on the CST to convert it into an appropriate &lt;a href="http://en.wikipedia.org/wiki/Abstract_syntax_tree"&gt;Abstract Syntax Tree&lt;/a&gt; (AST). This can involve some tricky analysis, particularly for aggregates (which are a RIF extension).&lt;/li&gt;&lt;li&gt;Transformation of the AST into &lt;a href="http://www.w3.org/TR/sparql11-query/"&gt;SPARQL 1.1 query&lt;/a&gt; fragments.&lt;/li&gt;&lt;li&gt;Execute the engine, by processing the rules to generate more data until the capacity to generate new data has been exhausted. (My... &lt;em&gt;that's&lt;/em&gt; a lot of hand waving).&lt;/li&gt;&lt;/ol&gt;It's step 3 that I was interested in today.
&lt;br /&gt;
&lt;br /&gt;The rest of this post is about how Rex processes a CST into an AST using Clojure, and about some subsequent refactoring that went on. You have been warned...
&lt;br /&gt;
&lt;br /&gt;When I first wrote the CST to AST transformation step, it was to do a reasonably straight forward analysis of the CST. Most importantly, I needed to see the structure of the rule so that I could see what kind of data it depends on, thereby figuring out which other rules might need to be run once a given rule was executed. Since the AST is a tree structure, this made for relatively straight forward recursive functions.
&lt;br /&gt;
&lt;br /&gt;Next, I had to start identifying some CST structures that needed to be changed in the AST. This is where it got more interesting. Again, I had to write recursive functions, but instead of simply analyzing the data, it had to be changed. It turns out that this is handled easily by having a different function for each type of node in the tree. In the normal case the function then recurses on all of its children, and constructs an identical node type using the new children. The leaf nodes then just return themselves. The "different function" for each type is actually accessed with the same name, but dispatches on the function type. In Java that would need a visitor pattern, or perhaps a map of types to functors, but in Clojure it's handled trivially with &lt;a href="http://clojure.org/multimethods"&gt;multimethods&lt;/a&gt; or &lt;a href="http://clojure.org/Protocols"&gt;protocols&lt;/a&gt;. Unfortunately, the online resources for describing the multi-dispatch aspects of Clojure protocols are not clear, but Luke VanderHart and Stuart Sierra's book &lt;a href="http://www.apress.com/9781430272311"&gt;Practical Clojure&lt;/a&gt; covers it nicely.
&lt;br /&gt;
&lt;br /&gt;As an abstract example of what I mean, say I have an AST consisting of Conjunctions, Disjunctions and leaf nodes. Both Conjunctions and Disjunctions have a single field that contains a seq of the child nodes. These are declared with:&lt;pre&gt;&lt;code&gt;(defrecord Conjunction [children])
&lt;br /&gt;(defrecord Disjunction [children])&lt;/code&gt;&lt;/pre&gt;The transformation function can be called &lt;code&gt;tx&lt;/code&gt;, and I'll define it with multiple dispatch on the node type using multimethods:&lt;pre&gt;&lt;code&gt;(defmulti tx  class)
&lt;br /&gt;
&lt;br /&gt;(defmethod tx Disjunction [{c :children}]
&lt;br /&gt;    (Disjunction. (map tx c)))
&lt;br /&gt;
&lt;br /&gt;(defmethod tx Conjunction [{c :children}]
&lt;br /&gt;    (Conjunction. (map tx c)))
&lt;br /&gt;
&lt;br /&gt;(defmethod tx :default [n] n)
&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;This will reconstruct an identical tree to the original, though with all new nodes except the leaves. Now, the duplication in the Disjunction and Conjunction methods should be ringing alarm bells, but in real code the functions have more specific jobs to do. For instance, the Conjunction may want to group terms that meet a certain condition (call the test "&lt;code&gt;special-type?&lt;/code&gt;") into a new node type (call it "&lt;code&gt;Foo&lt;/code&gt;"):&lt;pre&gt;&lt;code&gt;;; A different definition for tx on Conjunction
&lt;br /&gt;(defmethod tx Conjunction [{c :children}]
&lt;br /&gt;  (let [new-children (map tx c)
&lt;br /&gt;        special-nodes (filter special-type? new-children)
&lt;br /&gt;        other-nodes (filter (comp not special-type?) new-children)]
&lt;br /&gt;    (Conjunction. (conj other-nodes (Foo. special-nodes)))))&lt;/code&gt;&lt;/pre&gt;Hmmm... while writing that example I realized that I regularly run into the pattern of filtering out everything that meets a test, and everything that fails the test. Other than having to test everything twice, it seems too verbose. What I need is a function that will take a seq and a predicate and return a tuple containing a seq of everything that matches the predicate, and a second seq of everything that fails the predicate. I'm not seeing anything like that right now, so that may be a job for the morning.
&lt;br /&gt;
&lt;br /&gt;I should note, that there is no need for a function to return the same type that came into it. There are several occasions where Rex returns a different type. For example, a conjunction between a Basic Graph Pattern (BGP) and the negation of another BGP becomes a MINUS operation between the two BGPs (a Basic Graph Pattern comes from SPARQL and is just a triple pattern for matching against the subject/predicate/object of a triple in an RDF store).
&lt;br /&gt;
&lt;br /&gt;Overall, this approach works very well for transforming the CST into the full AST. As I've needed to incorporate more features and optimizations over time, I found that I had two choices. Either I could expand the complexity of the operation for every type in the tree processing code, or I could perform different types of analysis on the entire tree, one after another. The latter makes the process far easier to understand, making the design more robust and debugging easier, so that's how Rex has been written. It makes analysis slightly slower, but analysis is orders of magnitude faster than actually running the rules, so that is not a consideration.
&lt;br /&gt;
&lt;br /&gt;&lt;h3&gt;Threading&lt;/h3&gt; The first time through, analysis was simple:&lt;pre&gt;&lt;code&gt;(defn analyse [rules]
&lt;br /&gt;  (process rules))&lt;/code&gt;&lt;/pre&gt;Adding a new processing step was similarly easy:&lt;pre&gt;&lt;code&gt;(defn analyse [rules]
&lt;br /&gt;  (process2 (process1 rules)))&lt;/code&gt;&lt;/pre&gt;But once a third, then a fourth step appeared, it became obvious that I needed to use the &lt;a href="http://clojure.github.com/clojure/clojure.core-api.html#clojure.core/-&gt;"&gt;Clojure threading macro&lt;/a&gt;:&lt;pre&gt;&lt;code&gt;(defn analyse [rules]
&lt;br /&gt;  (-&gt; rules
&lt;br /&gt;      process1
&lt;br /&gt;      process2
&lt;br /&gt;      process3
&lt;br /&gt;      process4))&lt;/code&gt;&lt;/pre&gt;So now it's starting to look nice. Each step in the analysis process is a single function name implemented for various types. These names are then provided in a list of things to be applied to the rules, via the threading macro. There's a little more complexity (one of the steps picks up references to parts of the tree, and since each stage &lt;em&gt;changes&lt;/em&gt; the tree, then these references will be pointing to an old and unused version of the tree. So that step has to be last), but it paints the general picture.
&lt;br /&gt;
&lt;br /&gt;&lt;h3&gt;Partial&lt;/h3&gt; Another thing that I've glossed over is that each rule is actually a record that contains the AST as one of its members. The rules themselves are a seq which is in turn a member of a record containing a "Rule Program". So each process step actually ended up being like this:&lt;pre&gt;&lt;code&gt;(defn process1 [rule-program]
&lt;br /&gt;  (letfn [(process-rule [rule] (assoc rule :body (tx (:body rule))))]
&lt;br /&gt;    (assoc rule-program :rules (map process-rule (:rules rule-prog)))))&lt;/code&gt;&lt;/pre&gt;Did you follow that?
&lt;br /&gt;
&lt;br /&gt;The bottom line is replacing the :rules field with a new one. It's mapping &lt;code&gt;process-rule&lt;/code&gt; onto the seq of rules, and storing the result in a new rules-program, which is what gets returned. The &lt;code&gt;process-rule&lt;/code&gt; function is defined locally as associating the :body of a rule with the &lt;code&gt;tx&lt;/code&gt; function applied to the existing body. This creates a new rule that has has the &lt;code&gt;tx&lt;/code&gt; applied to it.
&lt;br /&gt;
&lt;br /&gt;This all looked fine to start with. A new rule program is created by transforming all the rules in the old program. A transformed rule is created by transforming the AST (the :body) in the old rule. But after the third analysis it became obvious that there was duplication going on. In fact, it was all being duplicated except for the &lt;code&gt;tx&lt;/code&gt; step. But that was buried deep in the function. What was the best way to pull it out?
&lt;br /&gt;
&lt;br /&gt;To start with, the embedded &lt;code&gt;process-rule&lt;/code&gt; function came out. After all, it was just inside to hide it, and not because it had to pick up a closure anywhere. This function then accepts the kind of transformation that it needs to do as a parameter:&lt;pre&gt;&lt;code&gt;(defn convert-rule
&lt;br /&gt;  [convert-fn rule]
&lt;br /&gt;  (assoc rule :body (convert-fn (:body rule))))&lt;/code&gt;&lt;/pre&gt;Next, we want a general function for converting all the rules, which can accept a conversion function to pass on to &lt;code&gt;convert-rule&lt;/code&gt;. It does all the rules, so I just pluralized the name:&lt;pre&gt;&lt;code&gt;(defn convert-rules
&lt;br /&gt;  [conversion-fn rule-prog]
&lt;br /&gt;  (assoc rule-prog :rules (map #(convert-rule conversion-fn %) (:rules rule-prog)))))&lt;/code&gt;&lt;/pre&gt;That works, but now the function getting mapped is looking messy (and messy leads to mistakes). I could improve it by defining a new function, but I just factored a function out of this function. Fortunately, there is a simpler way to define this new function. It's a "partial" application of &lt;code&gt;convert-rule&lt;/code&gt;. But I'll still move it into a &lt;code&gt;let&lt;/code&gt; block for clarity:&lt;pre&gt;&lt;code&gt;(defn convert-rules
&lt;br /&gt;  [conversion-fn rule-prog]
&lt;br /&gt;  (let [conv-rule (partial convert-rule conversion-fn)]
&lt;br /&gt;    (assoc rule-prog :rules (map conv-rule (:rules rule-prog)))))&lt;/code&gt;&lt;/pre&gt;So now my original &lt;code&gt;process1&lt;/code&gt; definition becomes a simple:&lt;pre&gt;&lt;code&gt;(defn process1 [rule-program]
&lt;br /&gt;  (convert-rules tx rule-program))&lt;/code&gt;&lt;/pre&gt;That works, but the &lt;code&gt;rule-program&lt;/code&gt; parameter is just sticking out like a sore thumb. Fortunately, we've already seen how to fix this:&lt;pre&gt;&lt;code&gt;(def process1 (partial convert-rules tx))&lt;/code&gt;&lt;/pre&gt;Indeed, all of the processing functions can be written this way:&lt;pre&gt;&lt;code&gt;(def process1 (partial convert-rules tx))
&lt;br /&gt;(def process2 (partial convert-rules tx2))
&lt;br /&gt;(def process3 (partial convert-rules tx3))
&lt;br /&gt;(def process4 (partial convert-rules tx4))&lt;/code&gt;&lt;/pre&gt;It may seem strange that a function is now being defined with a &lt;code&gt;def&lt;/code&gt; instead of a &lt;code&gt;defn&lt;/code&gt;, but it's really not an issue. It's worth remembering that &lt;code&gt;defn&lt;/code&gt; is just a macro that uses &lt;code&gt;def&lt;/code&gt; to attach a symbol to a call to &lt;code&gt;(fn ...)&lt;/code&gt;.
&lt;br /&gt;
&lt;br /&gt;&lt;h3&gt;Documenting&lt;/h3&gt; Of course, my functions don't appear as sterile as what I've been typing here. I do indeed use documentation. That means that the &lt;code&gt;process1&lt;/code&gt; function would look more like:&lt;pre&gt;&lt;code&gt;(defn process1 [rule-program]
&lt;br /&gt;  "The documentation for process1"
&lt;br /&gt;  (convert-rules tx rule-program))&lt;/code&gt;&lt;/pre&gt;One of the nice features of the &lt;code&gt;defn&lt;/code&gt; macro is the ease of writing documentation. This isn't as trivial with &lt;code&gt;def&lt;/code&gt; since it's a special form, rather than a macro, but it's still not too hard to do. You just need to attach some metadata to the object, with a key of &lt;code&gt;:doc&lt;/code&gt;. Unfortunately, I couldn't remember the exact syntax for this today, and rather then go trawling through books or existing code, &lt;a href="http://tech.puredanger.com/"&gt;Alex&lt;/a&gt; was kind enough to remind me:&lt;pre&gt;&lt;code&gt;(def ^{:doc "The documentation for process1"}
&lt;br /&gt;  process1 (partial convert-rules tx))&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;h3&gt;Framework&lt;/h3&gt; The upshot of all of this is a simpler framework for adding new steps to the existing analysis system. Adding a new analysis step just needs a new function thrown into the thread. I could put a call to &lt;code&gt;(partial convert-rules ...)&lt;/code&gt; directly into the thread, but by using a &lt;code&gt;def&lt;/code&gt; I get to name and document that step of the analysis. the only real work of the analysis is then done in the single multi-dispatch function, which is just as it should be.
&lt;br /&gt;
&lt;br /&gt;So right now my evening "hobby" has been JavaScript, while my day job is Clojure. I have to tell you, the day job is &lt;em&gt;much&lt;/em&gt; more fun. &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6848574-5406101921787200874?l=gearon.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://gearon.blogspot.com/2011/09/asts-after-yesterdays-post-i-noticed.html</link><author>noreply@blogger.com (Quoll)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6848574.post-7620051540900290700</guid><pubDate>Thu, 01 Sep 2011 15:30:00 +0000</pubDate><atom:updated>2011-09-01T11:17:43.528-05:00</atom:updated><title /><description>&lt;h3&gt;Robusta&lt;/h3&gt;I was just posting this into Google+ when I realized I was typing more than I'd intended. It read more like a short blog post. Which reminded me.... "Oh yeah. I have a blog out there somewhere! Maybe I should write this in there." 
&lt;br /&gt;
&lt;br /&gt;After spending a lot of recent nights on JavaScript I think I'm starting to get a feel for it. I started with Douglas Crockford's "&lt;a href="http://oreilly.com/catalog/9780596517748"&gt;JavaScript: The Good Parts&lt;/a&gt;", and am now plowing through David Flanagan's "&lt;a href="http://oreilly.com/catalog/9780596805524/"&gt;JavaScript: The Definitive Guide&lt;/a&gt;". (I met David when he came to Brisbane to run a short course on Java programming back in 1996. Nice guy. He said that he'd preferred to have called his book "Java in a Demitasse", but O'Reilly wanted it in their "Nutshell" series).
&lt;br /&gt;
&lt;br /&gt;After using languages like Ruby, Erlang, Scala and Clojure, I'm finding it a little frustrating, but it's hard to argue with the ubiquity of the platform. Fortunately it has closures and first class functions, though the variable scoping is bizarre. I've been enjoying the callback approach to asynchronous function calls, though the syntax tends to make the resulting code confusing to read. I'm mostly sticking to Crockford's subset of the language, and this does make things a little more sensible. Flanagan's book has been filling in the gaps for me, but it's especially useful for documenting libraries like HTML5 Canvas and the File API.
&lt;br /&gt;
&lt;br /&gt;As with all first attempts at using a language, mine is a little messy and inconsistent. However, it can't hurt to put it out there. I've built a simple tool for working with SPARQL endpoints (specifically aimed at Jena/Fuseki, but it should mostly work on others too). The important piece is the SPARQL connection object that it comes with (found in sparql.js). I'm hoping that this will be a useful object for more general application. It can even convert XML responses into a SPARQL-JSON structure (I wrote this after discovering Fuseki was ignoring my &lt;em&gt;Content-type&lt;/em&gt; settings on queries).
&lt;br /&gt;
&lt;br /&gt;Unfortunately, it's missing one important piece, which is the ability to upload a file from a browser. In general, it's possible to upload a file using a form submission, but that encodes all the parameters into the request body, and the SPARQL HTTP protocol requires that the graph URI appear as a parameter in the URL of the request. In an attempt to get the &lt;strong&gt;graph&lt;/strong&gt; parameter out of the body and into the URL, I even tried dynamically constructing the URL for the form submission, but the browser "cleverly" saw what I was doing and pushed the parameter back into the body. So I can't use form submission. Alternatively, JavaScript makes it easy to submit an HTTP POST operation with everything set the way you want it. However, the only way to read a local file is through the form submission process, which means I still can't do a file upload. In the end, I just used Fuseki's file upload servlet, but this has the problem of being non-standard, and it also doesn't like URIs that aren't http (yes Andy, that's why I asked you about this restriction - though I'd already run into it at work).
&lt;br /&gt;
&lt;br /&gt;The resulting system needed a name, so I called it &lt;em&gt;Robusta&lt;/em&gt;. Everyone seems to be enamored with Arabica beans, but no one ever talks about Robusta beans. Don't get me wrong.... if I had to choose between the two I'd definitely go for the Arabica. But by blending in a small portion of Robusta beans you add a richness to the flavor of your coffee (it's also used as a cheap "filler" and promotes crema in espresso, but I like the flavor aspect). At the time, I came up with the name because I really needed some caffeine, and Arabica was too obvious. But in retrospect, I like the name, since adding a bit of SPARQL to your scripts can really enhance a system (OK, that's tacky. I probably need another one of those coffees). It wasn't after I'd had some coffee that I thought to look for other projects with the same name, but by that point it was already up there.
&lt;br /&gt;
&lt;br /&gt;Robusta is still a work in progress, and it's mostly a late night project that fits around everything else that I'm doing. But I'm using it at work, and it makes my life easier. I'd like to know if anyone has ideas for it, or can point out errors, inefficiencies, or potential improvements. It's posted at GitHub as a part of the &lt;a href="https://github.com/revelytix"&gt;Revelytix project group&lt;/a&gt;, at:
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;a href="https://github.com/revelytix/robusta"&gt;http://github.com/revelytix/robusta&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6848574-7620051540900290700?l=gearon.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://gearon.blogspot.com/2011/09/robusta-i-was-just-posting-this-into.html</link><author>noreply@blogger.com (Quoll)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6848574.post-4297271368044649062</guid><pubDate>Fri, 22 Oct 2010 04:24:00 +0000</pubDate><atom:updated>2010-10-22T10:40:21.667-05:00</atom:updated><title /><description>&lt;h3&gt;Clojure Experiences&lt;/h3&gt; I've been learning Clojure recently, as my new job uses it frequently. I'm happy with this (it has me attending &lt;a href="http://clojure-conj.org/"&gt;(first clojure-conj)&lt;/a&gt; right now), but I'm still learning a lot about the language. I'm comfortable with functional programming, and of course, there's next to nothing to learn about syntax and grammar, but there is a steep learning curve to effectively use the libraries. Not only are there a lot of them, but they are not really well documented.&lt;br /&gt;&lt;br /&gt;OO languages tell you which functions belong to a class, but since Clojure functions don't really belong to anything it can sometimes be hard to find everything that is relevant to the structures you are dealing with. I've had a few people tell me that there are good websites out there that provide the sort of documentation I'd like, so I'll go looking for them soon.&lt;br /&gt;&lt;br /&gt;Meanwhile, I find myself looking at the libraries all the time. Other than the general principle of code reuse, the dominant paradigm in Clojure is to use the core libraries whenever possible.  This is because those libraries are likely to be much more efficient than anything you can come up with on your own. They're also "lazy", meaning that the functions do very little work themselves, with all of the work being put off until you actually need it. Laziness is a good thing, and should show up in Clojure code as much as possible. Using the core libraries is the best way to accomplish that.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Clojure Maps&lt;/h3&gt;&lt;br /&gt;Part of my current task is to take a data structure that represents an RDF graph, and process it. The structure that I have now maps resource identifiers (sometimes URIs, but mostly internal blank node IDs) to structures representing all of the property/values associated with that resource. Unfortunately, the values are simple identifiers too, so to find their data I have to go back to the structure and get the resources for that object. This has to be repeated until everything found has no properties or is a literal (which has no properties). Also, the anonymous resources in RDF lists are showing up as data structures, which makes them difficult to work with as well.&lt;br /&gt;&lt;br /&gt;Following this kind of structure is easy enough in an imperative language, though quite tedious. However, in Clojure it is simply too inelegant to work with. So I want some way to make this to a nice nested structure that represents the nested data from the RDF graph (fortunately, this kind of graph is guaranteed to not have any cycles). In particular, I'd this new structure to be lazy wherever I can get it.&lt;br /&gt;&lt;br /&gt;The basic approach is simple: get the property/values for a given resource. Then convert the values (resources) that aren't literals to the actual data that they represent. This is done by getting the property/values of those resources, which is what I started with, so now I know I need recursion.&lt;br /&gt;&lt;br /&gt;Now there are a few caveats. First off, if a resource is actually the head of a list, I don't want to just get it's properties. Instead, I want to traverse the list (lazily, of course) and get all the values attached to the nodes. That's easy enough, and is done with a function to identify resources that are lists, and another one to construct the list (a recursive function that uses &lt;a href="http://clojure.github.com/clojure/clojure.core-api.html#clojure.core/lazy-seq"&gt;lazy-seq&lt;/a&gt;). Second, there is one property/value that I want to preserve, and that is the &lt;code&gt;:id&lt;/code&gt; property. This property shows the URI or identifier for the original node, so the value here needs to be kept, and not expanded on (it would recurse indefinitely otherwise).&lt;br /&gt;&lt;br /&gt;After identifying these requirements, I figured I needed some way to convert all the key/value elements of a map into a new map. This sounds very much like converting all the elements in a sequence (a "seq") into a new sequence, a task which is done using the &lt;a href="http://clojure.github.com/clojure/clojure.core-api.html#clojure.core/map"&gt;map&lt;/a&gt; function. Is there a similar operation to be applied to a map? (The noun and the verb get confusing here, sorry).&lt;br /&gt;&lt;br /&gt;It turns out that Alex Miller had been dealing with exactly this problem just recently, and has built a new function called &lt;a href="http://tech.puredanger.com/2010/09/24/meet-my-little-friend-mapmap/"&gt;mapmap&lt;/a&gt; to do this operation. However, I wasn't aware of this at the time, so I had to pursue my own solution. I'm reasonably happy with my answer, and I learnt a bit in the process, so I'm glad I solved it myself, though it would have been nice to get that sleep back.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Morphing a Map&lt;/h3&gt;&lt;br /&gt;There have been a few times when I've needed to create a new map, and the first time I needed to I went to clojure.core to see what kind of map-creating functions were available to me. At that point I found &lt;a href="http://clojure.github.com/clojure/clojure.core-api.html#clojure.core/hash-map"&gt;hash-map&lt;/a&gt;, which takes a sequence containing an even number of items, and converts it into a map using the even-numbered offsets as the keys and the odd-numbered offsets as the values (with the first offset being "0"). So I could create a map of numbers to their labels using the following:&lt;pre&gt;&lt;code&gt;  (hash-map 1 "one" 2 "two" 3 "three")&lt;/code&gt;&lt;/pre&gt;So was there a way to create this list from my existing map? (Well, yes, but was it &lt;em&gt;easy&lt;/em&gt;?)&lt;br /&gt;&lt;br /&gt;I wanted to iterate over my existing map "entries" and create new entries. If you treat a map as a seq, then it appears as a sequence of 2-element vectors, with the first element being the key and the second element being the value. So if I want to morph the values in a map called "mymap" with a function called "morph", I could convert these pairs into new pairs with:&lt;pre&gt;&lt;code&gt;  (map (fn [[k v]] [k (morph v)]) mymap)&lt;/code&gt;&lt;/pre&gt;For anyone unfamiliar with the syntax, my little anonymous function in the middle there is taking as it's single parameter a 2 element vector, and destructuring it into the values k and v, then returning a new two element vector of k and (morph v). So let's apply this to a map of numbers to their names (incidentally, I don't code anything like this, but I do blog this way)....&lt;pre&gt;&lt;code&gt;  (def mymap {1 "one", 2 "two", 3 "three"})&lt;br /&gt;  (def morph #(.toUpperCase %))&lt;br /&gt;  (map (fn [[k v]] [k (morph v)]) mymap)&lt;/code&gt;&lt;/pre&gt;The result is:&lt;pre&gt;&lt;code&gt;([1 "ONE"] [2 "TWO"] [3 "THREE"])&lt;/code&gt;&lt;/pre&gt;Looks good, but there is one problem. This result is a sequence of pairs, while &lt;code&gt;hash-map&lt;/code&gt; just takes a sequence. That's OK, we can just call &lt;code&gt;flatten&lt;/code&gt; before passing it in:&lt;pre&gt;&lt;code&gt;  (apply hash-map (flatten (map (fn [[k v]] [k (morph v)]) mymap)))&lt;br /&gt;{1 "ONE", 2 "TWO", 3 "THREE"}&lt;/code&gt;&lt;/pre&gt;The "&lt;code&gt;apply&lt;/code&gt;" was needed because &lt;code&gt;hash-map&lt;/code&gt; needed lots of arguments (6 in this case) while the result of &lt;code&gt;flatten&lt;/code&gt; would have been just 1 argument (a list).&lt;br /&gt;&lt;br /&gt;This is looking good. It's what I've done in the past, and it's hardly worthy of a blog post. But this time I had a new twist. My "values" were also structures, and often these structures were seqs as well. For instance, say I have a map of numbers to names in a couple of languages:&lt;pre&gt;&lt;code&gt;(def langmap {1 ["one" "uno"], 2 ["two" "due"], 3 ["three" "tre"]})&lt;/code&gt;&lt;/pre&gt;My morph method needs to change to accept a seq of strings instead of just a string, but that's trivial. So then the map step looks good, giving an output of:&lt;pre&gt;&lt;code&gt;([1 ("ONE" "UNO")] [2 ("TWO" "DUE")] [3 ("THREE" "TRE")])&lt;/code&gt;&lt;/pre&gt;But this fails to be loaded into a hash-map, with the error:&lt;pre&gt;&lt;code&gt;java.lang.IllegalArgumentException: No value supplied for key: TRE (NO_SOURCE_FILE:0)&lt;/code&gt;&lt;/pre&gt;This is exactly what bit me at 1am.&lt;br /&gt;&lt;br /&gt;The problem is simple. &lt;a href="http://clojure.github.com/clojure/clojure.core-api.html#clojure.core/flatten"&gt;flatten&lt;/a&gt; is recursive. It dives into the sub-sequences, and brings them up too. The result is trying to map 1 to "ONE", mapping "UNO" to 2, and so on, until it gets to "TRE" at which point it doesn't has a value to map it to, so it gives an error. Fortunately for me I had an odd number of items when everything was flattened, or else I would have been working with a corrupted map and may not have discovered it for some time.&lt;br /&gt;&lt;br /&gt;My first thought was to write a version of flatten that isn't recursive, but that's when I took a step back and asked myself if there was &lt;em&gt;another&lt;/em&gt; way to construct a map. Maybe I shouldn't be using &lt;code&gt;hash-map&lt;/code&gt;. So I looked at Clojure's &lt;a href="http://clojure.org/cheatsheet"&gt;cheatsheet&lt;/a&gt;, and discovered &lt;a href="http://clojure.github.com/clojure/clojure.core-api.html#clojure.core/zipmap"&gt;zipmap&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;zipmap&lt;/h3&gt;&lt;br /&gt;&lt;code&gt;zipmap&lt;/code&gt; wasn't quite what I wanted, in that instead of taking a sequence of pairs, it wants a pair of sequences. It then constructs a map where the &lt;em&gt;n&lt;/em&gt;th key/value comes from the &lt;em&gt;n&lt;/em&gt;th entry in the first sequence (the key) and the &lt;em&gt;n&lt;/em&gt;th entry from the second sequence (the value). So I just needed to rotate, or transpose my data. Fortunately, the day before one of my co-workers had asked me exactly the same question.&lt;br /&gt;&lt;br /&gt;In this case, he had a sequence of MxN entries, looking something like:&lt;pre&gt;&lt;code&gt;[[a1 a2 a3] [b1 b2 b3] [c1 c2 c3]]&lt;/code&gt;&lt;/pre&gt;And the result that he wanted was:&lt;pre&gt;&lt;code&gt;[[a1 b1 c1] [a2 b2 c2] [a3 b3 c3]]&lt;/code&gt;&lt;/pre&gt;My first thought was some wildly inefficient loop-comprehension, when he asked me if the following would work (for some arg):&lt;pre&gt;&lt;code&gt;  (apply map list arg)&lt;/code&gt;&lt;/pre&gt;Obviously he didn't have a repl going, so I plugged it in, and sure enough it worked. But why?&lt;br /&gt;&lt;br /&gt;I struggled to understand it until I looked up the documentation for &lt;code&gt;map&lt;/code&gt; again, and remembered that it can take &lt;em&gt;multiple&lt;/em&gt; sequences, not just one. I had totally forgotten this. When provided with &lt;em&gt;n&lt;/em&gt; sequences, &lt;code&gt;map&lt;/code&gt; requires a function that accepts &lt;em&gt;n&lt;/em&gt; arguments. It then goes through each of the sequences in parallel, with the output being a sequence where the &lt;em&gt;n&lt;/em&gt;th entry is the result of calling the function with the &lt;em&gt;n&lt;/em&gt;th entry of every source sequence. In this case, the function was just &lt;code&gt;list&lt;/code&gt;, meaning that it creates a list out of the items from each sequence. The &lt;code&gt;apply&lt;/code&gt; just expanded the single argument out into the required lists that &lt;code&gt;map&lt;/code&gt; needed. This one line is a lovely piece of elegance, and deserves its own name:&lt;pre&gt;&lt;code&gt;  (defn rotate [l] (apply map list l))&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;So the final composition for creating a new map with values modified from the original map is:&lt;pre&gt;&lt;code&gt;  (apply zipmap (rotate (map (fn [[k v]] [k (morph v)]) langmap)))&lt;br /&gt;{3 ("THREE" "TRE"), 2 ("TWO" "DUE"), 1 ("ONE" "UNO")}&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now the actual function that I use inside map isn't nearly so simple. After all, I need to recursively traverse the RDF graph, plus I need to find RDF lists and turn them into sequences, etc. But this zipmap/rotate/map idiom certainly makes it easy.&lt;br /&gt;&lt;br /&gt;Incidentally, I could do exactly the same thing with Alex's &lt;code&gt;mapmap&lt;/code&gt;:&lt;pre&gt;&lt;code&gt;  (mapmap key (comp morph val) langmap)&lt;/code&gt;&lt;/pre&gt;Oh well. I'm still happy I discovered zipmap/rotate.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6848574-4297271368044649062?l=gearon.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://gearon.blogspot.com/2010/10/clojure-experiences-ive-been-learning.html</link><author>noreply@blogger.com (Quoll)</author><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6848574.post-5581888475103599038</guid><pubDate>Thu, 13 May 2010 17:18:00 +0000</pubDate><atom:updated>2010-05-13T12:25:22.615-05:00</atom:updated><title /><description>&lt;h3&gt;Feedburner&lt;/h3&gt;&lt;br /&gt;Something reminded me that I had RSS going through Feedburner, so I tried to look at it. Turns out that after the Google move they want to update everyone's account, and I hadn't done it yet. So I gave them all my details, and the system told me that it didn't recognize me.&lt;br /&gt;&lt;br /&gt;So then I said I'd forgotten my password, at which point it recognized my email address and asked a "secret question". I know the answer to the question, and it's not even that secret, since I'm sure that most of my family could figure it out, but Feedburner claims I'm wrong. Could someone have changed this? Maybe, but there are only a handful of people who would know that answer, and I trust them not to do something like that.&lt;br /&gt;&lt;br /&gt;Not a problem, I'll just submit a report explaining my problem. Only it seems that Feedburner is exempt from that kind of thing. The closest you can get to help is an FAQ. Good one Google.&lt;br /&gt;&lt;br /&gt;So now what? Well, I guess I just create a new Feedburner link and take it from there. Sorry, but if you've been using RSS to follow this blog, then would you mind changing it please? It's annoying, I know.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6848574-5581888475103599038?l=gearon.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://gearon.blogspot.com/2010/05/feedburner-something-reminded-me-that-i.html</link><author>noreply@blogger.com (Quoll)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6848574.post-736856052823901895</guid><pubDate>Thu, 13 May 2010 12:03:00 +0000</pubDate><atom:updated>2010-05-13T12:00:36.718-05:00</atom:updated><title /><description>&lt;h3&gt;Wrongful Indexing&lt;/h3&gt; &lt;br /&gt;Some years ago &lt;a href="http://gearon.blogspot.com/2004/08/proof-reading-once-again-its-way-too.html"&gt;I commented on the number and type of indexes&lt;/a&gt; that can be used for tuples. At the time, I pointed out that indexing triples required 3 indexes, and there were 2 appropriate sets of indexes to use. Similarly, quads can be indexed with 6 indexes, and there are 4 such sets. In both cases (5-tuples get silly, requiring 10 indexes and there are 12 possible sets). In each case, I said that each set of indexes would work just as well as the others, and so I always selected the set that included the natural ordering of the tuples.&lt;br /&gt;&lt;br /&gt;So for RDF triples, the two sets of indexes are ordered by:&lt;pre&gt;  subject,predicate,object&lt;br /&gt;  predicate,object,subject&lt;br /&gt;  object,subject,predicate&lt;/pre&gt;and&lt;pre&gt;  object,predicate,subject&lt;br /&gt;  predicate,subject,object&lt;br /&gt;  subject,object,predicate&lt;/pre&gt;For convenience I have always chosen the first set, as this includes the natural ordering of subject/predicate/object, but it looks like I was wrong.&lt;br /&gt;&lt;br /&gt;In using these indexes I've always presumed random 3-tuples, but in reality the index is representing RDF. Whenever I thought about the data I was looking for, this seemed OK, but that's because I tended to think about properties on resources, and not other RDF structures. In particular, I was failing to consider lists.&lt;br /&gt;&lt;br /&gt;Since first building RDF indexes (2001) and writing about them (2004) I've learnt a lot about functional programming. This, in turn, led to an appreciation of lists, particularly in algorithms. I'm still not enamored of them in on-disk structures, but I do appreciate their utility and elegance in many applications. So it was only natural that when I was representing RDF graphs with Scala and I needed to read lists, then I used some trivial recursive code to build a Scala list, and it all looked great. But then I decided to port the Graph class to Java to avoid including the Scala Jars for a really lightweight library.&lt;br /&gt;&lt;br /&gt;I'd like to point out that I'm talking about a library function that can read a well-formed RDF list and return a list in whatever programming language the library is implemented in. The remainder of this post is going to presume that the lists are well formed, since any alternatives can never be returned as a list in an API anyway.&lt;br /&gt;&lt;br /&gt;Reading a list usually involves the subject/predicate/object (SPO) index. You start by looking up the head of the list as a subject, then the predicates &lt;code&gt;rdf:first&lt;/code&gt; for the data at that point in the list, and &lt;code&gt;rdf:rest&lt;/code&gt; for the rest of the list. Rinse and repeat until &lt;code&gt;rdf:rest&lt;/code&gt; yields a value of &lt;code&gt;rdf:nil&lt;/code&gt;. So for each node in the list, there is a lookup by subject, followed by two lookups by predicate. This is perfect for the SPO index.&lt;br /&gt;&lt;br /&gt;However, it's been bugging me that I have such a general approach, when the structure is predetermined. Why look up these two predicates so generally, when we know exactly what we want? What if we reduce the set we're looking in to just the predicates that we want and then go looking for the subjects? That would mean looking first by predicate, then subject, then object, leading to a PSO index. So what does that algorithm look like?&lt;br /&gt;&lt;br /&gt;First, look up the &lt;code&gt;rdf:rest&lt;/code&gt; predicate, leading to an index of subject/object containing all list structures. Next, look up the &lt;code&gt;rdf:rest&lt;/code&gt; predicate, retrieving subject/objects containing all the list data. Now to iterate down the list no longer involves finding the subject followed by the predicate, in order to read the next list node, but rather it just requires finding the subject, and the list node is in the corresponding object. Similarly with the data stored in the node. We're still doing a fixed number of lookups in an index, which means that the overall complexity does not change at all. Tree indexes will still give &lt;em&gt;O(log(N))&lt;/em&gt; complexity, and hash indexes will still give &lt;em&gt;O(1)&lt;/em&gt; complexity. However, each step can involve disk seeks, so it's worth seeing the difference.&lt;br /&gt;&lt;br /&gt;To compare more directly, using an SPO index requires every node to:&lt;ul&gt;&lt;li&gt;Lookup across the entire graph by subject.&lt;/li&gt;&lt;li&gt;Lookup across the subject (2 or 3 predicates) for &lt;code&gt;rdf:first&lt;/code&gt;.&lt;/li&gt;&lt;li&gt;Lookup across the subject (2 or 3 predicates) for &lt;code&gt;rdf:rest&lt;/code&gt;.&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;For the PSO index we have some initial setup:&lt;ul&gt;&lt;li&gt;Lookup across the entire graph for the &lt;code&gt;rdf:first&lt;/code&gt; predicate.&lt;/li&gt;&lt;li&gt;Lookup across the entire graph for the &lt;code&gt;rdf:rest&lt;/code&gt; predicate.&lt;/li&gt;&lt;/ul&gt;Then for every node:&lt;ul&gt;&lt;li&gt;Lookup the &lt;code&gt;rdf:first&lt;/code&gt; data for the value.&lt;/li&gt;&lt;li&gt;Lookup the &lt;code&gt;rdf:rest&lt;/code&gt; data for the next node.&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;It's important to note a few things, particularly for tree indexes. Trees are the most likely structure used when using a disk, so I'm going to concentrate on them. The number of subjects in a graph tends to scale up with the size of the graph, while the number of predicates is bounded. This is because predicates are used to express a model, with each predicate indicating a certain relationship. Any system trying to deal with the model needs some idea of the concepts it is dealing with, so it's &lt;em&gt;almost&lt;/em&gt; impossible to deal with completely arbitrary relationships. If we know what the relationships are ahead of time, then there must be a fixed number of them. In contrast, subjects represent individuals, and these can be completely unbounded. So if we look up an entire graph to find a particular subject, then we may have to dive down a very deep tree to find that subject. Looking across the entire graph for a given predicate will never have to go very deep, because there are so few of them.&lt;br /&gt;&lt;br /&gt;So the first algorithm (using the SPO index) iteratively looks across every subject in the graph for each node in the list. The next two lookups are trivial, since nodes in a list will only have properties of &lt;code&gt;rdf:first&lt;/code&gt;, &lt;code&gt;rdf:rest&lt;/code&gt; and possibly &lt;code&gt;rdf:type&lt;/code&gt;. The data associated with these properties will almost certainly be in the same block where the subject was found, meaning that there will be no more disk seeks.&lt;br /&gt;&lt;br /&gt;The second algorithm (using the PSO index) does a pair of lookups across every predicate in the graph. The expected number of disk seeks to find the first predicate is significantly fewer than for any of the "subject" searches in the first algorithm. Given how few predicates are in the system, then finding the second predicate may barely involve any disk seeks at all, particularly since the first search will have populated the disk cache with a good portion of the tree, and the similarities in the URIs of the predicates is likely to make both predicates very close to each other. Of course, this presumes that the predicates are even in a tree. Several systems (including one I'm writing right now) treat predicates differently because of how few there are. Indeed, a lot of systems will cache them in a hashtable, regardless of the on-disk structure. So the initial lookup is very inexpensive.&lt;br /&gt;&lt;br /&gt;The second algorithm then iterates down the list, just like the first one does. However, this time, instead of searching for the nodes out of every subject in the list, it will now be just searching for these nodes in the subjects that appear as list nodes. While lists are commonly used in some RDF structures, the subjects in all the lists typically form a very small minority out of all the subjects in a graph. Consequently, depending on the type and depth of trees being used, iterating through a list with the second algorithm, could result in a 2 or three (or more) fewer disk seeks for each node. That's a saving that can add up.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Solid State Disks&lt;/h3&gt;&lt;br /&gt;I've been talking about disk seeks, but this is an artificial restriction imposed by spinning disk drives. Solid State Disks (SSDs) don't have this limitation.&lt;br /&gt;&lt;br /&gt;People have been promoting solid state drives (SSDs) for some years now, but I've yet to use them myself. In fact, most people I know are still using traditional spinning platters. The prices difference is still a big deal, and for really large data, disk drives are still the only viable option. But this will change one day, so am I right to be concerned about disk seeks?&lt;br /&gt;&lt;br /&gt;Disk seeks are a function of data locality. When data has to be stored somewhere else on a disk, the drive head must physically seek across the surface to this new address. SSDs don't require anything to move, but there are still costs in addressing scattered data.&lt;br /&gt;&lt;br /&gt;While it is possible to address every bit of memory in a device in one step, in practice this is never done. This is because the complexity of the circuit grows exponentially as you try to address more and more data in one step. Instead, the memory is broken up into "banks". A portion of the address can now be used to select a bank, allowing the remaining bits in the address to select the required memory in just that bank. This works well, but it does lead to some delays. Selecting a new bank requires "setup", "hold" and "settling" times, all leading to delays. These delays are an order of magnitude smaller than seek delays for a spinning disk, but they do represent a limit on the speed of the device. So while SSDs are much faster than disk drives, there are still limits to their speed, and improvements in data locality can still have a significant impact on performance.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6848574-736856052823901895?l=gearon.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://gearon.blogspot.com/2010/05/wrongful-indexing-some-years-ago-i.html</link><author>noreply@blogger.com (Quoll)</author><thr:total>2</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6848574.post-5054173887147152325</guid><pubDate>Wed, 05 May 2010 01:06:00 +0000</pubDate><atom:updated>2010-05-04T21:00:35.095-05:00</atom:updated><title /><description>&lt;h3&gt;Web Services Solved&lt;/h3&gt; &lt;br /&gt;It's a been a long couple of days, and I really want to relax instead of write, but it's been a few days and I've been promising myself that I'd write, so I figured I need to get something written before I can open a beer.&lt;br /&gt;&lt;br /&gt;First of all, the web services problem was trivial. I recently added a new feature that allowed &lt;a href="http://jetty.codehaus.org/jetty/jetty-6/apidocs/org/mortbay/jetty/handler/ContextHandler.html"&gt;ContextHandlers&lt;/a&gt; in &lt;a href="http://jetty.codehaus.org/jetty/"&gt;Jetty&lt;/a&gt; to be configured. Currently the only configuration option I've put in there is the one that was requested, and that is the size of a form. Apparently this is 200k by default, but if you're going to load large files then that may not be enough. Anyway, the problem came about when my code tried to read the maximum form size from the configuration. I wasn't careful enough to check if the context was being configured in the first place, so an NPE was thrown if it was missing.&lt;br /&gt;&lt;br /&gt;Fortunately, most people would never see the problem, since the default configuration file includes details for contexts, and this ends up in every build by default. The reason I was seeing it is because Topaz replaces the configuration with their own (since it describes their custom resolvers), and this custom configuration file doesn't have the new option in it. Of course, I could just add it to Topaz, but the correct solution is to make sure that a configuration can't throw an NPE – which is exactly what I told the Ehcache guys, so it's fitting that I have to do it myself. :-)&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Hosting&lt;/h3&gt;&lt;br /&gt;Since I'm on the topic of Topaz, it looks like te OSU/OSL guys and I have both the Topaz and Mulgara servers configured. They wouldn't typically be hosting individual projects (well, they do occasionally), but in this case it's all going in under the umbrella of Duraspace. Of course this has taken some time, and in the case of Topaz I'm still testing that it's all correct, but I think it's there. I'll be changing the DNS for Topaz over soon, and Mulgara was changed last week. Mulgara's DNS has propagated now, so I'm in the process of cutting a long-overdue release.&lt;br /&gt;&lt;br /&gt;One thing that changed in the hosting is that I no longer have a Linux host to build the distribution on. Theoretically, that would be OK, since I ought to be able to build on any platform. However, Mulgara is still distributed as a build for Java 1.5 (I've had complaints when I accidentally put out a release that was built for 1.6). This is easy to set up on Linux, since you just change the JAVA_HOME environment variable to make sure you're pointing to a 1.5 JDK. However, every computer I have here is a Mac. Once upon a time that didn't change anything, but now all JDKs point to JDK 1.6. That means I need to configure the compiler to output the correct version. It can be done, but Mulgara wasn't set up for it.&lt;br /&gt;&lt;br /&gt;If you read the &lt;a href="http://ant.apache.org/manual/CoreTasks/javac.html"&gt;Ant documentation on compiling&lt;/a&gt; you'll see that you can set the target to any JDK version you like. However, that would require editing 58 files (I just had to run a quick command to see that. Wow... I didn't realize it was so bad). I'm sure I'd miss a &amp;lt;&lt;code&gt;javac&lt;/code&gt;&amp;gt; somewhere. Fortunately, there is another option, even if the Ant documents discourage it. There's a system parameter called &lt;a href="http://ant.apache.org/manual/javacprops.html#target"&gt;ant.build.java.target&lt;/a&gt; which will set the default value globally. I checked to make sure that nothing was going to be missed by this (ie. that nothing was manually setting the target) and when it all looked good I changed the build script to set this to "1.5". I didn't change the corresponding script on Windows, but personally I only want this for distributions. Anyone who needs to set it up on Windows probably has the very JDK they want to run Mulgara on anyway.&lt;br /&gt;&lt;br /&gt;Well, that's my story, and I'm sticking to it.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Semantic Universe&lt;/h3&gt;&lt;br /&gt;What else? Oh yes. I wrote a &lt;a href="http://www.semanticuniverse.com/blogs-common-sparql-extension.html"&gt;post for Semantic Universe&lt;/a&gt;. It's much more technical that the other posts I've seen there, but I was told that would be OK. I'm curious to know how it will be received.&lt;br /&gt;&lt;br /&gt;I was interested in how it was promoted on Twitter. I wrote something that mixes linked data and SPARQL to create a kind of federated query (something I find to be very useful, BTW, and I think more people should be aware of it). However, in the process I mentioned that this shouldn't be necessary, since SPARQL 1.1 will be including a note on federated querying. Despite SPARQL 1.1 only being mentioned a couple of times, &lt;a href="http://twitter.com/SemUni/status/13325494782"&gt;the tweet&lt;/a&gt; said, that I discussed "how/why SPARQL 1.1 plans to be a bit more dazzling". Well, admittedly SPARQL 1.1 &lt;em&gt;will&lt;/em&gt; be more dazzling, but my post didn't discuss that. Perhaps it was a hint to talk about that in a future post.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Miscellanea&lt;/h3&gt;&lt;br /&gt;Speaking of future posts, I realized that I've been indexing RDF backwards, at least for lists. It doesn't affect the maximum complexity of iterating a list, but it &lt;em&gt;does&lt;/em&gt; affect the &lt;em&gt;expected complexity&lt;/em&gt;. I won't talk about it tonight, but hopefully by mentioning it here I'll prompt myself to write about it soon.&lt;br /&gt;&lt;br /&gt;This last weekend was the final weekend that my in-laws were visiting from the other side of the planet, so I didn't get much jSPARQLc done. I hope to fix that tomorrow night. I'm even wondering if the Graph API should be factored out into it's own sister project. It's turning out to be incredibly useful for reading and working with RDF data when you just want access to the structure and you don't need a full query engine. It would even plug directly into almost every query engine out there, so there's a lot of utility to it.&lt;br /&gt;&lt;br /&gt;I'm also &lt;em&gt;finally&lt;/em&gt; learning &lt;a href="http://hadoop.apache.org/"&gt;Hadoop&lt;/a&gt;, since I've had more pressure to consider a clustered RDF store, much as &lt;a href="http://www.cloudera.com/blog/2010/03/how-raytheon-researchers-are-using-hadoop-to-build-a-scalable-distributed-triple-store/"&gt;BBN have created&lt;/a&gt;. I've read the &lt;a href="http://labs.google.com/papers/mapreduce.html"&gt;MapReduce&lt;/a&gt;, &lt;a href="http://labs.google.com/papers/gfs.html"&gt;GFS&lt;/a&gt; and &lt;a href="http://labs.google.com/papers/bigtable.html"&gt;BigTable&lt;/a&gt; papers, so I went into it thinking I'd be approaching the problem one way, but the more I learn the more I think it would scale better if I went in other directions. So for the moment I'm trying to avoid getting too many preconceived notions of architecture until I've learnt some more and applied my ideas to some simple cases. Of course, &lt;a href="http://hadoop.apache.org/hive/"&gt;Hive&lt;/a&gt; tries to do the same thing for relational data, so I think I need to look at the code in that project too. I have a steep learning curve ahead of me there, but I've been avoiding those recently, so it will do me some good.&lt;br /&gt;&lt;br /&gt;Other than that, it's been interviews and immigration lawyers. These are horribly time consuming, and way too boring to talk about, so I won't. See you tomorrow.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6848574-5054173887147152325?l=gearon.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://gearon.blogspot.com/2010/05/web-services-solved-its-been-long.html</link><author>noreply@blogger.com (Quoll)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6848574.post-3163625980747870769</guid><pubDate>Fri, 30 Apr 2010 14:03:00 +0000</pubDate><atom:updated>2010-04-30T10:31:13.807-05:00</atom:updated><title /><description>&lt;h3&gt;Topaz and Ehcache&lt;/h3&gt; &lt;br /&gt;Don't ask what I did 2 days ago, because I forget. It's one of the reasons I need to blog more. I also forgot because my brain got clouded due to yesterday's tasks.&lt;br /&gt;&lt;br /&gt;I didn't get a lot done yesterday for the simple reason that I was filling in paperwork for an immigration lawyer. For anyone who has ever had to do this mind numbing task, they probably know that you end up filling in mostly the same things that you filled in 12 months ago, but just subtly different, so there's no possibility of using copy/paste. They will also know that getting all of the information together can take half a day. Strangely, the hardest piece of information was my mother's birthday (why do they want this? I have no idea). There is a bizarre story behind this, that I won't go into right now, but with my mother asleep in Australia there was no way to ask her. Fortunately, I had two brothers online at the time: one lives here in the USA, and the other is a student in Australia (who was up late drinking with friends, and decided to get online to say hi before going to bed). Unfortunately, neither of them new either (the well-oiled brother being completely unaware of why we didn't know).&lt;br /&gt;&lt;br /&gt;But I finally got it done, cleared my immediate email queue (only 65 to go!) and got down to work.&lt;br /&gt;&lt;br /&gt;My first task was to get the Topaz version of Mulgara up and running the same way it used to run 10 months ago. I had already tried going back through the subversion history for the project (ah, that's one of the things I did two days ago!), but with no success. However, I &lt;em&gt;had been&lt;/em&gt; able to find out that others have had this error with &lt;a href="http://www.ehcache.org/"&gt;Ehcache&lt;/a&gt;. No one had a fix, since upgrading the library normally made their problem go away. Well I tried upgrading it myself, but without luck. Evidently the problem was in usage, but I didn't know if it was a problem in the code talking to Ehcache, or the XML configuration file that is uses. Since everything used to work without error, I figured that the code was probably OK, and that it was the configuration at fault. The complexity of the configuration file only deepened my suspicion.&lt;br /&gt;&lt;br /&gt;I didn't want to learn the ins-and-outs of an Ehcache configuration, so my first non-lawyer related task yesterday was to look at the code where the exception was coming from (thank goodness the Java compiler includes line numbers in class files by default). So it turned out that &lt;a href="http://www.terracotta.org/"&gt;Terracotta&lt;/a&gt; (the company who provides Ehcache) have a nice navigable HTML versions of all their opensource code, which made this task much more pleasant than having to get it all from Subversion. This led me to &lt;a href="http://ehcache.org/xref/net/sf/ehcache/distribution/MulticastKeepaliveHeartbeatSender.html#180"&gt;the line&lt;/a&gt; that was throwing the exception, which looked like:&lt;pre&gt;&lt;code&gt;List localCachePeers = cacheManager.getCachePeerListener("RMI").getBoundCachePeers();&lt;/code&gt;&lt;/pre&gt;Great, a compound statement. OK, so I use them myself, but they're annoying when you debug. Was it &lt;code&gt;cacheManager&lt;/code&gt; that was &lt;code&gt;null&lt;/code&gt; or was it the return value from &lt;code&gt;getCachePeerListener("RMI")&lt;/code&gt;?&lt;br /&gt;&lt;br /&gt;At this point I jumped around in the code for a bit (I quite like those hyperlinks. I've seen them before too. I should figure out which project creates these pages), looking for what initialized cacheManager. I didn't find definitive proof that it was set, but it looked pretty good. So I looked at &lt;a href="http://ehcache.org/xref/net/sf/ehcache/CacheManager.html#1128"&gt;getCachePeerListener("RMI")&lt;/a&gt; and discovered that it was a lookup in a Hashmap. This is a prime candidate for returning &lt;code&gt;null&lt;/code&gt;, and indeed the documentation for the method even states that it will return &lt;code&gt;null&lt;/code&gt; if the scheme is not configured. Since the heartbeat code was making the presumption that it could perform an operation on the return value of this method, then the "RMI" scheme is evidently supposed to be configured in every configuration. The fact that it's possible for this method to return &lt;code&gt;null&lt;/code&gt; (even if it's not supposed to) means that the calling code is not defensive enough (any kind of NullPointerException is unacceptable, even if you catch it and log it). Also, the fact that something is always supposed to be configured for "RMI" had me looking in the code to discover where listeners get registered. This turned out to come from some kind of configuration object, which looked like it had been built from an XML file.&lt;br /&gt;&lt;br /&gt;So the problem appears to be the combination of something that's missing from the configuration file, and a presumption that it will be there (i.e. the code couldn't handle it if the item was missing). At this point I joined a forum and described the issue, both to point out that the code should be more defensive, and also to ask what is missing. In the meantime, I tried creating my own version of the library with a fix in it, and discovered that the issue did indeed go away. Then this morning I received a message explaining what I &lt;a href="http://ehcache.org/documentation/distributed_caching_with_rmi.html"&gt;needed to configure&lt;/a&gt;, and also that the code now deals with the missing configuration. It still complains on every heartbeat (in 5 second intervals), but now it tells you what's wrong, and how to fix it:&lt;pre&gt;&lt;code&gt;WARNING: The RMICacheManagerPeerListener is missing. You need to configure&lt;br /&gt;  a cacheManagerPeerListenerFactory with&lt;br /&gt;  class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"&lt;br /&gt;  in ehcache.xml.&lt;/code&gt;&lt;/pre&gt;Kudos to "gluck" for the quick response. (Hey, I just realized – "gluck" is from Brisbane. My home town!)&lt;br /&gt;&lt;br /&gt;Incidentally, creating my own version of Ehcache was problematic in itself. It's a Maven project, and when I tried to build "package" it attempted to run all the tests, which took well over an hour. Coincidentally, it also happened to be dinner time, so I came back later, only to discover that not all of the tests had passed, and that the JAR files had not been built. Admittedly, it was an older release, but it &lt;em&gt;was&lt;/em&gt; a release, so I found this odd. In the end, I avoided the tests by removing the code, and running the "package" target again.&lt;br /&gt;&lt;br /&gt;With all the errors out of the way I went back to the Topaz system again and run it. As I said earlier, it was no longer reporting errors. But then when I tried to use queries against it, it was completely unresponsive. A little probing found that it wasn't listening for HTTP at all, so I checked the log, and sure enough:&lt;pre&gt;&lt;code&gt;EmbeddedMulgaraServer&gt; Unable to start web services due to: null [Continuing]&lt;/code&gt;&lt;/pre&gt;Argh.&lt;br /&gt;&lt;br /&gt;Not only do I have to figure out what's going on here, it also appears that someone (possibly me) didn't code this configuration defensively enough! Sigh.&lt;br /&gt;&lt;br /&gt;At that point it was after dinner, and I had technical reading to do for a job I might have. Well, I've received the offer, but it all depends on me not being kicked out of the country.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6848574-3163625980747870769?l=gearon.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://gearon.blogspot.com/2010/04/topaz-and-ehcache-dont-ask-what-i-did-2.html</link><author>noreply@blogger.com (Quoll)</author><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6848574.post-2991388790499106088</guid><pubDate>Tue, 27 Apr 2010 01:52:00 +0000</pubDate><atom:updated>2010-04-26T23:21:18.948-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">SPARQL</category><category domain="http://www.blogger.com/atom/ns#">Mulgara</category><title /><description>&lt;h3&gt;Multitasking&lt;/h3&gt; &lt;br /&gt;At the moment I feel like I have too many things on the boil. I'm regularly answering &lt;a href="http://osuosl.org/"&gt;OSU/OSL&lt;/a&gt; about porting data over from &lt;a href="http://topazproject.org/trac/"&gt;Topaz&lt;/a&gt; and &lt;a class="zem_slink" href="http://mulgara.org/" title="Mulgara (software)" rel="homepage"&gt;Mulgara&lt;/a&gt;, I'm supposed to be getting work done on &lt;a class="zem_slink" href="http://en.wikipedia.org/wiki/SPARQL" title="SPARQL" rel="wikipedia"&gt;SPARQL&lt;/a&gt; Update 1.1 (which suffered last week while I looked around for a way to stay in the USA), I'm trying to track down some unnecessary sorting that is being done by Mulgara queries in a Topaz configuration, I'm trying to catch up on reading (refreshing my memory on some important Semantic Web topics so that I keep nice and current), I'm trying to find a someone who can help us not get kicked out of the country (long story), I'm responding to requests on Mulgara, and when I have some spare time (in my evenings and weekends) I'm trying to make &lt;a href="http://code.google.com/p/jsparqlc"&gt;jSPARQLc&lt;/a&gt; look more impressive.&lt;br /&gt;&lt;br /&gt;So how's it all going?&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;OSU/OSL&lt;/h3&gt;&lt;br /&gt;Well, OSU/OSL are responding slowly, which is frustrating, but also allows me the time to look at other things, so it's a mixed blessing. They keep losing my tickets, and then respond some time later apologizing for not getting back to me. However, they're not entirely at fault, as I have sudo access on out server, and could do some of this work for myself. The thing is that I've been avoiding the learning curves of Mailman and Trac porting while I have other stuff to be doing. All the same, we've made some progress lately, and I'm really hoping to switch the DNS over to the new servers in the next couple of days. Once that happens I'll be cutting an overdue release to Mulgara.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;SPARQL Update 1.1&lt;/h3&gt;&lt;br /&gt;I really should have done some of this work already, but my job (and impending lack thereof) have interfered. Fortunately another editor has stepped up to help here, so with his help we should have it under control for the next publication round.&lt;br /&gt;&lt;br /&gt;The biggest issues are:&lt;ol&gt;&lt;li&gt;Writing possible responses for each operation. In some cases this will simply be success/failure, but for others it will mean describing partial success. For instance, a long-running &lt;code&gt;LOAD&lt;/code&gt; operation may have loaded 100,000 triples before failing. Most systems want that data to stay in there, and not roll back the change, and we need some way to report what has happened.&lt;/li&gt;&lt;li&gt;Dealing with an equivalent for &lt;code&gt;FROM&lt;/code&gt; and &lt;code&gt;FROM NAMED&lt;/code&gt; in &lt;code&gt;INSERT/DELETE&lt;/code&gt; operations. Using &lt;code&gt;FROM&lt;/code&gt; in a &lt;code&gt;DELETE&lt;/code&gt; operation looks like this is the graph that you want to remove data from, whereas we really want to describe the list of graphs (and/or named graphs) that affect the &lt;code&gt;WHERE&lt;/code&gt; clause. The last I read, the suggestion to use &lt;code&gt;USING&lt;/code&gt; and &lt;code&gt;USING NAMED&lt;/code&gt; instead was winning out. The problem is that no one really likes it, though they don't like every other suggestion even more. :-)&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;&lt;br /&gt;I doubt I'll get much done before the next meeting, but at least I did a little today, and I've been able to bring the other editor up to speed.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Sorting&lt;/h3&gt;&lt;br /&gt;This is a hassle that's been plaguing me for a while. A long time back &lt;a href="http://www.plos.org/"&gt;PLoS&lt;/a&gt; complained about queries that were taking too long (like, up to 10 minutes!). After looking at them, I found that a lot of sorting of a lot of data was going on, so I investigated why.&lt;br /&gt;&lt;br /&gt;From the outset, Mulgara adopted "Set Semantics". This meant that everything appeared only once. It made things a little harder to code, but it also made the algebra easier to work with. In order to accomplish this cleanly, each step in a query resolution removed duplicates. I wasn't there, so I don't know why the decision wasn't made to just leave it to the end. Maybe there was a good reason. Of course, in order to remove these duplicates, it had to order the data.&lt;br /&gt;&lt;br /&gt;When SPARQL came along, the pragmatists pointed out that not having duplicates was a cost, and for many applications it didn't matter anyway. So they made duplicates allowable by default, and introduced the &lt;code&gt;DISTINCT&lt;/code&gt; keyword to remove them if necessary, just like SQL. Mulgara didn't have this feature (though the Sesame-Mulgara bridge hacked it to work by selecting all variables across the bridge and projecting out the ones that weren't needed), but given the cost of this sorting, it was obvious we needed it.&lt;br /&gt;&lt;br /&gt;The sorting in question came about because the query was a UNION between a number of product terms (or a disjunction of conjunctions). In order to make the UNION in order, each of the product terms was sorted first. Of course, without the sorting, a UNION can be a trivial operation, but with it the system was very slow. Actually, the query in question was more like a UNION between multiple products, with some of the product terms being UNIONS themselves. The resulting nested sorting was painful. Unfortunately, the way things stood, it was necessary, since there was no way to do a conjunction (product) without having the terms sorted, and since some of the terms could be UNIONS, then the result of a UNION had to be sorted.&lt;br /&gt;&lt;br /&gt;The first thing I did was to factor the query out into a big UNION between terms (a sum-of-products). Then I manually executed each one to find out how long it took. After I added up all the times, the total was about 3 seconds, and most of that time was spent waiting for &lt;a href="http://lucene.apache.org/java/docs/"&gt;Lucene&lt;/a&gt; to respond (something I have no control over), so this was looking pretty good.&lt;br /&gt;&lt;br /&gt;To make this work in a real query I had to make the factoring occur automatically, I had to remove the need to sort the output of a UNION, and I had to add a query syntax to TQL to turn this behavior on and off.&lt;br /&gt;&lt;br /&gt;The syntax was already done for SPARQL, but PLoS were using TQL through Topaz. I know that a number of people use TQL, so I wasn't prepared to break the semantics of that language, which in turn meant that I couldn't introduce a &lt;code&gt;DISTINCT&lt;/code&gt; keyword. After asking a couple of people, I eventually went with a new keyword of &lt;code&gt;NONDISTINCT&lt;/code&gt;. I hate it, but it also seemed to be the best fit.&lt;br /&gt;&lt;br /&gt;Next I did the factorization. Fortunately, Andrae had introduced a framework for modifying a query to a &lt;a href="http://en.wikipedia.org/wiki/Fixed_point_%28mathematics%29"&gt;fixpoint&lt;/a&gt;, so I was able to add to that for my algebraic manipulation. I also looked at other expressions, like differences (which was only in TQL, but is about to become a part of SPARQL) and Optional joins (which were part of SPARQL, and came late into TQL). It turns out that there is a lot that you can do to expand a query to a sum-of-products (or as close to as possible), and fortunately it was easy to accomplish (thanks Andrae).&lt;br /&gt;&lt;br /&gt;Finally, I put the code in to only do this factorization if a query was &lt;em&gt;not&lt;/em&gt; supposed to be &lt;code&gt;DISTINCT&lt;/code&gt; (the default in SPARQL, and if the new keyword is present for TQL). Unexpectedly, this ended up being the trickiest part. Part of the reason was because some UNION operations still needed to have the output sorted if they were embedded in an expression that couldn't be expanded out (a rare, though possible situation, but only when mixing with differences and optional joins).&lt;br /&gt;&lt;br /&gt;I needed lots of tests to be sure that I'd done things correctly. I mean, this was a huge change to the query engine. If I'd got it wrong, it would be a serious issue. As a consequence, this code didn't get checked in and used in the timeframe that it ought to have. But finally, I felt it was correct, and I ran my 10 minute queries against the PLoS data.&lt;br /&gt;&lt;br /&gt;Now the queries were running at a little over a minute. Well, this was an order of magnitude improvement, but still 30 times slower than I expected. What had happened? I checked where it was spending it's time, and it was still in a &lt;code&gt;sort()&lt;/code&gt; method. Sigh. At a guess, I missed something in the code that allows sorting when needed, and avoids it the rest of the time.&lt;br /&gt;&lt;br /&gt;Unfortunately, the time taken to get to that point had led to other things becoming important, and I didn't pursue the issue. Also, the only way to take advantage of this change was to update Topaz to use &lt;code&gt;SELECT NONDISTINCT&lt;/code&gt; but that keyword was going to fail unless being run on a new Mulgara server. This meant that I couldn't update Topaz until I knew they'd moved to a newer Mulgara, and that didn't happen for a long time. Consequently, PLoS didn't see a performance change, and I ended up trying to improve other things for them rather than tracking it down. In retrospect, I confess that this was a huge mistake. PLoS recently reminded me of their speed issues with certain queries, but now they're looking at other solutions to it. Well, it's my fault that I didn't get it all going for them but that doesn't mean I should never do it, so I'm back at it again.&lt;br /&gt;&lt;br /&gt;The problem queries only look really slow when executed against a large amount of data, so I had to get back to the PLoS dataset. The queries also meant running the Topaz setup, since they make use of the Topaz Lucene resolvers. So I updated Topaz and built the system.&lt;br /&gt;&lt;br /&gt;Since I was going to work on Topaz, I figured I ought to add in the use of &lt;code&gt;NONDISTINCT&lt;/code&gt;. This was trickier than I expected, since it looked like the Topaz code was not only trying to generate TQL code, it was also trying to re-parse it to do transformations on it. The parser in question was &lt;a href="http://www.antlr.org/"&gt;Antlr&lt;/a&gt; which is one that I've limited experience with, so I spent quite a bit of time trying to figure out what instances of &lt;code&gt;SELECT&lt;/code&gt; could have a &lt;code&gt;NONDISTINCT&lt;/code&gt; appended to it. In the end, I decided that all of the parsing was really for their own &lt;a href="http://topazproject.org/trac/wiki/Topaz/Manual/Section11#ObjectQueryLanguage"&gt;OQL&lt;/a&gt; language (which looks a lot like TQL). I hope I was right!&lt;br /&gt;&lt;br /&gt;After spending way to long on Topaz, I took the latest updates from SVN, and compiled the Topaz version of Mulgara. Then I ran it to test where it was spending time in the query.&lt;br /&gt;&lt;br /&gt;Unfortunately, I immediately started getting regular INFO messages of the form:&lt;pre&gt;&lt;code&gt;MulticastKeepaliveHeartbeatSender&gt; Unexpected throwable in run thread. Continuing...null&lt;br /&gt;java.lang.NullPointerException&lt;br /&gt; at net.sf.ehcache.distribution.MulticastKeepaliveHeartbeatSender$MulticastServerThread.createCachePeersPayload(MulticastKeepaliveHeartbeatSender.java:180)&lt;br /&gt; at net.sf.ehcache.distribution.MulticastKeepaliveHeartbeatSender$MulticastServerThread.run(MulticastKeepaliveHeartbeatSender.java:137)&lt;/code&gt;&lt;/pre&gt;Now Mulgara doesn't make use of ehcache at all. That's purely a Topaz thing, and my opinion to date has been that it's more trouble than it's worth. This is another example of it. I really don't know what could be going on here, but luckily I kept open the window where I updated the source from SVN, and I can see that someone has modified the class:&lt;pre&gt;&lt;code&gt;  org.topazproject.mulgara.resolver.CacheInvalidator&lt;/code&gt;&lt;/pre&gt;I can't guarantee that this is the problem, but I've never seen it before, and no other changes look related.&lt;br /&gt;&lt;br /&gt;But by this point I'd reached the end of my day, so I decided I should come back to it in the morning (errr, maybe that will be &lt;em&gt;after&lt;/em&gt; the SPARQL Working Group meeting).&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Jetty&lt;/h3&gt;&lt;br /&gt;Despite that describing a good portion of my day (at least, those parts not spent in correspondence), I also got a few things done over the weekend. The first of these was a request for a new feature in the Mulgara &lt;a href="http://jetty.codehaus.org/jetty/"&gt;Jetty&lt;/a&gt; configuration.&lt;br /&gt;&lt;br /&gt;One of our users has been making heavy use of the REST API (yay! That time wasn't wasted after all!) and had found that Jetty was truncating their POST methods. It turns out that Jetty restricts this to 200,000 characters by default, and it wasn't enough for them. I do have to wonder what they're sticking in their queries, but OK. Or maybe they're POSTing RDF files to the server? That might explain it.&lt;br /&gt;&lt;br /&gt;Jetty normally lets you define a lot of configuration with system parameters from the command line, or with an XML configuration file, and I was asked if I could allow either of those methods. Unfortunately, our embedded use of Jetty doesn't allow for either of these, but since I was shown exactly what was wanted I was able to track it down. A bit of 'grepping' for the system parameter showed me the class that gets affected. Then some Javadoc surfing took me to the appropriate interface (Context), and then I was able to go grepping through Mulgara's code. I found where we had access to these Contexts, and fortunately the Jetty configuration was located nearby. Up until this point Jetty's Contexts had not been configurable, but now they are. I only added in the field that had been requested, but everything is set up to add more with just two lines of code each - plus the XSD to describe the configuration in the configuration file.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;jSPARQLc&lt;/h3&gt;&lt;br /&gt;My other weekend task was to add &lt;code&gt;CONSTRUCT&lt;/code&gt; support to &lt;a href="http://code.google.com/p/jsparqlc/"&gt;jSPARQLc&lt;/a&gt;. Sure, no one is using it yet, but Java needs so much boilerplate to make SPARQL work, that I figure it will be of use to &lt;em&gt;someone&lt;/em&gt; eventually – possibly me. I'm also finding it to be a good learning experience for why JDBC is the wrong paradigm for SPARQL. I'm not too worried about that though, as the boilerplate stuff is all there, and it would be could easy to clean it up to something that doesn't try to conform to SPARQL. But for the moment it's trying to make SPARQL look like JDBC, and besides there's already another library that isn't trying to look like JDBC. I'd better stick to my niche.&lt;br /&gt;&lt;br /&gt;I've decided that I'm definitely going to go with StAX to make forward-only result sets. However, I'm not sure if there is supposed to be a standard configuration for JDBC to set the desired form of the result set, so I haven't started on that yet.&lt;br /&gt;&lt;br /&gt;The result of a &lt;code&gt;CONSTRUCT&lt;/code&gt; is a graph. By default we can expect a RDF/XML document, though other formats are certainly possible. I'm not yet doing content negotiation with jSPARQLc, though that may need to be configurable, so I wanted to keep an open mind about what can be returned. That means that standard &lt;code&gt;SELECT&lt;/code&gt; queries could return &lt;a href="http://www.w3.org/TR/rdf-sparql-XMLres/"&gt;SPARQL Query Result XML&lt;/a&gt; or &lt;a href="http://www.w3.org/TR/rdf-sparql-json-res/"&gt;JSON&lt;/a&gt;, and &lt;code&gt;CONSTRUCT&lt;/code&gt; queries could result in RDF/XML, &lt;a href="http://www.w3.org/DesignIssues/Notation3"&gt;N3&lt;/a&gt;, or &lt;a href="http://n2.talis.com/wiki/RDF_JSON_Specification"&gt;RDF-JSON&lt;/a&gt; (Mulgara supports all but the last, but maybe I should add that one in. I've already left space for it).&lt;br /&gt;&lt;br /&gt;Without content negotiation, I'm keeping to the XML formats for the moment, with the framework looking for the other formats (though it will report that the format is not handled). Initially I thought I might have to parse the top of the file, until I cursed myself for an idiot and looked up the content type in the header. Once the parameters have been removed, I could use the content type to do a "look up" for a parser constructor. I like this approach, since it means that any new content types I want to handle just become new entries in the look-up table.&lt;br /&gt;&lt;br /&gt;This did leave me wondering if every SPARQL endpoint was going to fill in the Content-Type header, but I presume they will. I can always try a survey of servers once I get more features into the code.&lt;br /&gt;&lt;br /&gt;Parsing an RDF/XML graph is a complex process that I had no desire to attempt (it could take all week to get it right - if not longer). Luckily, Jena has the ARP parser to do the job for me. However, the ARP parser is part of the main Jena jar, which seemed excessive to me. Fortunately, Jena's license is BSD, so it was possible to bring the ARP code in locally. I just had to update the packages to make sure it wouldn't conflict if anyone happens to have their own Jena in the classpath.&lt;br /&gt;&lt;br /&gt;Funnily enough, while editing the ARP files (I'm doing this project "oldschool" with &lt;a href="http://www.vim.org/"&gt;VIM&lt;/a&gt;). I discovered copyright notices for Plugged In Software. For anyone who doesn't know, Plugged In Software was the company that created the Tucana Knowledge Store (later to be open sourced as Kowari, then renamed to Mulgara). The company changed its name later on to match the software, but this code predated that. Looking at it, I seem to recall that the code in question was just a few bugfixes that Simon made. But it was still funny to see.&lt;br /&gt;&lt;br /&gt;Once I had ARP installed, I could parse a graph, but into what? I'm not trying to run a triplestore here, just an API. So I reused an interface I came up with when I built my SPARQL test framework when I needed to read a graph. The interface isn't fully indexed, but it lets you do a lot of useful things if you want to navigate around a graph. For instance, it lets you ask for the list of properties on a subject, or to find the value(s) of a particular subject's property, or to construct a list from an RDF collection (usually an iterative operation). Thinking that I might also want to ask questions about particular objects (or even predicates) I've added in the other two indexes this time, but I'm in two minds about whether they really need to be there.&lt;br /&gt;&lt;br /&gt;The original code for my graph interface was in Scala, and I was tempted to bring it in like this. But one of the purposes of this project was to be lightweight (unfortunately, I lost that advantage when I discovered that ARP needs &lt;a href="http://xerces.apache.org/"&gt;Xerces&lt;/a&gt;), so I thought I should try to avoid the Scala JARs. Also, I thought that the exercise of bringing the Scala code into Java would refresh the API for me, as well as refresh me on Scala (which I haven't used for a couple of months). It did all of this, as well as having the effect of reminding me why Scala is so superior to Java.&lt;br /&gt;&lt;br /&gt;Anyway, the project is getting some meat to it now, and it's been fun to work on in my evenings, and while I've been stuck indoors on my weekends. If anyone has any suggestions for it, then please feel free to let me know.&lt;br /&gt;&lt;br /&gt;&lt;div style="margin-top: 10px; height: 15px;" class="zemanta-pixie"&gt;&lt;a class="zemanta-pixie-a" href="http://reblog.zemanta.com/zemified/9128f86b-b7c9-45cc-878a-b12d0c138756/" title="Reblog this post [with Zemanta]"&gt;&lt;img style="border: medium none; float: right;" class="zemanta-pixie-img" src="http://img.zemanta.com/reblog_e.png?x-id=9128f86b-b7c9-45cc-878a-b12d0c138756" alt="Reblog this post [with Zemanta]"&gt;&lt;/a&gt;&lt;span class="zem-script more-related pretty-attribution"&gt;&lt;script type="text/javascript" src="http://static.zemanta.com/readside/loader.js" defer="defer"&gt;&lt;/script&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6848574-2991388790499106088?l=gearon.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://gearon.blogspot.com/2010/04/multitasking-at-moment-i-feel-like-i.html</link><author>noreply@blogger.com (Quoll)</author><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6848574.post-67221495540229172</guid><pubDate>Sat, 24 Apr 2010 21:39:00 +0000</pubDate><atom:updated>2010-04-24T20:49:09.949-05:00</atom:updated><title /><description>&lt;h3&gt;Program Modeling&lt;/h3&gt; &lt;br /&gt;The rise of &lt;a href="http://en.wikipedia.org/wiki/Model-driven_architecture"&gt;Model Driven Architecture&lt;/a&gt; in development, has created a slew of modeling frameworks that can be used as tools for this design process. While some MDA tools involve a static design and a development process, others seek to have an interactive model that allows developers to work with the model at runtime. Since an RDF store allows models developed in RDFS and OWL to be read and updated at runtime, it therefore seems natural to use the modeling capabilities of RDFS and OWL to provide yet another framework for design and development.  RDF also has the unusual characteristic of seamlessly mixing instance data with model data (the so-called "ABox" and "TBox"), giving the promise of a system that allows both dynamic modeling and persistent data all in a single integrated system. However, there appear to be some common pitfalls that developers fall prey to, which make this approach less useful than it might otherwise be.&lt;br /&gt;&lt;br /&gt;For good or ill, two of the most common languages used on large scale projects today are Java and C#. Java in particular also has good penetration on the web, though for smaller projects more modern languages, such as Python or Ruby, are more often deployed. There are lots of reasons for Java and C# to be so popular on large projects: They are widely known and it can be easy to assemble a team around it; both the JVM and .Net engines have demonstrated substantial benefits in portability, memory management and optimization through JIT compiling; they have established a reputation of stability over their histories. Being a fan of functional programming and modern languages, I often find Java to be frustrating, but these strengths often bring me back to Java again, despite its shortcomings. Consequently, it is usually with Java or C# in mind that MDA projects start out trying to use OWL modeling.&lt;br /&gt;&lt;br /&gt;On a related note, enterprise frameworks regularly make use of &lt;a href="http://www.hibernate.org/"&gt;Hibernate&lt;/a&gt; to store and retrieve instance data using a relational database (RDBMS). Hibernate maps object definitions to an equivalent representation in a database table using an Object-Relational Mapping (ORM). While not a formal MDA modeling paradigm, a relational database schema forms a model, in the same way that UML or MOF does (only less expressive). While an ORM is not a tool for MDA, it nevertheless represents the code of a project in a form of model, with instance data that is interactive at runtime.&lt;br /&gt;&lt;br /&gt;Unfortunately, the ORM approach offers a very weak form of modeling, and it has no capability to dynamically update at runtime. Several developers have looked at this problem and reasoned that perhaps these problems could be solved by modeling in RDF instead. After all, an RDF store allows a model to be updated as easily as the data, and the expressivity of OWL is far greater than that of the typical RDBMS schema. To this end, we have seen a few systems which have created an Object-Triples Mapping (OTM), with some approaches demonstrating more utility than others.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Static Languages&lt;/h3&gt;&lt;br /&gt;When OTM approaches are applied to Java and C#, we typically see an RDFS schema that describes the data to be stored and retrieved. This can be just as effective as an ORM on a relational database, and has the added benefit of allowing expansions of the class definitions to be implemented simply as extra data to be stored, rather than the whole change management demanded with the update of a RDBMS. An RDF store also has the benefit of being able to easily annotate the class instances being stored, though this is not reflected in the Java/C# classes and requires a new interface to interact with it. Unfortunately, the flow of modeling information through these systems is typically one-way, and does not make use of the real power being offered by RDF.&lt;br /&gt;&lt;br /&gt;ORM in Hibernate embeds the database schema into the programming language by mapping table schemas to class descriptions in Java/C# and table entries to instances of those classes in runtime memory. Perhaps through this example set by ORM, we often see OTM systems mapping OWL classes to Java/C# classes, and RDF instances to Java/C# instances. This mapping seems intuitive, and it has its uses, but it is also fundamentally flawed.&lt;br /&gt;&lt;br /&gt;The principle issue with OTM systems that attempt to embed themselves in the language, is that static languages (like the popular Java and C# languages) are unable to deal with arbitrary RDF. RDF and OWL work on an Open World Assumption, meaning that there may well be more of the model that the system is not yet aware of, and should be capable of taking into consideration. However, static languages are only able to update class definitions outside of runtime, meaning that they cannot accept new modeling information during runtime. It &lt;em&gt;is&lt;/em&gt; possible to define a new class at runtime using a bytecode editing library, but then the class may only be accessed through meta-programming interfaces like reflection, defeating the purpose of the embedding in the first place. This is what is meant by the flow of modeling information being one-way: updates to the program code can be dynamically handled by a model in an RDF store, but updates to the model cannot be reflected by corresponding updates in the program.&lt;br /&gt;&lt;br /&gt;But these programming languages are Turing Complete. We ought to be able to work with dynamic modeling in triples with static languages, so how do we approach it? The solution is to abandon the notion of embedding the model into the language. These classes are not dynamically reconfigurable, and therefore they cannot update with new model updates. Instead, object structures that &lt;em&gt;can&lt;/em&gt; be updated can be used to represent the model. Unfortunately, this no longer means that the model is being used to model the programming code (as desired in MDA), but it does mean that the models are now accurate, and can represent the full functionality being expressed in the RDFS/OWL model.&lt;br /&gt;&lt;br /&gt;As an example, it is relatively easy to express an instance of a class as a Java Map, with properties being the keys, and the "object" values being the values in the map. This is exactly the same as the way structures are expressed in Perl, so it should be a familiar approach to many developers. These instances should be constructed with a factory that takes a structure that contains the details of an OWL class (or, more likely, that subset of OWL that is relevant to the application). In this way it is possible to accurately represent any information found in an RDF store, regardless of foreknowledge. I can personally attest to the ease and utility of this approach, having written a version of it over two nights, and then providing it to a colleague who used it along with Rails to develop an impressive prototype ontology and data editor, complete with rules engine, all in a single day. I expect others can cite similar experiences.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Really Embedding&lt;/h3&gt;&lt;br /&gt;So we've seen that static languages like C# and Java can't dynamically embed "Open" models like RDF/OWL, but are there languages that can?&lt;br /&gt;&lt;br /&gt;In the last decade we've seen a lot of "dynamic" languages gaining popularity, and to various extents, several of these offer that functionality. The most obvious example is &lt;a href="http://www.ruby-lang.org/en/"&gt;Ruby&lt;/a&gt;, which has explicit support for opening up already defined classes in order to add new methods, or redefine existing ones. Smalltalk has &lt;a href="http://coweb.cc.gatech.edu/cs2340/6243"&gt;Metaprogramming&lt;/a&gt;. Meta-programming isn't an explicit feature for many other languages, but so long as the language is dynamic there is often a way, such as these methods for &lt;a href="http://blog.ianbicking.org/2007/08/08/opening-python-classes/"&gt;Python&lt;/a&gt; and &lt;a href="http://transfixedbutnotdead.com/2010/01/14/anyone-for-perl-6-metaprogramming/"&gt;Perl&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Despite the opportunity to embed models into these languages, I'm unaware of any systems which do so. It seems that the only forms of OTM I can find are in the languages which already have an ORM, and are probably better used with that paradigm. There are numerous libraries for accessing RDF in each of the above languages, such as the Redland RDF Language bindings for &lt;a href="http://librdf.org/docs/ruby.html"&gt;Ruby&lt;/a&gt; and &lt;a href="http://librdf.org/docs/python.html"&gt;Python&lt;/a&gt;, the &lt;a href="http://raa.ruby-lang.org/project/rena/"&gt;Rena&lt;/a&gt;, and &lt;a href="http://activerdf.org/"&gt;ActiveRDF&lt;/a&gt; in Ruby, &lt;a href="http://www.rdflib.net/"&gt;RDFLib&lt;/a&gt; and &lt;a href="http://infomesh.net/pyrple/"&gt;pyrple&lt;/a&gt; in Python, &lt;a href="http://www.perlrdf.org/"&gt;Perl RDF&lt;/a&gt;... the list goes and continues to grow. But none of the libraries I know perform any kind of language embedding in a dynamic language. My knowledge in this space is not exhaustive, but the lack of obvious candidates tells a story on its own.&lt;br /&gt;&lt;br /&gt;Is this indicative of dynamic languages not needing the same kind of modeling storage that static languages seem to require? Java and C# often used Hibernate and similar systems in large scale commercial applications with large development teams, while dynamic languages are often used by individuals or small groups to quickly put together useful systems that aim at a very different target market. But as commercial acceptance of dynamic languages develops further, perhaps this kind of modeling would be useful in future. In fact a good modeling library like this could well show a Java team struggling with their own version of an OTM, just what they've been missing in their closed world.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Topaz&lt;/h3&gt;&lt;br /&gt;I wrote this essay partly out of frustration with a system I've worked with called &lt;a href="http://www.topazproject.org/trac/"&gt;Topaz&lt;/a&gt;. Topaz is a very clever piece of OTM code, written for Java, and built over my own project &lt;a href="http://mulgara.org/"&gt;Mulgara&lt;/a&gt;. However, Topaz suffers from all of the closed world problems I outlined above, without any apparent attempt to mitigate the use of RDF by reading extra annotations, etc. It has been used by the &lt;a href="http://www.plos.org/"&gt;Public Library of Science&lt;/a&gt; for their data persistence, but they have been unhappy with it, and it will soon be replaced.&lt;br /&gt;&lt;br /&gt;While performance in Mulgara (something I'm working on), in Topaz's use of Mulgara, and in Topaz itself, has been an issue, I believe that a deeper problem lay in the use of a dynamic system to represent static data. My knowledge of Topaz has me wondering why the system didn't simply choose to use Hibernate. I'm sure the used of RDF and OWL provided some functionality that isn't easy accomplished by Hibernate, but I don't see the benefits being strong enough to make it worth the switch to a dynamic model.&lt;br /&gt;&lt;br /&gt;For my money, I'd either adopt the standard static approach that so many systems already employ to great effect, or go the whole hog and design an OTM system that is truly dynamic and open.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6848574-67221495540229172?l=gearon.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://gearon.blogspot.com/2010/04/program-modeling-rise-of-model-driven.html</link><author>noreply@blogger.com (Quoll)</author><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6848574.post-6950581414187666399</guid><pubDate>Thu, 22 Apr 2010 02:26:00 +0000</pubDate><atom:updated>2010-04-21T22:43:51.857-05:00</atom:updated><title /><description>&lt;h3&gt;Work&lt;/h3&gt; I've had a number of administrative things to get done this week, since work will be taking a dramatic new turn soon. I've been missing working in a team, so that part will be good, but there are too many unknowns right now, including a visa nightmare that has been unceremoniously dumped in my lap. So, I'm stressed and have a lot to do. But that doesn't mean I'm not working.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Multi-Results&lt;/h3&gt;&lt;br /&gt;I'd recently been asked to allow the HTTP interfaces to return multiple results. One look at the &lt;a href="http://www.w3.org/TR/rdf-sparql-XMLres/"&gt;SPARQL Query Results XML Format&lt;/a&gt; makes it clear that SPARQL isn't capable of it, but the TQL XML format has always allowed it - or at least, I think it did. The SPARQL structure is sort of flat, with a declaration of variables at the top, and bindings under it. The TQL structure is similar, but embeds it all in another element called a "query". That name seems odd (since it's a result, not a query), so I wonder if someone had intended to include the original query as an attribute of that tag. Anyway, the structure is available, so I figured I should add it.&lt;br /&gt;&lt;br /&gt;This was a little trickier than I expected, since I'd tried to abstract out the streaming of answers. This means that I could select the output type simply by using a different streaming class. For now, the available classes are SPARQL-XML, SPARQL-JSON and TQL-XML, but there could easily be others. However, I now had to modify all of those classes to handle multiple answers. Of course, the SPARQL streaming classes had to ignore them, while the TQL class didn't, but that wasn't too hard. However, I came away feeling that it was somehow messier than it ought to have been. Even so, I thought it worked OK.&lt;br /&gt;&lt;br /&gt;One bit of complexity was in handling the GET requests of TQL vs. SPARQL. In SPARQL we can only expect a single query in a GET, but TQL can have multiple queries, separated by semicolons. While I like to keep as much code as possible common to all the classes, in the end I decided that the complexity of doing this was more than it was worth, and I put special multi-query-handling code in the TQL servlet.&lt;br /&gt;&lt;br /&gt;All of this was done a little while ago, but because I was waiting on responses on the mulgara.org move, I decided not to release just yet. This was probably fortunate, since I got an email the other day explaining that subqueries were not being embedded properly. They were starting with a new &lt;code&gt;query&lt;/code&gt; element tag, but not closing with them. However, these tags should not have appeared at this level at all. The suggested patch would have worked, but it relied on checking the indentation used for pretty-printing in order to find out if the &lt;code&gt;query&lt;/code&gt; element should be opened. This would work, but was covering the problem, rather than solving it. A bit of checking, and I realized that I had code to send a header for each answer, code to send the data for the answer, but no code for the "footer". The footer would have been the closing tag for the &lt;code&gt;query&lt;/code&gt; element, and this was being handled in other code, meaning that it only came up at the top level, and not in the embedded sub-answers. This in turn meant that it wasn't always matching up to the header. So I introduced a footer method for answers (a no-op in SPARQL-XML and SPARQL-JSON) which cleaned up the process well enough that avoiding the header (and footer) on sub-answers was now easy to see and get right.&lt;br /&gt;&lt;br /&gt;So was I done? No. The email also commented on warnings of transactions not being closed. So I went looking at this, and decided that all answers were being closed properly. In confusion, I looked at the email again, and this time realized that the bug report said that they were using &lt;code&gt;POST&lt;/code&gt; methods. Since I was only dealing with queries (and not update commands) I had only gone to the &lt;code&gt;GET&lt;/code&gt; method. So I looked at &lt;code&gt;POST&lt;/code&gt;, and sure enough it was a dogs breakfast.&lt;br /&gt;&lt;br /&gt;Part of the problem with a &lt;code&gt;POST&lt;/code&gt; is that it can include updates as well as queries. Not having a standard response for an update, I had struggled a little with this in the past. In the end, I'd chosen to only output the final result of all operations, but this was causing all sorts of problems. For a start, if there was more than one query, then only the last would be shown (OK in SPARQL, not in TQL). Also, since I was ignoring so many things, it meant that I wasn't closing anything if it needed it. This was particularly galling to have wrong, since I'd finally added SPARQL support for &lt;code&gt;POST&lt;/code&gt; queries.&lt;br /&gt;&lt;br /&gt;I'd really have liked to use the same multi-result code that I had for &lt;code&gt;GET&lt;/code&gt; requests, but that didn't look like it was going to mix well with the need to support commands in the middle. In the end I copied/pasted some of the GET code (shudder) and fixed it up to deal with the result lists that I'd already built through the course of processing the &lt;code&gt;POST&lt;/code&gt; request. It doesn't look too bad, and I've commented on the redundancy and why I've allowed it, so I think it's all OK. Anyway, it's all looking good now. Given that I also have a major bugfix from a few weeks back, then I should get it out the door despite the mulgara.org shuffle not being done.&lt;br /&gt;&lt;br /&gt;I didn't mention that major bug, did I? For anyone interested, some time early last year a race bug was avoided by putting a lock into the transaction code. Unfortunately, that lock was to broad, and it prevented any other thread from reading while a transaction was being committed. This locked the database up during large commit operations. It's not the sort of thing that you're likely to see with unit tests, but I was still deeply embarrassed. At least I found it (a big thanks to the guys at PLoS for reporting this bug, and helping me find where it was).&lt;br /&gt;&lt;br /&gt;So before I get dragged into any admin stuff tomorrow morning (office admin or sysadmin), I should try to cut a release to clean up some of these problems.&lt;br /&gt;&lt;br /&gt;Meanwhile, I'm going to relax with a bit of Hadoop reading. I once talked about putting a triplestore on top of this, and it's an idea that's way overdue. I know others have tried exactly this, but each approach has been different, and I want to see what I can make of it. But I think I need a stronger background in the subject matter before I try to design something in earnest.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6848574-6950581414187666399?l=gearon.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://gearon.blogspot.com/2010/04/work-ive-had-number-of-administrative.html</link><author>noreply@blogger.com (Quoll)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6848574.post-3012391275739554247</guid><pubDate>Mon, 19 Apr 2010 16:03:00 +0000</pubDate><atom:updated>2010-04-19T20:17:34.202-05:00</atom:updated><title /><description>&lt;h3&gt;jSPARQLc&lt;/h3&gt; &lt;br /&gt;I spent Sunday and a little bit of this afternoon finishing up the code and testing for the SPARQL API. The whole thing had just a couple of typos in it, which surprised me no end, because I used VIM and not Eclipse. I must be getting more thorough as I age. :-)&lt;br /&gt;&lt;br /&gt;Anyway, the whole thing works, though its limited in scope. To start with, the only data accessing methods I wrote were &lt;code&gt;getObject(int)&lt;/code&gt; and &lt;code&gt;getObject(String)&lt;/code&gt;. Ultimately, I'd like to include many of the other &lt;code&gt;get...&lt;/code&gt; methods, but these would require tedious mapping. For instance, &lt;code&gt;getInt()&lt;/code&gt; would need to map &lt;code&gt;xsd:int&lt;/code&gt;, &lt;code&gt;xsd:integer&lt;/code&gt;, and all the other integral types to an integer. I've done this work in some of the internal APIs for Mulgara (particularly when dealing with SPARQL), so I know how tedious it is. I suppose I can copy/paste a good portion of it out of Mulgara (it's all Apache 2.0), but for the moment I wanted to get it up and running the way I said.&lt;br /&gt;&lt;br /&gt;If I were to do all of this, then there are all sorts of mappings that can be done between data types. For instance, &lt;code&gt;xsd:base64Binary&lt;/code&gt; would be good for Blobs. I could even introduce some custom data types to handle things like serialized Java objects, with a data type like: &lt;code&gt;java:org.example.ClassName&lt;/code&gt;. Actually, that looks familiar. I should see if anyone has done it.&lt;br /&gt;&lt;br /&gt;Anyway, as I progressed, I found that while it was straight forward enough to get basic functionality in, the JDBC interfaces are really inappropriate.&lt;br /&gt;&lt;br /&gt;To start with, JDBC usually accesses a "cursor" at the server end, and this is accessed implicitly by &lt;code&gt;ResultSet&lt;/code&gt;. It's not absolutely necessary, but moving backwards and forwards through a result that isn't entirely in memory really does need a server-side cursor. Since I'm doing everything in memory right now, then I was able to do an implementation that isn't &lt;code&gt;TYPE_FORWARD_ONLY&lt;/code&gt;, but if I were to move over to using StAX (in the comments from my last entry) then I'd have to fall back to that.&lt;br /&gt;&lt;br /&gt;The server-side cursor approach also makes it possible to write to a &lt;code&gt;ResultSet&lt;/code&gt;, since SQL results are closely tied to the tables they represent. However, this doesn't really apply to RDF, since statements can never be updated, only added and removed. SPARQL Update is coming (I ought to know, as I'm the editor for the document), but there is no real way to convert the update operations on a &lt;code&gt;ResultSet&lt;/code&gt; back into SPARQL-Update operations over the network. It might be theoretically, possible but it would need a lot of communication with the server, and it doesn't even make sense. After all, you'd be trying to map one operation paradigm to a completely different one. Even if it could be made to work, it would be confusing to use. Since my whole point in writing this API was to simplify things for people who are used to JDBC, then it would be self defeating.&lt;br /&gt;&lt;br /&gt;So if this API were to allow write operations as well, then it would need a new approach, and I'm not sure what that should be. Passing SPARQL Update operations straight through might be the best bet, though it's not offering a lot of help (beyond doing all the HTTP work for you).&lt;br /&gt;&lt;br /&gt;The other thing that I noticed was that a blind adherence to the JDBC approach created a few classes that I don't think are really needed. For instance, the &lt;code&gt;ResultSetMetaData&lt;/code&gt; interface only contains two methods that make any sense from the perspective of SPARQL: &lt;code&gt;getColumnCount()&lt;/code&gt; and &lt;code&gt;getColumnName()&lt;/code&gt;. The data comes straight out of the ResultSet, so I would have put them there if the choice were mine. The real metadata is in the list of "link" elements in the result set, but this could encoded with anything (even text) so there was no way to make that metadata fit the JDBC API. Instead, I just let the user ask for the last of links directly (creating a new method to do so).&lt;br /&gt;&lt;br /&gt;Another class that didn't make too much sense to me was &lt;code&gt;Statement&lt;/code&gt;. It's a handy place to record some state about what you've doing on a &lt;code&gt;Connection&lt;/code&gt;, but other than that, it just seems to proxy the &lt;code&gt;Connection&lt;/code&gt; it's attached to. I see there some options for caching (that I've never used myself when I've been on JDBC), so I suspect that it does more than I give it credit for, but for the moment it just appears to be an inconvenience.&lt;br /&gt;&lt;br /&gt;Anyway, I thought I'd put it up somewhere, and since I haven't tried Google's code repository before, I've put it up there. It's a Java SPARQL Connectivity library, so for lack of anything better I called it &lt;a href="http://code.google.com/p/jsparqlc/"&gt;jSPARQLc&lt;/a&gt; (maybe JRC for Java RDF Connectivity would have been better, but there are lots of JRC things out there, but jSPARQLc didn't return any hits from Google, so I went with that). It's very raw and has very little configuration, but it passes it's tests.  :-)&lt;br /&gt;&lt;br /&gt;Speaking of tests, if you want to try it, then the connectivity tests won't pass until you've done the following:&lt;ul&gt;&lt;li&gt;Start a SPARQL endpoint at http://localhost:8080/sparql/ (the sourcecode in the test needs to change if your endpoint is elsewhere).&lt;/li&gt;&lt;li&gt;Create a graph with the URI &lt;code&gt;&amp;lt;test:data&amp;gt;&lt;/code&gt;&lt;/li&gt;&lt;li&gt;Loaded the data in &lt;em&gt;test.n3&lt;/em&gt; up into it (this file is in the root directory)&lt;/li&gt;&lt;/ul&gt;I know I shouldn't have hardcoded some of this, but it was just a test on a 0.1 level project. If it seems useful, and/or you have ideas for it, then please let me know.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Mulgara&lt;/h3&gt;&lt;br /&gt;Other than this, I have some administration I need to do to get both Mulgara and Topaz onto another server, and this seems to slow everything down as I wait for the admins to get back to me. It's also why there hasn't been a Mulgara release recently, even though it's overdue. However, I just got a message from an admin today, so hopefully things have progressed. Even so, I think I'll just cut the release soon anyway.&lt;br /&gt;&lt;br /&gt;One fortunate aspect of the delayed release was a message I got from David Smith about how some resources aren't being closed in the TQL REST interface (when subqueries are used). He's sent me a patch, but I need to spend some time figuring out why I got this wrong, else I could end up hiding the real problem. That's a job for the morning... right after the SPARQL Working Group meeting. Once all of that is resolved, I'll get a release out, and try to figure out what I can do to speed up the server migration.&lt;br /&gt;&lt;br /&gt;Oh, and I need to update Topaz to take advantage of some major performance improvements in Mulgara, and then I need to find even  more performance improvements. Hopefully I'll be onto some of that by the afternoon, but I don't want to promise the moon only to come back tomorrow night and confess I got stuck on the same thing all day.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6848574-3012391275739554247?l=gearon.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://gearon.blogspot.com/2010/04/jsparqlc-i-spent-sunday-and-little-bit.html</link><author>noreply@blogger.com (Quoll)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6848574.post-2768812035285723292</guid><pubDate>Sun, 18 Apr 2010 00:08:00 +0000</pubDate><atom:updated>2010-04-17T20:46:55.618-05:00</atom:updated><title /><description>&lt;h3&gt;SPARQL API&lt;/h3&gt; Every time I try to use SPARQL with Java I keep running into all that minutiae that Java makes you deal with. The &lt;a href="http://hc.apache.org/"&gt;HttpComponents from Apache&lt;/a&gt; make things easier, but there's still a loto f code that has to be written. Then after you get your data back, you still have to process it, which means XML or JSON parsing. All of this means a lot of code, just to get a basic framework going.&lt;br /&gt;&lt;br /&gt;I know there are a lot of APIs out there for working with RDF engines, but there aren't many for working directly over SPARQL. I eventually had a look and found &lt;a href="http://sparql.sourceforge.net/"&gt;SPARQL Engine for Java&lt;/a&gt;, but this seemed to have more client-side processing than I'd expect. I haven't looked too carefully at it, so this may be incorrect, but I thought it would be worthwhile to take all the boilerplate I've had to put together in the past, and see if I can glue it all together in some sensible fashion. Besides, today's Saturday, meaning I don't have to worry about my regular job, and I'm recovering from a procedure yesterday, so I couldn't do much more than sit at the computer anyway.&lt;br /&gt;&lt;br /&gt;One of my inspirations was a conversation I had with &lt;a href="http://bblfish.net/"&gt;Henry Story&lt;/a&gt; (hmmm, Henry's let that link get badly out of date) a couple of years ago about a standard API for RDF access, much like &lt;a href="http://java.sun.com/javase/6/docs/technotes/guides/jdbc/"&gt;JDBC&lt;/a&gt;. At the time I didn't think that Sun could make something like that happen, but if there were a couple of decent attempts at it floating around, then some kind of pseudo standard could emerge. I never tried it before, but today I thought it might be fun to try.&lt;br /&gt;&lt;br /&gt;The first thing I remembered was that when you write a library, you end up writing all sorts of tedious code while you consider the various ways that a user might want to use it. So I stuck to the basics, though I did add in various options as I dealt with individual configuration options. So it's possible to set the &lt;em&gt;default-graph-uri&lt;/em&gt; as a single item as well as with a list (since a lot of the time you only want to set one graph URI). I was eschewing Eclipse today, so I ended up making use of VIM macros for some of my more tedious coding. The tediousness also reminded me again why I like Scala, but given that I wanted it to look &lt;em&gt;vaguely&lt;/em&gt; JDBC-like, I figured that the Java approach was more appropriate.&lt;br /&gt;&lt;br /&gt;I remember that TKS (the name of the first incarnation of the Mulgara codebase) had attempted to implement JDBC. Apparently, a good portion of the API, was implemented, but the there were some elements that just didn't fit. So from the outset I avoided trying to duplicate that mistake. Instead, I decided to cherry pick the most obvious features, abandon anything that doesn't make sense, and add in a couple of new features where it seems useful or necessary. So while some of it might &lt;em&gt;look&lt;/em&gt; like JDBC, it won't have anything to do with it.&lt;br /&gt;&lt;br /&gt;I found a piece of trivial JDBC code I'd used to test something once-upon-a-time, and tweaked it a little to look like something I might try to do with SPARQL. My goal was to write the library that would make this work, and then take it from there. This is the example:&lt;br /&gt;&lt;pre&gt;&lt;code&gt;    final String ENDPOINT = "http://localhost:8080/sparql/";&lt;br /&gt;    Connection c = DriverManager.getConnection(ENDPOINT);&lt;br /&gt;&lt;br /&gt;    Statement s = c.createStatement();&lt;br /&gt;    s.setDefaultGraph("test:data");&lt;br /&gt;    ResultSet rs = s.executeQuery("SELECT * WHERE { ?s ?p ?o }");&lt;br /&gt;    rs.beforeFirst();&lt;br /&gt;    while (rs.next()) {&lt;br /&gt;      System.out.println(&lt;br /&gt;              rs.getObject(1).toString() + ", " +&lt;br /&gt;              rs.getObject(2) + ", " +&lt;br /&gt;              rs.getObject(3));&lt;br /&gt;    }&lt;br /&gt;    rs.close();&lt;br /&gt;    c.close();&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;My first thought was that this is not how I would design the API (the "Statement" seems a little superfluous), but that wasn't the point.&lt;br /&gt;&lt;br /&gt;Anyway, I've nearly finished it, but I'm dopey from pain medication, so I thought I'd write down some thoughts about it, and pick it up again in the morning. So if anyone out there is reading this (which I doubt, given how little I write here) these notes are more for me than for you, so don't expect to find it interesting.  :-)&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Observations&lt;/h3&gt;&lt;br /&gt;The first big difference to JDBC is the configuration. A lot of JDBC is either specific to a particular driver, or to RDBM Systems in general. This goes for the structure of the API as well as the configuration. For instance, &lt;code&gt;ResultSet&lt;/code&gt; seems to be heavily geared towards cursors, which SPARQL doesn't support. I was momentarily tempted to try emulating this functionality through LIMIT and OFFSET, but that would have involved a lot of network traffic, and could potentially interfere with the user trying to use these keywords themselves. Getting the row number (&lt;a href="http://java.sun.com/javase/6/docs/api/java/sql/ResultSet.html#getRow()"&gt;getRow&lt;/a&gt;) would have been really tricky if I'd gone that way too.&lt;br /&gt;&lt;br /&gt;But ResultSet was one of the last things I worked on today, so I'll rewind.&lt;br /&gt;&lt;br /&gt;The first step was making the HTTP call. I usually use GET, but I've recently added in the &lt;a href="http://www.w3.org/TR/rdf-sparql-protocol/#query-bindings-http"&gt;POST binding&lt;/a&gt; for SPARQL querying in Mulgara , so I made sure the client code can do both. For the moment I'm automatically choosing to do a POST query when the URL gets above 1024 characters (I believe that was the URL limit for some version of IE), but I should probably make the use of POST vs. GET configurable. Fortunately, building parameters was identical for both methods, though they get put into difference places.&lt;br /&gt;&lt;br /&gt;Speaking of parameters, I need to check this out, but I believe that graph URIs in SPARQL do not get encoded. Now that's not going to work if they contain their own queries (any why wouldn't they), but most graphs don't do that, so it's never bitten me before. Fortunately, doing a URL-Decode on an unencoded graph URI is usually safe, so that's how I've been able to get away with it until now. But as a client that has to do the encoding I needed to think more carefully about it.&lt;br /&gt;&lt;br /&gt;From what I can tell, the only part that will give me grief is the query portion of the URI. So I checked out the query, and if there wasn't one, I just sent the graph unencoded. If there was one, then I'd encode just the query, add it to the URI, and then see if decoding got me back to the original. If it does, then I send that. Otherwise, I just encode the whole graph URI and send that. As I write it down, it looks even more like a hack than ever, but so far it seems to work.&lt;br /&gt;&lt;br /&gt;So now that I have all the HTTP stuff happening, what about the response? Since answers can be large, my first thought was &lt;a href="http://java.sun.com/javase/6/docs/api/org/xml/sax/package-summary.html"&gt;SAX&lt;/a&gt;. Well, actually, my first thought was Scala, since I've already parsed SPARQL response documents with Scala's XML handling, and it was trivial. But I'm Java so that means SAX or DOM. SAX can handle large documents, but possibly more importantly, I've always found SAX easier to deal with than DOM, so that's the way I went.&lt;br /&gt;&lt;br /&gt;Because SAX operates on a stream, I thought I could build a stream handler, but I think that was just the medication talking, since I quickly remembered that it's an event model. The only way I could do it as a stream would be if I buit up a queue with one thread writing at one end and the consuming thread taking data off at the other. That's possible, but it's hard to test if it scales, and if the consumer doesn't get drain the queue in a timely manner, then you can cause problems for the writing end as well. It's possible to slow up the writer by not returning from the even methods until the queue has some space, but that seems clunky. Also, when you consider that a ResultSet is supposed to be able to rewind and so forth, a streaming model just doesn't work.&lt;br /&gt;&lt;br /&gt;In the end, it seemed that I would have to have my ResultSets in memory. This is certainly easier that any other option I could think of, and the size of RAM these days means that it's not really a big deal. But it's still in the back of my mind that maybe I'm missing an obvious idea.&lt;br /&gt;&lt;br /&gt;The other thing that came to mind is to create an API to provides object events in the same way that SAX provides events for XML elements. This would work fine, but it's nothing like the API I'm trying to look like, so I didn't give that any serious thought.&lt;br /&gt;&lt;br /&gt;So now I'm in the midst of a SAX parser. There's a lot of work in there that I don't need when working with other languages, but it does give you a comfortable feeling knowing that you have such fine-grained control over the process, Java enumerations have come in handy here, as I decided to go with a state-machine approach. I don't use this very often (outside of hardware design, where I've always liked it), but it's made the coding so straightforward it's been a breeze.&lt;br /&gt;&lt;br /&gt;One question I have, is if the parser should create a ResultSet object, or if it should &lt;em&gt;be&lt;/em&gt; the object. It's sort of easy to just create the object with the InputStream as the parameter for the constructor, but then the object you get back could be either a boolean result or a list of variable bindings, and you have to interrogate it to find out which one it is. The alternative is to use a factory that returns different types of result sets. I initially went with the former because both have to parse the header section, but now that I've written it out, I'm thinking that the latter is the better way to go. I'll change it in the morning.&lt;br /&gt;&lt;br /&gt;I'm also thinking of having a parser to deal with JSON (I did some abstraction to make this easy), but for now I'll just take one step at a time.&lt;br /&gt;&lt;br /&gt;One issue I haven't given a lot of time to yet is the CONSTRUCT query. These have to return a graph and not a result set. That brings a few questions to mind:&lt;ul&gt;&lt;li&gt;How do I tell the difference? I don't want to do it in the API, since that's something the user may not want to have to figure out. But short of having an entire parser, it could be difficult to see the form of the query before it's sent.&lt;/li&gt;&lt;li&gt;I can wait for the response, and figure it out there, but then my SAX parser needs to be able to deal with RDF/XML. I usually use Jena's parser for this, since I know it's a lot of work. Do I really want to go that way? Unfortunately, I don't know of any good way to move to a different parser once I've seen the opening elements. I &lt;em&gt;could&lt;/em&gt; try a &lt;a href="http://java.sun.com/javase/6/docs/api/java/io/BufferedInputStream.html"&gt;BufferedInputStream&lt;/a&gt;, so I could rewind it, but can that handle really large streams? I'll think on that.&lt;/li&gt;&lt;li&gt;How do I represent the graph at the client end?&lt;/li&gt;&lt;/ul&gt;Representing a graph goes way beyond ResultSet, and poses the question of just how far to go. A simple list of triples would probably suffice, but if I have a graph then I usually want to do interesting stuff with it.&lt;br /&gt;&lt;br /&gt;I'm thinking of using my normal graph library, which isn't out in the wild yet, but I find it very useful. I currently have implementations of it in Java, Ruby and Scala. I keep re-implementing it whenever I'm in a new language, because it's just so useful (it's trivial to put under a Jena or Mulgara API too). However, it also goes beyond the JDBC goal that I was looking for, so I'm cautious about going that way.&lt;br /&gt;&lt;br /&gt;Anyway, it's getting late on a Saturday night, and I'm due for some more pain medication, so I'll leave it there. I need to talk to people about work again, so having an active blog will be important once more (even if it makes me look ignorant occasionally). I'll see if I can keep it up.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6848574-2768812035285723292?l=gearon.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://gearon.blogspot.com/2010/04/sparql-api-every-time-i-try-to-use.html</link><author>noreply@blogger.com (Quoll)</author><thr:total>4</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6848574.post-3040619251796237722</guid><pubDate>Thu, 21 May 2009 18:15:00 +0000</pubDate><atom:updated>2009-05-21T18:15:07.306-05:00</atom:updated><title /><description>&lt;h3&gt;Federated Queries&lt;/h3&gt; A long time ago, TKS supported federated queries, though the approach was a little naive (bring all the matches of triple patterns in to a single place, and join them there). Then a few years ago I added this to Mulgaraas well. I've always wanted to make it more intelligent in order to reduce network bandwidth, but at the same time, I was always happy that it worked. Unfortunately, it was all accomplished through RMI, and was Mulgara specific. That used to be OK, since RDF servers didn't have standardized communications mechanisms, but that changed with SPARQL.&lt;br /&gt;&lt;br /&gt;More recently, I've started running across distributed queries through another avenue. While working through the SPARQL protocol, I realized that the Mulgara approach of treating unknown HTTP URIs as data that can be retrieved can be mixed with SPARQL CONSTRUCT queries encoded into a URI. The result of an HTTP request on a SPARQL CONSTRUCT query is an RDF document, which is exactly what Mulgara is expecting when it does an HTTP GET on a graph URI. The resulting syntax is messy, but it works quite well. Also, while retrieving graph URIs is not standard in SPARQL, most systems implement this, making it a relatively portable idiom. I was quite amused at the exclamations of surprise and horror (especially the horror) when I &lt;a href="http://lists.w3.org/Archives/Public/semantic-web/2009May/0029.html"&gt;passed this along on a mailing list&lt;/a&gt; a few weeks ago.&lt;br /&gt;&lt;br /&gt;The ease at which this was achieved using SPARQL made me consider how federated querying might be done using a SPARQL-like protocol. Coincidentally, the &lt;a href="http://www.w3.org/2009/sparql/wiki/Main_Page"&gt;SPARQL Working Group&lt;/a&gt; has &lt;a href="http://www.w3.org/2009/sparql/wiki/Feature:BasicFederatedQuery"&gt;Basic Federated Queries&lt;/a&gt; as a proposed feature, and now I'm starting to see a lot of people asking about it on mailing lists (was people always asking about this, or am I just noticing it now?). I'm starting to think this feature may be more important in SPARQL, and think that perhaps I should have made it a higher priority when I voted on it. As it is, it's in the list of things we'll get to if we have time.&lt;br /&gt;&lt;br /&gt;Then, while I was thinking about this, one of the other Mulgara developers tells me that he absolutely has to have distributed queries (actually, he needs to run rules over distributed datasets) to meet requirements in his organization. Well, the existing mechanisms will sort of work for him, but to do it right it should be in SPARQL.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Requirements&lt;/h3&gt; So what would I want to see in federated SPARQL queries? Well, as an implementer I need to see a few things:&lt;br /&gt;&lt;ol&gt;&lt;li&gt;A syntactic mechanism for defining the URI of a SPARQL endpoint containing the graph(s) to be accessed.&lt;/li&gt;&lt;li&gt;A syntactic mechanism for defining the query to be made on that endpoint (a subquery syntax would be fine here).&lt;/li&gt;&lt;li&gt;A means of asking the size of a query result.&lt;/li&gt;&lt;li&gt;A mechanism for passing existing bindings along with a query.&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;&lt;br /&gt;The first item seemed trivial until I realized that SPARQL has no standard way of describing an endpoint. Systems like Mulgara simply use &lt;code&gt;http://hostname/sparql/&lt;/code&gt;, which provides access to the entire store (everything can be referred to using HTTP parameters, such as &lt;code&gt;default-graph-uri&lt;/code&gt; and &lt;code&gt;query&lt;/code&gt;). On the other hand, &lt;a href="http://www.joseki.org/"&gt;Joseki&lt;/a&gt; can do the /sparql/ thing, but also provides an option to access datasets through the path, and &lt;a href="http://www.openrdf.org/"&gt;Sesame&lt;/a&gt; can have several repositories, each of which is accessible by varying the path in the URL.&lt;br /&gt;&lt;br /&gt;The base URL for issuing SPARQL queries against would be easy enough to specify, but it introduces a new concept into the query language, and that has deeper ramifications than should be broached in this context.&lt;br /&gt;&lt;br /&gt;The query that can be issued against an endpoint should look like a standard query, and not just a CONSTRUCT, as this provides greater flexibility and also binds the columns to variable names that can appear in other parts of the query. This is basically identical to a subquery, which is exactly what we want.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Bandwidth Efficiency&lt;/h3&gt; The last 2 items are a matter of efficiency and not correctness. However, they can mean the difference between transferring a few bytes vs a few megabytes over a network.&lt;br /&gt;&lt;br /&gt;(BTW, when did "bandwidth" get subverted to describe data rates? When I was a boy this referred to the range of frequencies that a signal used, and this had a mathematical formula relating it to the number of symbols-per-second that could be transmitted over that signal - which does indeed translate to a data rate. However, it now gets used in completely different contexts which have nothing to do with frequency range. Oh well.. back to the story).&lt;br /&gt;&lt;br /&gt;If I want to ask for the identifiers of people named "Fred" (as opposed to something else I want to name with &lt;code&gt;foaf:givenname&lt;/code&gt;), then I could use the query:&lt;pre&gt;&lt;code&gt;PREFIX foaf: &amp;lt;http://xmlns.com/foaf/0.1/&amp;gt;&lt;br /&gt;SELECT ?person WHERE {&lt;br /&gt;  ?person foaf:givenname "Fred" .&lt;br /&gt;  ?person a foaf:Person&lt;br /&gt;}&lt;/code&gt;&lt;/pre&gt;Now what if the "type" data and the "name" data appear on different servers? In that case we would use a distributed query.&lt;br /&gt;&lt;br /&gt;Using the HTTP/GET idiom I mentioned at the top of this post, then I could send the query to the server containing the &lt;code&gt;foaf:givenname&lt;/code&gt; statements, and change it now to say:&lt;pre&gt;&lt;code&gt;PREFIX foaf: &amp;lt;http://xmlns.com/foaf/0.1/&amp;gt;&lt;br /&gt;SELECT ?person WHERE {&lt;br /&gt;  ?person foaf:givenname "Fred" .&lt;br /&gt;  GRAPH &amp;lt;http://hostname/sparql/?query=&lt;br /&gt;PREFIX+foaf%3A+%3Chttp%3A%2F%2Fxmlns.com%2Ffoaf%2F0.1%2F%3E%0A&lt;br /&gt;CONSTRUCT+%7B%3Fperson+a+foaf%3APerson%7D+&lt;br /&gt;WHERE+%7B%3Fperson+a+foaf%3APerson%7D&amp;gt; {&lt;br /&gt;    ?person a foaf:Person&lt;br /&gt;  }&lt;br /&gt;}&lt;/code&gt;&lt;/pre&gt;So now the server will resolver all the entities with the name "Fred", then it will retrieve a graph and ask it for all the entities that are a &lt;code&gt;foaf:Person&lt;/code&gt;. Then it will join these results to create the final result.&lt;br /&gt;&lt;br /&gt;But what happens if there are only 3 things named "Fred", but 10,000 people in the data set? In that case the server will resolve the first pattern, getting 3 bindings for ?person, and then make a request across the network, getting back 10,000 statement which are then queried for those statements the describe a &lt;code&gt;foaf:Person&lt;/code&gt; (they all will), and only then does the join happen. Ideally, we'd have gone the other way, and asked the server with 10,000 people to request data from the server that had 3 entities named Fred, but we may not have known ahead of time that this would be better, and a more complex query could require a more complex access pattern than simply "reversing" the resolution order.&lt;br /&gt;&lt;br /&gt;First of all, we need a way to ask each server how large a set of results is likely to be. The &lt;a href="http://www.w3.org/2009/sparql/wiki/Feature:AggregateFunctions"&gt;COUNT&lt;/a&gt; function that is being discussed in the SPARQL &lt;abbr title="Working Group"&gt;WG&lt;/abbr&gt; at the moment could certainly be used to help here, though for the sake of efficiency it would also be nice to have a mechanism for asking for the upper-limit of the COUNT. That isn't appropriate for a query language (since it refers to database internals) but would be nice to have in the protocol, such as with an HTTP/OPTION request (though I &lt;em&gt;really&lt;/em&gt; don't see something like that being ratified by the SPARQL WG). But even without an "upper limit" option, a normal COUNT would give us what we need to find out how to move the query around.&lt;br /&gt;&lt;br /&gt;So once we realize that the server running the query has only a little data (call it "Server A"), and it needs to join it to a large amount of data on a different server (call this one "Server B", then of course we want Server A to send the small amount of data to Server B instead of retrieving the large amount from it. One way to do this might be to invert the query at this point, and send the whole thing to Server B. That server then asks Server A for the data, and sends its response. Unfortunately, that is both complex, and requires a lot more hops than we want. The final chain here would be:&lt;ol&gt;&lt;li&gt;Client sends query as a request to Server A&lt;/li&gt;&lt;li&gt;Server A reverses the query and sends the new query as a request to Server B&lt;/li&gt;&lt;li&gt;Server B resolves its local data, and sends the remainder of the query as a request to Server A&lt;/li&gt;&lt;li&gt;Server A responds to Server B with the result of entities with the name "Fred"&lt;/li&gt;&lt;/li&gt;Server B joins the data it got with the local data and responds to Server A with the results of the entire query&lt;/li&gt;&lt;li&gt;Server A responds to the client with the unmodified results it just received&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;Yuck.&lt;br /&gt;&lt;br /&gt;Instead, when Server A detects a data size disparity like this, it needs a mechanism to package up its bindings for the &lt;em&gt;?person&lt;/em&gt; variable, and send these to Server B along with the request. Fortunately, we already have a format for this in the &lt;a href="http://www.w3.org/TR/rdf-sparql-XMLres/"&gt;SPARQL result set format&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Normally, a query would be performed using an HTTP/GET, but including a content-body in a GET request has never been formally recognized (though it has not been made illegal), so I don't want to go that way. Instead, a POST would work just as well here. The HTTP request with content could look like this (I've added line breaks to the request):&lt;code&gt;&lt;pre&gt;POST /sparql/?query=&lt;br /&gt;PREFIX+foaf%3A+%3Chttp%3A%2F%2Fxmlns.com%2Ffoaf%2F0.1%2F%3E%0A&lt;br /&gt;SELECT+%3Fperson+WHERE+%7B%3Fperson+a+foaf%3APerson%7D HTTP/1.1&lt;br /&gt;Host: www.example&lt;br /&gt;User-agent: my-sparql-client/0.1&lt;br /&gt;Content-Type: application/sparql-results+xml&lt;br /&gt;Content-Length: xxx&lt;br /&gt;&lt;br /&gt;&amp;lt;?xml version="1.0"?&amp;gt;&lt;br /&gt;&amp;lt;sparql xmlns="http://www.w3.org/2005/sparql-results#"&amp;gt;&lt;br /&gt; &amp;lt;head&amp;gt;&lt;br /&gt;   &amp;lt;variable name="person"/&amp;gt;&lt;br /&gt; &amp;lt;/head&amp;gt;&lt;br /&gt; &amp;lt;results distinct="false" ordered="false"&amp;gt;&lt;br /&gt;   &amp;lt;result&amp;gt;&lt;br /&gt;     &amp;lt;binding name="person"&amp;gt;&amp;lt;uri&amp;gt;http://www.example/FredFlintstone&amp;lt;/uri&amp;gt;&amp;lt;/binding&amp;gt;&lt;br /&gt;   &amp;lt;/result&amp;gt;&lt;br /&gt;   &amp;lt;result&amp;gt;&lt;br /&gt;     &amp;lt;binding name="person"&amp;gt;&amp;lt;uri&amp;gt;http://www.example/FredKruger&amp;lt;/uri&amp;gt;&amp;lt;/binding&amp;gt;&lt;br /&gt;   &amp;lt;/result&amp;gt;&lt;br /&gt;   &amp;lt;result&amp;gt;&lt;br /&gt;     &amp;lt;binding name="person"&amp;gt;&amp;lt;uri&amp;gt;http://www.example/FredTheDog&amp;lt;/uri&amp;gt;&amp;lt;/binding&amp;gt;&lt;br /&gt;   &amp;lt;/result&amp;gt;&lt;br /&gt; &amp;lt;/results&amp;gt;&lt;br /&gt;&amp;lt;/sparql&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;I can't imagine that I could be successful in suggesting this as part of the underlying protocol for federated querying, but I'm thinking that I'll be incorporating it into Mulgara all the same.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6848574-3040619251796237722?l=gearon.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://gearon.blogspot.com/2009/05/federated-queries-long-time-ago-tks.html</link><author>noreply@blogger.com (Quoll)</author><thr:total>4</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6848574.post-1365826457813077288</guid><pubDate>Fri, 27 Feb 2009 18:37:00 +0000</pubDate><atom:updated>2009-02-27T21:16:15.411-06:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">OWL</category><category domain="http://www.blogger.com/atom/ns#">integration</category><category domain="http://www.blogger.com/atom/ns#">RLog</category><category domain="http://www.blogger.com/atom/ns#">description logic</category><category domain="http://www.blogger.com/atom/ns#">SKOS</category><category domain="http://www.blogger.com/atom/ns#">RDF</category><category domain="http://www.blogger.com/atom/ns#">Mulgara</category><category domain="http://www.blogger.com/atom/ns#">logic</category><title /><description>&lt;h3&gt;More Programmable Logic&lt;/h3&gt; In the last post I gave a basic description of how the Krule rules engine works. I left out a number of details, but it provides some details on the overall approach.&lt;br /&gt;&lt;br /&gt;The most important detail I skipped was the interaction with resolvers in order to identify resources with particular properties. This includes among other things, finding URIs in a domain, inequality comparisons for numeric literals, regular expression matching on strings, the "type" of a resource (URI, blank node, or literal), and optimized transitivity of predicates. We also manage "subtractions" in our data, in the same way that Evren Sirin &lt;a href="http://clarkparsia.com/weblog/2009/02/11/integrity-constraints-for-owl/"&gt;described NOT&lt;/a&gt; two weeks ago. I should point out that Mulgara does subtractions directly, and not with a combined operation with the OPTIONAL/FILTER/!BOUND pattern. This was introduced this in 2004 (or was it 2005?). I have to say that I'm a little surprised that SPARQL never included anything to express it directly, particularly since so many people ask for it (and hence, the popularization of OPTIONAL/FILTER/!BOUND as a pattern) and because the &lt;a href="p://www.w3.org/TR/rdf-sparql-query/#sparqlAlgebra"&gt;SPARQL algebra&lt;/a&gt; provides a definition of a function called "Diff" that is used internally.&lt;br /&gt;&lt;br /&gt;Anyway, these extensions are not necessary to understand Krule or RLog, but I think it's useful to know that they're there.&lt;br /&gt;&lt;br /&gt;So now that I've described Krule, I've set the scene for describing RLog.&lt;br /&gt;&lt;h3&gt;Krule Configuration&lt;/h3&gt; When I first wrote &lt;abbrev title="Kowari Rules"&gt;Krule&lt;/abbrev&gt;, I was ultimately aiming at OWL, but I had a short term goal of RDFS. I find that I have to take these things one step at a time, or else I never make progress. Since I knew that my rules were going to expand, I figured I should not hard code anything into Mulgara, but that I should instead interpret a data structure which described the rules. That also meant I would be able to run rules for lots of systems: RDFS, SKOS, OWL, or anything else. Of course, some things would need more features than RDFS needed (e.g. both OWL and SKOS need "lists"), but my plan was to work on that iteratively.&lt;br /&gt;&lt;br /&gt;At the time, I designed an &lt;a href="http://mulgara.org/files/misc/krule.rdf"&gt;RDF schema&lt;/a&gt; to describe my rules, and built the Krule engine to initialize itself from this. This works well, since the whole system is built around RDF already. I also created a new TQL command for applying rules to data:&lt;pre&gt;&lt;code&gt;  &lt;strong&gt;apply&lt;/strong&gt; &amp;lt;&lt;em&gt;rule_graph_uri&lt;/em&gt;&amp;gt; &lt;strong&gt;to&lt;/strong&gt; &amp;lt;&lt;em&gt;data_graph_uri&lt;/em&gt;&amp;gt; [&amp;lt;&lt;em&gt;output_graph_uri&lt;/em&gt;&amp;gt;]&lt;/code&gt;&lt;/pre&gt;By default all of the entailed data goes into the graph the rules are being applied to, but by including the optional output graph you can send the entailed data there instead.&lt;br /&gt;&lt;br /&gt;This worked as planned, and I was able to build a &lt;a href="http://mulgara.org/files/misc/rdfs-krule.rdf"&gt;Krule configuration graph for RDFS&lt;/a&gt;. Then life and work interfered and the rules engine was put on the back burner before I got to add some of the required features (like consistency checking).&lt;br /&gt;&lt;br /&gt;Then about 18 months ago I thought I'd have a go at writing OWL entailment, at least for that part that the rules engine would support. So I set out to write a new Krule file. The complexity of the file was such that I started writing out the rules that I wanted using a kind of Prolog notation with second order programming, in a very similar way to how Raphael Volz represented the same constructs in some of &lt;a href="http://www.daml.org/listarchive/joint-committee/att-1254/01-bubo.pdf"&gt;his&lt;/a&gt; &lt;a href="http://lists.w3.org/Archives/Public/www-webont-wg/2002Oct/att-0033/Paper.pdf"&gt;papers&lt;/a&gt;. This grammar uses binary predicates to represent genereal triples, and unary predicates to indicate "type" statements, ie. statements with a predicate of &lt;em&gt;rdf:type&lt;/em&gt;. As an example, the &lt;code&gt;owl:sameAs&lt;/code&gt; predicate indicates that if the subject of a statement is the &lt;code&gt;owl:sameAs&lt;/code&gt; another resource, then that statement can be duplicated with the other resource as the subject. This was easily expressed this as:&lt;pre&gt;&lt;code&gt;  A(Y,Z) :- A(X,Z), owl:sameAs(X,Y).&lt;/code&gt;&lt;/pre&gt;I wrote out about 3 rules before I realized that converting these to Krule was going to be tedious and prone to error. In fact, I had unthinkingly demonstrated that I already had a language I wanted to use, and the process of translation was an easily automated task. Since the language was allowing me to describe RDF with logic, I decided to call it RLog (for RDF Logic).&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Iterations&lt;/h3&gt; Andrae and I had been discussing how much we disliked &lt;a href="http://sablecc.org/"&gt;SableCC&lt;/a&gt; for generating the &lt;abbrev title="Tucana Query Language"&gt;TQL&lt;/abbrev&gt; parser for Mulgara, and so I started looking around at other parsers. The power of &lt;a href="http://en.wikipedia.org/wiki/LALR_parser"&gt;LALR parsers&lt;/a&gt; appealed to me, and so I went with &lt;a href="http://beaver.sourceforge.net/"&gt;Beaver&lt;/a&gt;. Along with the &lt;a href="http://jflex.de/"&gt;JFlex&lt;/a&gt; lexer, this software is a pleasure to use. I had learned how to use them both, &lt;em&gt;and&lt;/em&gt; created the RLog grammar in about an hour. I then converted the &lt;a href="http://mulgara.org/files/misc/rdfs-krule.rdf"&gt;Krule configuration for RDFS&lt;/a&gt; into this new grammar, and convinced myself that I had it right. Then life got in the way again, and I put it away.&lt;br /&gt;&lt;br /&gt;Last year while waiting for some tests to complete, I remembered this grammar, and spent some of my enforced downtime making it output some useful RDF in the Krule schema. For anyone who's looked at Krule, they may have noticed that triggers for rules (which rules cause which other rules to be run) are explicitly encoded into the configuration. I did this partly because I already had the list of trigger dependencies for RDFS rules, and partly because I thought it would offer more flexibility. However, I had realized some time before that these dependencies were easy to work out, and had been wanting to automate this. I decided that RLog was the perfect place to do it, partly because it meant not having to change much, but also because it still allowed me the flexibility of tweaking the configuration.&lt;br /&gt;&lt;br /&gt;Once I'd finished writing a system that could output Krule, I tested it against my &lt;a href="http://mulgara.org/files/misc/rdfs.dl"&gt;RDFS RLog file&lt;/a&gt;, and compared the generated Krule to the original configuration. Initially I was disappointed to see to many dependencies, but on closer inspection I realized that they were all valid. The original dependencies were a reduced set because they applied some of the semantics of the predicates and classes they were describing, which was not something that a grammar at the level of RLog could deal with. Semi-na&amp;iuml;ve evaluation was going to stop unnecessary rules from running anyway, so I decided that these extra triggers were fine. I ran it against the various test graphs that I had, and was pleased to see that it all worked perfectly.&lt;br /&gt;&lt;br /&gt;But once again, work and life got in the way, and I put it aside again.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;SKOS&lt;/h3&gt; A couple of months ago Brian asked me about running rules for generating &lt;a href="http://www.w3.org/TR/skos-reference/"&gt;SKOS&lt;/a&gt; entailments, as he was writing &lt;a href="http://www.devx.com/semantic/Article/39348/1954"&gt;a paper&lt;/a&gt; on this topic. I pointed him towards RLog and knocked up a couple of useful rules for him. However, as I got into it, I realized that I could actually do most of SKOS quite easily, and before I knew it, I'd written an entire &lt;a href="http://mulgara.org/trac/attachment/wiki/SKOS/skos.rlog"&gt;RLog program for it&lt;/a&gt;. The only thing I could not do was "&lt;a href="http://www.w3.org/TR/skos-reference/#L3312"&gt;S35&lt;/a&gt;", as this requires a predicate for list membership (also a requirement for OWL, and on my TODO list).&lt;br /&gt;&lt;br /&gt;The &lt;em&gt;really&lt;/em&gt; interesting thing about this document, is that almost everything is an axiom and not a rule. It only requires 2 RDFS rules and 5 OWL rules to make the whole thing work. This is quite important, as the complexity in running the rules is generally exponential in the number of rules.&lt;br /&gt;&lt;br /&gt;This is (&lt;a href="http://en.wiktionary.org/wiki/IMNSHO"&gt;IMNSHO&lt;/a&gt;) the power of ontologies. By providing properties of classes and properties, they reduce the need for many rules. To demonstrate what I mean, I've seen a few systems (such as &lt;a href="http://www.dbai.tuwien.ac.at/proj/dlv/"&gt;DLV&lt;/a&gt;) which define a predicate to be transitive in the following way:&lt;pre&gt;&lt;code&gt;  pred(A,C) :- pred(A,B), pred(B,C).&lt;/code&gt;&lt;/pre&gt;This works, but it creates a new rule to do it. Every new transitive predicate also gets its own rule. As I have already said, this has a significant detrimental effect on complexity.&lt;br /&gt;&lt;br /&gt;Conversely, models such as OWL are able to declare properties as "transitive". Each such declaration then becomes a statement rather than a rule. Indeed, all the transitive statements get covered with a single second-order rule:&lt;pre&gt;&lt;code&gt;  P(A,C) :- P(A,B), P(B,C), owl:TransitivePredicate(P).&lt;/code&gt;&lt;/pre&gt;"Second-order" refers to the fact that variables can be used for the predicates (such as the variable &lt;em&gt;P&lt;/em&gt; in the expression &lt;em&gt;P(A,B)&lt;/em&gt;), and that predicates can appear as parameters for other predicates, such as &lt;em&gt;owl:TransitivePredicate(...)&lt;/em&gt;. The symmetry of Mulgara indexes for RDF statements allows such second order constructs to be evaluated trivially.&lt;br /&gt;&lt;br /&gt;Using the OWL construct for transitivity, any number of predicates can be declared as transitive with no increase to the number of rules. The complexity of rules does have a component derived from the number of statements, but this is closer to linear or polynomial (depending on the specific structure of the rules), and is therefore far less significant for large systems. It is also worth noting that several OWL constructs do not need an exhaustive set of their own rules, as their properties can be described using other OWL constructs. For instance, &lt;em&gt;owl:sameAs&lt;/em&gt; is declared as being &lt;em&gt;owl:SymmetricProperty&lt;/em&gt;. This means that the entailment rule for &lt;em&gt;owl:sameAs&lt;/em&gt; (shown above) need only be written once for &lt;em&gt;owl:sameAs(A,B)&lt;/em&gt; and is not needed for symmetric case of &lt;em&gt;owl:sameAs(B,A)&lt;/em&gt;.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;General Acceptance&lt;/h3&gt; Brian wasn't the only one to like RLog. I've had reports and feature requests from a few other people who like using it as well. The most commonly requested feature has been the generation of blank nodes. The main reason for this is to handle existential formula, which makes me wary, as this can lead to infinite loops if not carefully controlled. On the other hand, I &lt;em&gt;can&lt;/em&gt; see the usefulness of it, so I expect to implement it eventually.&lt;br /&gt;&lt;br /&gt;A related feature is to create multiple statements based on a single matched rule. This can usually be handled by introducing a new rule with the same body and a different head, but if a blank node has been generated by the rule, then there needs to be some way to re-use it in the same context.&lt;br /&gt;&lt;br /&gt;A problem with general usage is that the domains understood by RLog have been preset with the domains that I've wanted, namely: &lt;a href="http://www.w3.org/1999/02/22-rdf-syntax-ns#"&gt;RDF&lt;/a&gt;, &lt;a href="http://www.w3.org/2000/01/rdf-schema#"&gt;RDFS&lt;/a&gt;, &lt;a href="http://www.w3.org/2002/07/owl#"&gt;OWL&lt;/a&gt;, &lt;a href="http://www.w3.org/2001/XMLSchema#"&gt;XSD&lt;/a&gt;, &lt;a href="http://mulgara.org/mulgara#"&gt;MULGARA&lt;/a&gt;, &lt;a href="http://mulgara.org/owl/krule/#"&gt;KRULE&lt;/a&gt;, &lt;a href="http://xmlns.com/foaf/0.1/"&gt;FOAF&lt;/a&gt;, &lt;a href="http://www.w3.org/2004/02/skos/core#"&gt;SKOS&lt;/a&gt;, and &lt;a href="http://purl.org/dc/elements/1.1/"&gt;DC&lt;/a&gt;. The fix to this can be isolated in the parser, so I anticipate this being fixed by Monday. :-)&lt;br /&gt;&lt;br /&gt;Despite it being limited, RLog was proving to be useful, allowing me to encode systems like SKOS very easily. However, being a separate program that translated an RLog file into Krule configuration files that &lt;em&gt;then&lt;/em&gt; had to be loaded and applied to data, was a serious impediment to the usage.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Integration&lt;/h3&gt; The Mulgara "Content Handler" interface is a mechanism for loading any kind of data as triples, and optionally writing it back out. The two main ones are the &lt;a href="http://www.w3.org/TR/rdf-syntax-grammar/"&gt;RDF/XML&lt;/a&gt; handler and the &lt;a href="http://www.w3.org/DesignIssues/Notation3.html"&gt;N3&lt;/a&gt; handler, but there are others in the default distribution as well. There is a MBox handler for representing Unix Mailbox files as RDF, and an &lt;abbrev title="Moving Pictures Expert Group-1, Audio Layer 3"&gt;MP3&lt;/abbrev&gt; handler which maps ID3 metadata from MP3 files. These handlers compliment the "Resolver" interface which represents external data sources as a dynamic graph.&lt;br /&gt;&lt;br /&gt;Since RLog has a well-defined mapping into RDF (something the RLog program was already doing when it emitted RDF/XML) then reimplementing this system as a content handler would integrate it into Mulgara with minimal effort. I had been planning on this for some time, but there always seemed to be more pressing priorities. These other priorities are still there (and still pressing!) but a few people (e.g. &lt;a href="http://prototypo.blogspot.com/2009/02/desperately-seeking-skos-vendors.html"&gt;David&lt;/a&gt;) have been pushing me for it recently, so I decided to bite the bullet and get it done.&lt;br /&gt;&lt;br /&gt;The first problem was that the parser was in Beaver. This is yet another &lt;abbrev title="Java ARchive"&gt;JAR&lt;/abbrev&gt; file to include at a time when I'm trying to cut down on our plethora of libraries. It also seemed excessive, since we already have both JavaCC &lt;em&gt;and&lt;/em&gt; SableCC in our system - the former for SPARQL, the latter for TQL, and I hope to redo TQL in JavaCC eventually anyway. So I decided to re-implement the grammar parser in JavaCC.&lt;br /&gt;&lt;br /&gt;Unfortunately, it's been over a year since I looked at JavaCC, and I was very rusty. So my first few hours were spent relearning token lookahead, and various aspects of JavaCC grammar files. I actually think I know it better now than I did when I first did the SPARQL parser (that's a concern). There are a few parts of the grammar which are not LL(1) either, which forced me to think through the structure more carefully, and I think I benefited from the effort.&lt;br /&gt;&lt;br /&gt;I was concerned that I would need to reimplement a lot of the AST for RLog, but fortunately this was not the case. Once I got a handle on the translation it all went pretty smoothly, and the JavaCC parser was working identically to the original Beaver parser by the end of the first day.&lt;br /&gt;&lt;br /&gt;After the parser was under control I moved on to emitting triples. This was when I was reminded that writing RDF/XML can actually be a lot easier than writing raw triples. I ended up making slow progress, but I finally got it done last night.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Testing&lt;/h3&gt; Before running a program through the content handler for the first time, I wanted to see that the data looked as I expected it to. &lt;a href="http://www.junit.org/"&gt;JUnit&lt;/a&gt; tests are going to take some time to write, and with so much framework around the rules configuration, it was going to be clear very quickly if things weren't &lt;em&gt;just&lt;/em&gt; right. I considered running it all through the debugger, but that was going to drown me in a sea of RDF nodes. That was when I decided that I could make the resolver/content-handler interfaces work for me.&lt;br /&gt;&lt;br /&gt;Mulgara can't usually tell the difference between data in its own storage, and data sourced from elsewhere. It always opts for internal storage first, but if a graph URI is not found, then it will ask the various handlers if they know what to do with the graph. By using a &lt;strong&gt;file:&lt;/strong&gt; URL for the graphs, I could make Mulgara do all of it's reading and writing to files, using the content handlers to do the I/O. In this case, I decided to "export" my RLog graph to an N3 file, and compare the result to an original Krule RDF/XML file that I exported to another N3 file.&lt;br /&gt;&lt;br /&gt;The TQL command for this was:&lt;pre&gt;&lt;code&gt;  export &amp;lt;file:/path/rdfs.rlog&amp;gt; to &amp;lt;file:/path/rlog-output.n3&amp;gt;&lt;/code&gt;&lt;/pre&gt;Similarly, for the RDF/XML file was transformed to N3 with:&lt;pre&gt;&lt;code&gt;  export &amp;lt;file:/path/rdfs-krule.rdf&amp;gt; to &amp;lt;file:/path/krule-output.n3&amp;gt;&lt;/code&gt;&lt;/pre&gt;I love it when I can glue arbitrary things together and it all "just works". (This may explain why I like the Semantic Web).&lt;br /&gt;&lt;br /&gt;My first test run demonstrated that I was allowing an extra # into my URIs, and then I discovered that I'd fiddled with the literal token parsing, and was now including quotes in my strings (oops). These were trivial fixes. The third time through was the charm. I spent some time sorting my N3 files before deciding it looked practically identical, and so off I went to run an RLog program directly.&lt;br /&gt;&lt;br /&gt;As I mentioned in my last post, applying a set of rules to data is done with the &lt;strong&gt;apply&lt;/strong&gt; command. While I could have loaded the rules into an internal graph (pre-compiling them, so to speak) I was keen to "run" my program straight from the source:&lt;pre&gt;&lt;code&gt;  apply &amp;lt;file:/path/rdfs.rlog&amp;gt; to &amp;lt;test:data:uri&amp;gt;&lt;/code&gt;&lt;/pre&gt;...and whaddaya know? It worked. :-)&lt;br /&gt;&lt;br /&gt;Now I have a long list of features to add, optimizations to make, bugs to fix, and all while trying to stay on top of the other unrelated parts of the system. Possibly even more importantly, I need to document how to write an RLog file! But for the moment I'm pretty happy about it, and I'm going to take it easy for the weekend. See you all on Monday!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6848574-1365826457813077288?l=gearon.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://gearon.blogspot.com/2009/02/more-programmable-logic-in-last-post-i.html</link><author>noreply@blogger.com (Quoll)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6848574.post-2523761822983983225</guid><pubDate>Fri, 27 Feb 2009 16:46:00 +0000</pubDate><atom:updated>2009-02-27T12:37:03.960-06:00</atom:updated><title /><description>&lt;h3&gt;Programmable Logic&lt;/h3&gt; I had hoped to blog a lot this week, but I kept putting it off in order to get some actual work done. I still have a lot more to do, but I'm at a natural break, so I thought I'd write about it.&lt;br /&gt;&lt;br /&gt;I have finally integrated RLog into Mulgara! In some senses this was not a big deal, so it took a surprising amount of work.&lt;br /&gt;&lt;br /&gt;To explain what RLog is, I should describe Krule first.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Krule&lt;/h3&gt; The Mulgara rules engine, &lt;abbrev title="Kowari Rules"&gt;Krule&lt;/abbrev&gt;, implements my design for executing rules on large data sets. For those familiar with rules engines, it is similar to &lt;a href="http://en.wikipedia.org/wiki/Rete_algorithm"&gt;RETE&lt;/a&gt;, but it runs over data as a batch, rather than iteratively. It was designed this way because our requirements were to perform inferencing on gigabytes of RDF. This was taking a long time to load, so we wanted to load it all up, and &lt;em&gt;then&lt;/em&gt; do the inferencing.&lt;br /&gt;&lt;br /&gt;RETE operates by setting up a network describing the rules, and then as statements are fed through it, each node in that network builds up a memory of the data it has seen and passed. As data comes in the first time, the nodes that care about it will remember this data and pass it on, but subsequent times through, the node will recognize the data and prevent it from going any further. In this way, every statement fed into the system will be processed as much as it needs to be, and no more. There is even a proof out there that says that RETE is the optimal rules &lt;em&gt;algorithm&lt;/em&gt;. Note that the implementation of an algorithm can, and does, have numerous permutations which can allow for greater efficiency in some circumstances, so RETE is often treated as the basis for efficient engines.&lt;br /&gt;&lt;br /&gt;One variation on algorithms of this sort is to trade &lt;em&gt;time&lt;/em&gt; for &lt;em&gt;space&lt;/em&gt;. This is a fancy way of saying that if we use more memory then we can use less processing time, or we can use more processing time to save on memory. Several variations on RETE do just this, and so does Krule.&lt;br /&gt;&lt;br /&gt;When looking at the kinds of rules that can be run on RDF data, I noticed that the simple structure of RDF meant that each "node" in a RETE network corresponds to a constraint on a triple (or a &lt;abbrev title="Basic Graph Pattern"&gt;BGP&lt;/abbrev&gt; in &lt;a href="http://www.w3.org/TR/rdf-sparql-query/"&gt;SPARQL&lt;/a&gt;). Because Mulgara is indexed in "every direction", this means that every constraint can be found as a "slice" out of one of the indexes (while our current system usually takes &lt;em&gt;O(log(n))&lt;/em&gt; to find, upcoming systems can do some or all of these searches in &lt;em&gt;O(1)&lt;/em&gt;). Consequently, instead of my rule network keeping a table in memory associated with every node, there is a section out of an index which exactly corresponds to this table.&lt;br /&gt;&lt;br /&gt;There are several advantages to this. First, the existence of the data in the database is defined by it being in the indexes. This means that all the data gets indexed, rules engine or not. Second, when the rules engine is run, there is no need to use the data to iteratively populate the tables for each node, as the index slices (or &lt;strong&gt;constraint resolutions&lt;/strong&gt;) are &lt;em&gt;already&lt;/em&gt; fully populated, by definition. Finally, our query engine caches constraint resolutions, and they do not have to be re-resolved if no data has gone in that can affect them (well, some of the caching heuristics can be improved for better coverage, but the potential is there). This means that the "tables" associated with each node will be automatically updated for us as the index is updated, and the work needed to handle updates is minimal.&lt;br /&gt;&lt;br /&gt;During the first run of Krule, none of the potential entailments have been made yet, so everything is potentially relevant. However, during subsequent iterations of the rules, Krule has no knowledge of which statements are new in the table on any given node. This means it will produce entailed statements that already exist, and are duplicates. Inserting these is unnecessary (and hence, suboptimal) and creates unwanted duplicates. We handle this in two ways.&lt;br /&gt;&lt;br /&gt;The first and simpler mechanism is that Mulgara uses &lt;a href="http://en.wikipedia.org/wiki/Set_(mathematics)"&gt;Set semantics&lt;/a&gt;, meaning that any duplicates are silently (and efficiently) ignored. Set semantics are important when dealing with RDF, and this is why I'm so frustrated at non-distinct nature of SPARQL queries... but that's a discussion for another time. :-)&lt;br /&gt;&lt;br /&gt;The more important mechanism for duplicate inserts is based on RDF having a property of being monotonically increasing. This is because RDF lets you assert data, but not to "unassert" it. OWL 2 has introduced explicit denial of statements, but this is useful for preventing entailments and consistency checking... it does not remove previously existing statements. In non-monotonic systems a constraint resolution may keep the same size if some statements are deleted while an equal number of statements are inserted, but in a monotonic system like RDF, keeping the same size means that there has been no change. So a node knows to pass its data on if the size of its table increases, but otherwise it will do nothing. I stumbled across this technique as an obvious optimization, but I've since learned that it has a formal name: &lt;em&gt;semi-na&amp;iuml;ve evaluation&lt;/em&gt;.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Krule Extensions&lt;/h3&gt; While this covers the "batch" use-case, what about the "iterative" use-case, where the user wants to perform inferences on streams of data as it is inserted into an existing database? In this case, the batch approach is too heavyweight, as it will infer statements that are almost entirely pre-existing. We might handle the non-insertion of these statements pretty well, but if you do the work again and again for every statement you try to insert, then it will add up. In this case, the iterative approach of standard RETE is more appropriate.&lt;br /&gt;&lt;br /&gt;Unfortunately, RETE needs to build its tables up by iterating over the entire data set, but I've already indicated that this is expensive for the size of set that may be encountered. However, the Krule approach of using constraint resolutions as the tables is perfect for pre-populating these tables in a standard RETE engine. I mentioned this to Alex a few months ago, and he pointed out that he did exactly the same thing once before when implementing RETE in &lt;abbrev title="Tucana Knowledge Store"&gt;TKS&lt;/abbrev&gt;.&lt;br /&gt;&lt;br /&gt;I haven't actually done this extension, but I thought I'd let people know that we haven't forgotten it, and it's in the works. It will be based on Krule configurations, so a lot of existing work will be reused.&lt;br /&gt;&lt;br /&gt;I don't want to overdo it in one post, so I'll write about RLog in the next one.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6848574-2523761822983983225?l=gearon.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://gearon.blogspot.com/2009/02/programmable-logic-i-had-hoped-to-blog.html</link><author>noreply@blogger.com (Quoll)</author><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6848574.post-7513571316750121818</guid><pubDate>Thu, 19 Feb 2009 06:34:00 +0000</pubDate><atom:updated>2009-02-19T00:47:08.730-06:00</atom:updated><title /><description>&lt;h3&gt;Is it Me?&lt;/h3&gt; After struggling against nonsensical errors all day, I finally realized that either Eclipse was going mad, or I was. In frustration I finally updated a method to look like this:&lt;pre&gt;&lt;code&gt;  public void setContextOwner(ContextOwner owner) {&lt;br /&gt;    contextOwner = owner;&lt;br /&gt;    if (owner != contextOwner) throw new AssertionError("VM causing problems");&lt;br /&gt;  }&lt;/code&gt;&lt;/pre&gt;This code throws an AssertionError, and yes, there is only 1 thread. If it were multithreaded at least I'd have a starting point. The problem only appears while debugging in Eclipse.&lt;br /&gt;&lt;br /&gt;I'm not sure whether I'm happy to have isolated my problem down to a single point, or to be unhappy at something that is breaking everything I am trying to work on. I guess I'm unhappy, because it's kept me up much later than I'd hoped.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6848574-7513571316750121818?l=gearon.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://gearon.blogspot.com/2009/02/is-it-me-after-struggling-against.html</link><author>noreply@blogger.com (Quoll)</author><thr:total>2</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6848574.post-6773794379073821893</guid><pubDate>Tue, 17 Feb 2009 06:48:00 +0000</pubDate><atom:updated>2009-02-17T02:16:08.381-06:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">REST</category><category domain="http://www.blogger.com/atom/ns#">RDF</category><title /><description>&lt;h3&gt;Resting&lt;/h3&gt; I've had a couple of drinks this evening. Lets see if that makes me more or less intelligible.&lt;br /&gt;&lt;br /&gt;Now that I've added a &lt;abbr title="REpresentational State Transfer"&gt;REST&lt;/abbr&gt;-like interface to Mulgara, I've found that I've been using it more and more. This is fine, but to modify data I've had to either upload a document (a very crude tool) or issue write commands on the &lt;abbr title="Tucana Query Language"&gt;TQL&lt;/abbr&gt; endpoint. Neither of these were very RESTful, and so I started wondering if it would make sense to do something more direct.&lt;br /&gt;&lt;br /&gt;From my perspective (and I'm sure there will be some who disagree with me), the basic resources in an RDF database are graphs and statements. Sure, the URIs themselves are resources, but the perspective of RDF is that these resources are infinite. Graphs are a description of how a subset of the set of all resources are related. Of course, these relationships are described via statements.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Graphs and Statements&lt;/h3&gt; So I had to work out how to represent a graph in a RESTful way. Unfortunately, graphs are already their own URI, and this probably has nothing to do with the server it is on. However, REST requires a URL which identifies the host and service, and then the resource within it. So the graph URI has to be embedded in the URL, after the host. While REST URLs typically try to reflect structure in a path, encoding a URL makes this almost impossible. Instead I opted to encode the graph URI as a "graph" parameter.&lt;br /&gt;&lt;br /&gt;Statements posed a similar though more complex challenge. I still needed the graph, so this had to stay. Similarly, the other resources also needed to be encoded as parameters, so I added this as well. This left me with 2 issues: blank nodes and literals.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Literals&lt;/h3&gt; Literals were reasonably easy... sort of. I simply decided that anything that didn't look like a URI would be a literal. Furthermore, if it was structured like a SPARQL literal, then this would be parsed, allowing a datatype or language to be included. However, nothing is never &lt;em&gt;really&lt;/em&gt; easy (of course) and I found myself wondering about relative URIs. These had never been allowed in Mulgara before, but I've brought them in recently after several requests. Most people will ignore them, but for those people who have a use, they can be handy. That all seems OK, until you realize that the single quote character &amp;quot; is an &lt;em&gt;unreserved&lt;/em&gt; character in URIs, and so the apparent literal &lt;em&gt;&amp;quot;foo&amp;quot;&lt;/em&gt; is actually a valid relative URI. (Thank goodness for unit tests, or I would never have realized that). In the end, I decided to treat any valid URI as a URI and not a literal, &lt;em&gt;unless&lt;/em&gt; it starts with a quote. If you really want a relative URI of &lt;em&gt;&amp;quot;foo&amp;quot;&lt;/em&gt; then you'll have to choose another interface.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Blank Nodes&lt;/h3&gt; Blank nodes presented another problem. Initially, I decided that any missing parameter would be a blank node. That worked well, but then I started wondering about using the same blank node in more than one statement. I'm treating statements as resources, and you can't put more than one "resource" into a REST URL, so that would mean referring to the same "nameless" thing in two different method calls, which isn't possible. Also, adding statements with a blank node necessarily creates a new blank node every time, which breaks idempotency.&lt;br /&gt;&lt;br /&gt;Then what about deletion? Does nothing match, or does the blank node match everything? But doing matches like that means I'm no longer matching a single statement, which was what I was trying to do to make this REST and not RPC for a query-like command.&lt;br /&gt;&lt;br /&gt;Another option is to refer to blanks with a syntax like &lt;code&gt;_:123&lt;/code&gt;. However, this has all of the same problems we've had with exactly this idea in the query language. For instance, these identifiers are not guaranteed to match between different copies of the same data. Also, introducing new data that includes the same ID will accidentally merge these nodes incorrectly. There are other reasons as well. Essentially, you are using a name for something that was supposed to be nameless, and because you're not using URIs (like named things are supposed to use) then you're going to encounter problems. URIs were created for a reason. If you need to refer to something in a persistent way, then use a name for it. (Alternatively, use a query that links a blank node through a functional/inverse-functional predicate to uniquely identify it, but that's another discussion).&lt;br /&gt;&lt;br /&gt;So in the end I realized that I can't refer to blank nodes at all in this way. But I think that's OK. There are other interfaces available if you need to work with blank nodes, and &lt;a href="http://www.talis.com/platform/"&gt;some applications&lt;/a&gt; prohibit them anyway.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Reification&lt;/h3&gt; Something I wanted to come back to is this notion of representing a statement as 3 parameters in a URL (actually 4, since the graph is needed). The notion of representing a statement as a URI has already been addressed in reification, however I dismissed this as a solution here since reifying a statement does not imply that statement exists (indeed, the purpose of the reification may be to say that the statement is false). All the same, it's left me thinking that I should consider a way to use this interface to reify statements.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Methods&lt;/h3&gt; So the methods as they stand now are:&lt;br /&gt;&lt;table border="1"&gt;&lt;tr&gt;&lt;th&gt;method/ resource&lt;/th&gt;&lt;th&gt;Graph&lt;/th&gt;&lt;th&gt;Statement&lt;/th&gt;&lt;th&gt;Other&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;th&gt;GET&lt;/th&gt;&lt;td align="center"&gt;N/A&lt;/td&gt;&lt;td align="center"&gt;N/A&lt;/td&gt;&lt;td align="center"&gt;Used for queries.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;th&gt;POST&lt;/th&gt;&lt;td align="center"&gt;Upload graphs&lt;/td&gt;&lt;td align="center"&gt;N/A&lt;/td&gt;&lt;td align="center"&gt;Write commands (not SPARQL)&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;th&gt;PUT&lt;/th&gt;&lt;td align="center"&gt;Creates graph&lt;/td&gt;&lt;td align="center"&gt;Creates statement&lt;/td&gt;&lt;td align="center"&gt;N/A&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;th&gt;DELETE&lt;/th&gt;&lt;td align="center"&gt;Deletes graph&lt;/td&gt;&lt;td align="center"&gt;Deletes statement&lt;/td&gt;&lt;td align="center"&gt;N/A&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;br /&gt;I haven't done HEAD yet (I intend to indicate if a graph or statement exists), and I'm ignoring OPTION.&lt;br /&gt;&lt;br /&gt;I've also considered what it might mean to GET a statement or a graph. When applied to a graph, I could treat this as a synonym for the query:&lt;pre&gt;&lt;code&gt;  construct {?s ?p ?o} where {?s ?p ?o}&lt;/code&gt;&lt;/pre&gt;Initially I didn't think it made much sense to GET a statement, but while writing this it occurs to me that I could return a reification URI, if one exists (this is also an option for HEAD, but I think &lt;em&gt;existence&lt;/em&gt; is a better function there).&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Is There a Point?&lt;/h3&gt; Everything I've discussed here may seem pointless, especially since there are alternatives, none of it is standard, and I'm sure there will be numerous criticisms on my choices. On the other hand, I wrote this because I found that uploading documents at a time to be too crude for real coding. I also find that constructing TQL command to modify data to be a little too convoluted in many circumstances, and that a simple PUT is much more appropriate.&lt;br /&gt;&lt;br /&gt;So, I'm pretty happy with it, for the simple fact that &lt;em&gt;I&lt;/em&gt; find it useful. If anyone has suggested modifications or features, than I'll be more than happy to take them on board.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6848574-6773794379073821893?l=gearon.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://gearon.blogspot.com/2009/02/resting-ive-had-couple-of-drinks-this.html</link><author>noreply@blogger.com (Quoll)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6848574.post-8431227637282433975</guid><pubDate>Fri, 13 Feb 2009 15:02:00 +0000</pubDate><atom:updated>2009-02-13T12:09:00.515-06:00</atom:updated><title /><description>&lt;h3&gt;Prodding&lt;/h3&gt; Going back through a recent flurry of activity by &lt;a href="http://twitter.com/wmudge"&gt;Webster Mudge&lt;/a&gt; on Google Groups, I noticed a couple of things directly related to me.&lt;br /&gt;&lt;br /&gt;First was a link to &lt;a href="http://prototypo.blogspot.com/2009/02/skos-in-mulgaras-rlog.html"&gt;David Wood's post&lt;/a&gt; from last month in which he talks about how I did &lt;a href="http://www.w3.org/2004/02/skos/"&gt;SKOS&lt;/a&gt; using &lt;a href="http://www.mulgara.org/trac/wiki/Rules"&gt;RLog&lt;/a&gt; (some nice compliments BTW, thanks David). Both in this post and personally, David has been hassling me to integrate RLog into Mulgara. I'd love to get this done, but SPARQL and scalability have been priorities for me, and no one ever asked for RLog before. But it's been shuffling to the top of my list recently, so I'm going to see what I can get done in the next week, before I get loaded with new priorities.&lt;br /&gt;&lt;br /&gt;The other link was to &lt;a href="http://jena.sourceforge.net/SquirrelRDF/"&gt;SquirrelRDF&lt;/a&gt; and included the comment, &lt;span style="font-style:italic;"&gt;“Great idea, bummer it's tied to Jena.”&lt;/span&gt; This intrigued me, and I wondered if it was something Mulgara could do, so I checked it out. Only, once I got there I discovered that Mulgara already does it, and has done for years!&lt;br /&gt;&lt;br /&gt;That's one of the biggest problems with Mulgara: lack of documentation. People just aren't aware of what the system can do, and there's no easy way to find out. I'd love to fix this on the Wiki, but when I'm accountable for getting things done, and not for telling people how to do it, then I tend to opt for the "getting things done" work instead.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Resolvers&lt;/h3&gt; For anyone interested, Mulgara has a system we call the "Resolver" interface. The purpose of this is to present any data as live RDF data. Included with Mulgara are resolvers for accessing: &lt;a href="http://lucene.apache.org/"&gt;Lucene&lt;/a&gt; indexes; RDF files over HTTP; filesystem data; &lt;abbr title="Geographic Information System"&gt;GIS&lt;/abbr&gt; data; &lt;abbr title="Relational Data Base Management System"&gt;RDBMS&lt;/abbr&gt;s (via &lt;a href="http://java.sun.com/javase/technologies/database/"&gt;JDBC&lt;/a&gt;, and using &lt;a href="http://www4.wiwiss.fu-berlin.de/bizer/d2rq/"&gt;D2RQ&lt;/a&gt;); &lt;abbr title="Java ARchive"&gt;JAR&lt;/abbr&gt; files; plus a few resolvers specifically for representing aspects of literals and URIs stored in the database. Most are read-only interpretations of external data, but some are writable.&lt;br /&gt;&lt;br /&gt;We also have a related system called "Content Handlers". These are for handling raw file formats and returning RDF triples. We support the obvious RDF/XML and N3 file formats, but also interpret Unix MBox files and MP3 files (the latter was done as a tutorial). This mixes well with things like the HTTP and file resolvers, as it lets us refer to a graph such as &lt;a href="http://www.w3.org/2000/01/rdf-schema"&gt;http://www.w3.org/2000/01/rdf-schema&lt;/a&gt; in a query. In this example the graph will not be in the local database (it could be, but only if you'd created it), so the HTTP resolver will be asked to retrieve the contents from the URL. Once the data arrived, it would be sent to the RDF/XML content handler (havind recognized the "application/rdf+xml" &lt;abbr title="Multipurpose Internet Mail Extensions"&gt;MIME&lt;/abbr&gt; type), which will then turn it into a queryable local graph in memory. The query can continue then as if everything was local. If the data is on the local filesystem, or MIME type isn't recognized, then it will fall back to relying on filename extensions.&lt;br /&gt;&lt;br /&gt;It's because of the way these things hook together that allows us to hook SPARQL sources together easily. It may be messy, but it is perfectly possible to select from a graph with a URI like:&lt;br /&gt;&lt;pre&gt;&lt;code&gt;http://host/sparql?default-graph-uri=my%3Agraph&amp;&lt;br /&gt;query=%40prefix+rdfs%3A+%3Chttp%3A%2F%2Fwww.w3.org%2F2000%2F01%2Frdf-schema%23%3E+.&lt;br /&gt;+create+%7B+%3Fs+%3Fp+%3Fo+%7D+where+%7B+%3Fs+%3Fp+%3Fo+.&lt;br /&gt;+%3Fp+rdfs%3Adomain+%3Cmy%3AClass%3E+%7D&lt;/code&gt;&lt;/pre&gt;I've split the URI over a few lines to make it fit better, and I also used the graph name of &lt;code&gt;my:graph&lt;/code&gt; just to keep it shorter. It's legal, though unusual.&lt;br /&gt;&lt;br /&gt;Mulgara originally aimed at being highly scalable, and we're in the process of regaining that title (honest... the modest improvements we've had recently are orders of magnitude short of XA2). However, the sheer number of features and flexibility of the system is probably it's most compelling attribute at the moment. If only I could document it all, and spread the word.&lt;br /&gt;&lt;br /&gt;Oh well, back to the grind. At the moment I'm alternating between &lt;abbr title="REpresentational State Transfer"&gt;REST&lt;/abbr&gt;ful features (I want to PUT and DELETE individual statements) and a class that will transparently memory map a file larger than 2GB. For the latter, I'd love to offer and extension to &lt;a href="http://java.sun.com/javase/6/docs/api/java/nio/Buffer.html"&gt;java.nio.Buffer&lt;/a&gt;, but this package has been completely locked down by Sun. I hate not being able to extend on built-in functionality.  :-(&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6848574-8431227637282433975?l=gearon.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://gearon.blogspot.com/2009/02/prodding-going-back-through-recent.html</link><author>noreply@blogger.com (Quoll)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6848574.post-4698312072094959141</guid><pubDate>Wed, 03 Dec 2008 04:29:00 +0000</pubDate><atom:updated>2008-12-02T23:23:13.921-06:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">indexing</category><title /><description>&lt;h3&gt;Dropping Indexes&lt;/h3&gt; One of the optimizations I'm making for XA 1.1 is the removal of 3 of our 6 statement indexes. The reason for this is pretty clear: they're almost &lt;em&gt;never&lt;/em&gt; used. Why would I want to double our space, and double our contention for the hard drive on data structures that are superfluous?&lt;br /&gt;&lt;br /&gt;To date, Mulgara's indexes have been completely symmetric. I still want to maintain this with respect to &lt;em&gt;subject&lt;/em&gt;, &lt;em&gt;predicate&lt;/em&gt; and &lt;em&gt;object&lt;/em&gt;, but I don't really see the need for it with graphs. (That said, the 2-column index in XA2 will have optimizations around common predicates, but in general there will still be symmetry). I've had people say that they want to use millions of graphs, but in reality I've yet to see it. The query languages (TQL, SPARQL, etc) haven't really supported large numbers of graphs anyway.&lt;br /&gt;&lt;br /&gt;The index orderings we've had to date have been:&lt;pre&gt;&lt;code&gt;  SPOG&lt;br /&gt;  POSG&lt;br /&gt;  OSPG&lt;br /&gt;  GSPO&lt;br /&gt;  GPOS&lt;br /&gt;  GOSP&lt;/code&gt;&lt;/pre&gt;For &lt;strong&gt;G&lt;/strong&gt;=Graph, &lt;strong&gt;S&lt;/strong&gt;=Subject, &lt;strong&gt;P&lt;/strong&gt;=Predicate, &lt;strong&gt;O&lt;/strong&gt;=Object.&lt;br /&gt;&lt;br /&gt;For anyone unfamiliar with these indexes, they permit a group of statements to be found given any possible pattern of 0, 1, 2, 3 or 4 elements.&lt;br /&gt;&lt;br /&gt;The first 3 indexes allow for searching on statements that may occur in any graph. However, almost all queries identify the graphs to be searched in, meaning that we always end up binding the "graph" node before looking for statements. That means that the first 3 indexes are &lt;em&gt;almost&lt;/em&gt; never used. However, it's the "almost" which is my problem at the moment.&lt;br /&gt;&lt;br /&gt;Fortunately, the first 3 indexes can be easily emulated with our "System graph". This countains a list of all the known graphs, particularly the graphs stored with the "System Resolver" (this is the part of the system that uses the above indexes). Using this information, it is possible to pre-bind the graph node for every possible query. However, I really want to do this at the lowest possible level, so the interface on the resolver remains unchanged.&lt;br /&gt;&lt;br /&gt;Dropping the first 3 indexes went smoothly, and 97% of the tests still work (OK, it's 96.99%, but who's counting?). However, the emulation of these indexes will probably take me a few days. That's a shame, as I'd prefer to get it all into the next release, but since I want to do a release before I go to Australia for Christmas (on Monday) then I'm pretty sure I can't do it in time (not if I want robust testing anyway).&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Compromises&lt;/h3&gt; Emulating the indexes which allow unbound graphs, means that I'll need to bind the graph to a series of ALL the graphs in the system. Then for each of those graphs, I'll need to re-execute the resolution of the graph pattern being resolver. That means that for these types of queries, then it will increase in complexity with the number of graphs in the system. This goes completely against what we want in Mulgara, but as I said, it's such a rarely used feature that the cost seems mitigated.&lt;br /&gt;&lt;br /&gt;I had thought that I'd be doing a query to find the graphs, and then join this to the resolution of the graph pattern that we want, but that failed to take several things into account. First, resolutions from the resolver come back with a particular order, and the kind of join I was proposing was not going to be ordered the way we wanted (it would have been ordered for within each graph, and then ordered within the graph). Reordering may have been prohibitively expensive (depending on context), so this was out.&lt;br /&gt;&lt;br /&gt;It was while thinking through on this that I realized I can create a new Tuples "append" operation. The new append will take arguments that all have the same variables and the same ordering, and will perform a streamed merge-sort. This should give me exactly what I want.&lt;br /&gt;&lt;br /&gt;So the next thing I need is the complete list of graphs to bind the "G" node to when querying the indexes. I have thought that I'd be doing a query of the system graph for this, but my thinking has moved on from there. To start with, in order to make this query, I'll need the local node value for &lt;code&gt;&amp;lt;rdf:type&amp;gt;&lt;/code&gt; the URI for the "type" of graphs stored in the system resolver, and the system graph itself (a relative URI of &lt;code&gt;&amp;lt;#&amp;gt;&lt;/code&gt;). The creation of these occurs during bootstrapping, and is fortunately over before any possibility of my "unusual" queries.&lt;br /&gt;&lt;br /&gt;While thinking about getting the local node values for these URIs, it occurred to me that something similar to the mechanism to do this can be used to record whenever a graph is being created in the system graph. That means that I can store each of the graphs in a list (and re-populate this list on startup with a simple constraint resolution). This list then becomes the basis for the graph bindings when I'm trying to emulate the missing indexes.&lt;br /&gt;&lt;br /&gt;My first concern was that this might take too much space, thereby limiting the number of graphs that someone can have (as I said, some people have proposed using millions), but then I realized that my merge-join was going to need to reference the same number of resolutions as the number of graphs, and this would take more RAM anyway. It's really a moot point anyway, since the system would choke from performing a million lookups before you need to worry about an Out Of Memory condition. All this reminds me... I should worry too much about optimizations at such at early juncture. Premature optimization is the root of all evil.&lt;br /&gt;&lt;br /&gt;Anyway, I'll probably spend a day on this, and may even get it all going, but I won't have it tested in time for a release before the weekend. I'd better let Amit (my boss) know that he won't get it until Christmas.  :-)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6848574-4698312072094959141?l=gearon.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://gearon.blogspot.com/2008/12/dropping-indexes-one-of-optimizations.html</link><author>noreply@blogger.com (Quoll)</author><thr:total>4</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6848574.post-1789534819774988294</guid><pubDate>Wed, 03 Dec 2008 04:20:00 +0000</pubDate><atom:updated>2008-12-02T22:29:42.303-06:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">performance</category><category domain="http://www.blogger.com/atom/ns#">disk</category><category domain="http://www.blogger.com/atom/ns#">Graphs</category><title /><description>&lt;h3&gt;Size&lt;/h3&gt; Disk usage is probably the second most common question I get about Mulgara, after speed. So to complement the plots from Monday, I've also plotted the disk usage for these "number" graphs.&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_GtcSYVnYjYQ/STYI5hJqN8I/AAAAAAAAAAw/9MwWC31q1zQ/s1600-h/image001.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 273px;" src="http://1.bp.blogspot.com/_GtcSYVnYjYQ/STYI5hJqN8I/AAAAAAAAAAw/9MwWC31q1zQ/s400/image001.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5275413797755566018" /&gt;&lt;/a&gt;&lt;br /&gt;The lowest line represents the space being used for URIs and Literals. The upper line is for the statements themselves. For convenience, the top line is the sum of the other two.&lt;br /&gt;&lt;br /&gt;This storage mechanism is doing no compression on the data whatsoever. The current code in XA2 is already using an order of magnitude less space, both because of more intelligent storage, and also because many blocks will be gzip compressed in our structures. Andrae's reasoning for that is that while CPUs are getting faster all the time, disks are not. This means that any processing we do on the data is essentially free, since the CPU can usually be done in less than the time it takes to wait for a hard drive to return a result, even a solid state drive.&lt;br /&gt;&lt;br /&gt;I should note that these graphs are all on a version of XA1.1 that is not yet released (it's in SVN, but not in the trunk yet). I've been hoping to get this into the next release, but because I'm doing a release by the end of this week, then I'm thinking it will have to be in the release after (before Christmas).&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6848574-1789534819774988294?l=gearon.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://gearon.blogspot.com/2008/12/size-disk-usage-is-probably-second-most.html</link><author>noreply@blogger.com (Quoll)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/_GtcSYVnYjYQ/STYI5hJqN8I/AAAAAAAAAAw/9MwWC31q1zQ/s72-c/image001.png" height="72" width="72" /><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6848574.post-644599254200113973</guid><pubDate>Mon, 01 Dec 2008 15:36:00 +0000</pubDate><atom:updated>2008-12-01T12:43:38.761-06:00</atom:updated><title /><description>&lt;h3&gt;Mulgara Stats&lt;/h3&gt; The one question everyone asks me about Mulgara is always some variation on "How does it scale?" It's never easy to answer, as it depends on the hardware you're using, the OS (Linux does memory mapping better than Windows), and of course, the data.&lt;br /&gt;&lt;br /&gt;I wanted to put off benchmarking until XA2 was released (early next year). I've also been hoping to have decent hardware to do it with, though I'm less sure about when that might happen. However, I've improved things by releasing the XA1.1 system recently, and it doesn't hurt to see how things run on desktop hardware.&lt;br /&gt;&lt;br /&gt;RDF data varies according to the number of triples, the number of distinct URIs and literals, and the size of the literals. Some data uses only a few predicates, a modest number of URIs, and enormous literals. Other data uses only a few short literals, and has lots of URIs. Then there is the number of triples being stored. As an example, doing complete RDFS inferencing will introduce no new resources, but can increase the number of triples in a graph by an order of magnitude.&lt;br /&gt;&lt;br /&gt;There are various standard sets and I intend to explore them, but in the meantime I'm going with a metric that Kowari/TKS used back in the days of Tucana, when we had a big 64bit machine with fast RAID storage. Funnily enough, these days I have a faster CPU, but I still don't have access to storage that is as fast as that box had.&lt;br /&gt;&lt;br /&gt;The data I've been working with is the "Numbers" data set that I first created about 4 years ago. I tweaked the program a little bit, adding a couple of options and updating the output. There are probably better ways to model numbers, but the point of this is just to grow a large data set, and it does that well. You can find the code &lt;a href="http://mulgara.org/files/misc/rdf-generator.tar.gz"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Hardware&lt;/h3&gt; The computer I've been using is my MacBook Pro, which comes with the following specs:&lt;pre&gt;Mac OS 10.5.5&lt;br /&gt;2.6 GHz Intel Core 2 Duo&lt;br /&gt;4GB 667 MHz DDR2 SDRAM&lt;br /&gt;4MB L2 Cache&lt;br /&gt;HDD: Hitachi HTS722020K9SA00&lt;br /&gt;     186.31GB&lt;br /&gt;     Native Command Queuing: Yes&lt;br /&gt;     Queue Depth: 32&lt;br /&gt;     File System Journaled HFS+&lt;/pre&gt;&lt;br /&gt;Note that there is &lt;strong&gt;nothing&lt;/strong&gt; about this machine that is even slightly optimized for benchmarking. If I had any sense, I'd be using Linux, and I wouldn't have a journaled filesystem (since Mulgara maintains its own integrity). Even if I couldn't have RAID, it would still be beneficial to use another hard drive. But as I said, this is a standard desktop configuration.&lt;br /&gt;&lt;br /&gt;Also, being a desktop system, it was impossible to shut down everything else, though I did turn off backups, and had as few running programs as possible.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;The Test&lt;/h3&gt; I used a series of files, generating numbers to each million mark, up to 30 million. The number of triples was approximately 8-9 times the largest number, with the numbers from 1 to 30 million generating 267,592,533 triples, or a little over a quarter of a billion triples.&lt;br /&gt;&lt;br /&gt;Each load was done with a clean start to Mulgara, and was done in a single transaction. The data was loaded from a gzipped RDF/XML file. I ignored caching in RAM, since the data far exceeded the amount of RAM that I had.&lt;br /&gt;&lt;br /&gt;At the conclusion of the load, I ran a query to count the data. We still have linear counting complexity, so this is expected to be an expensive operation (this will change soon).&lt;br /&gt;&lt;br /&gt;Due to the time needed for larger loads, I skipped most of the loads in the 20 millions. However, the curve for load times is smooth enough that interpolation is easy. The curve for counting is all over the place, but you'll have to live with that.&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_GtcSYVnYjYQ/STQsArRJV8I/AAAAAAAAAAk/EUJusSZ_E-U/s1600-h/image001.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 321px;" src="http://2.bp.blogspot.com/_GtcSYVnYjYQ/STQsArRJV8I/AAAAAAAAAAk/EUJusSZ_E-U/s400/image001.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5274889453683955650" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;The axis on the left is the number of seconds for loading, and the axis on the right is the number of seconds for counting. The X-axis is the number of triples loaded.&lt;br /&gt;&lt;br /&gt;Counting was less that a second up to the 8 million mark (70.8 million triples). This would be because most of the index could fix into memory. While the trees in the indexes do get shuffled around as they grow, I don't think that explains the volatility in the counting times I'm guessing that external processes had a larger influence here, since the total time was still within just a few minutes (as opposed to the full day required to load the quarter billion triples in the final load).&lt;br /&gt;&lt;br /&gt;Overall, the graph looks to be gradually increasing beyond linear growth. From experience with tests on XA1, we found linear growth, followed by an elbow, and then an asymptotic approach to a new, much steeper gradient. This occurred at the point where RAM could no longer effectively cache the indexes. If that is happening here, then the new gradient is still somewhere beyond where I've tested.&lt;br /&gt;&lt;br /&gt;My next step is to start profiling load times with the XA1 store. I don't have any real comparison here, except that I know that there is a point somewhere in the middle of this graph (depending on my RAM) where XA1 will suddenly turn upwards. I've already seen this from Ronald's tests, but I've yet to chart it against this data.&lt;br /&gt;&lt;br /&gt;I'm also very excited to see how this will compare with XA2. I'm meeting Andrae in Brisbane next week, so I'll find out more about the progress then.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6848574-644599254200113973?l=gearon.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://gearon.blogspot.com/2008/12/mulgara-stats-one-question-everyone.html</link><author>noreply@blogger.com (Quoll)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/_GtcSYVnYjYQ/STQsArRJV8I/AAAAAAAAAAk/EUJusSZ_E-U/s72-c/image001.png" height="72" width="72" /><thr:total>2</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6848574.post-6135747305180855637</guid><pubDate>Fri, 19 Sep 2008 03:57:00 +0000</pubDate><atom:updated>2008-10-16T21:12:58.378-05:00</atom:updated><title /><description>&lt;h3&gt;Disclaimer&lt;/h3&gt; New babies are wonderful, but the resulting sleep patterns are far from optimal. Please excuse me if I stop making sense halfway through any of the ensuing sentences.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Hash Tables&lt;/h3&gt; Whenever I have a spare moment (and sometimes when I don't) I'm forever re-examining how I think RDF should be indexed. After all, I've already found a few different ways to do it, both in Mulgara and out of it, and each have their own pros and cons.&lt;br /&gt;&lt;br /&gt;One of the most interesting indexes to consider is the Hash Table. Constant time reads and writes makes for a compelling argument in terms of scalability. Re-hashing an index during expansion is painful on systems that should scale, but I was recently reminded that amortized complexity is still linear, so I shouldn't be &lt;strong&gt;too&lt;/strong&gt; scared.&lt;br /&gt;&lt;br /&gt;Years ago &lt;acronym title="Tucana Knowledge Store"&gt;TKS&lt;/acronym&gt; (the forerunner to both Mulgara and Kowari) used a few on-disk hash tables, but they proved ineffective for us, and we moved to trees. But many of our assumptions back in 2000 no longer apply to modern systems, and I've already found several things worth re-examining for this reason. On top of that, Andy Seaborne was discussing using them for Jena, and while I was initially dubious, on further reflection I can see the reasoning.&lt;br /&gt;&lt;br /&gt;&lt;h4&gt;Pros&lt;/h4&gt; &lt;strong&gt;It's &lt;em&gt;O(1)&lt;/em&gt;:&lt;/strong&gt; That's kind of a trump card. Everything else I have to say here is a discussion as to what could possibly be more important than being &lt;em&gt;O(1)&lt;/em&gt;.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Opaque Data:&lt;/strong&gt; Data store in a hash is treated as an atom, meaning there is no ordering or other meaning on the data. While this creates problems (mentioned below) it also provides the opportunity to distribute the data across a cluster like &lt;a href="http://hadoop.apache.org/"&gt;Hadoop&lt;/a&gt;. That's a big deal these days.&lt;br /&gt;&lt;br /&gt;&lt;h4&gt;Cons&lt;/h4&gt; &lt;strong&gt;Re-Hashing:&lt;/strong&gt; The first problem I think about with on-disk hash tables is the cost of a re-hashing operation. These are expensive in memory, but on disk they are going to be frightful. Reading the original hash will be OK, as this is a linear scan through the file, but writing will be problematic, as the seeks are essentially random. That's a cost of &lt;em&gt;N&lt;/em&gt; seeks, for &lt;em&gt;N&lt;/em&gt; entries (ignoring seeks for reads, but they're amortized, and could even be on another drive). There may be some algorithms for clustering the writes, but if you're trying to scale on the size of your data, then this would be overwhelmed.&lt;br /&gt;&lt;br /&gt;The best way to address this is to allocate as much space as you can, and to be generous when growing. That could be a problem for some systems, but if you're &lt;em&gt;really&lt;/em&gt; in the business of scaling on data, then you'll be up for it.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Space:&lt;/strong&gt; Hash tables require a lot of empty space to work, else you end up with a lot of hashing collisions, and those lovely &lt;em&gt;O(1)&lt;/em&gt; properties go out the window (until you expand and re-hash, but I've already talked about that). I shouldn't really make a big deal out of this, especially when you consider that Mulgara was built using the idea that "disk is cheap", but it does still feel a little strange to be that lavish. Also, being extravagant with space can lead to speed issues as well, so it's always worth looking at with the critical eye, even if the final decision is to use the space.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;No Ordering:&lt;/strong&gt; Data in a hash table cannot be ordered. Well, OK, a &lt;em&gt;linked&lt;/em&gt; hash table can do it, but you only want to link by insertion order, or else all your &lt;em&gt;O(1)&lt;/em&gt; benefits are gone.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Hashes and SPARQL&lt;/h3&gt; Of the three cons I listed here, it's relatively easy to justify the concerns about re-hashing and space. In fact, once you decide that "space is no object", then re-hashing isn't such a big deal since you can just start with an enormous table that never (or &lt;em&gt;almost&lt;/em&gt; never) gets rehashed.&lt;br /&gt;&lt;br /&gt;The ordering issue bugged me for a while, and it was then that I realized that this actually works well for SPARQL. In fact, this looks like yet another case where the heritage of filtering is showing up again (though maybe it's a coincidence this time).&lt;br /&gt;&lt;br /&gt;When you use the appropriate resolvers in Mulgara (in either TQL or SPARQL, since resolvers are just mapped onto graph names) then data can be selected by "range". This lets us select an ordered set of date/times, numbers, or strings that occur between a pair of boundaries. (Particularly useful for something like selecting events during a particular time window). It is even useful for selecting URIs based on namespace. These selections are then joined to the remainder of the query to create a result. The end effect is processing much less data than simply selecting it all, and FILTERing it down by the data that meets the given criteria. We always pursued this in Mulgara, as we found that filtering could slow down certain queries by orders of magnitude.&lt;br /&gt;&lt;br /&gt;However, SPARQL was never designed for this kind of thing, and as a result it relies entirely on filtering to do its work. This usually bothers me, but for hash tables it actually works, since they don't provide the ability to select a range anyway, and hence &lt;em&gt;require&lt;/em&gt; filtering if you want to use them.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;To Tree or not to Tree?&lt;/h3&gt; I've been wedded to trees in Mulgara for so long that it feels weird just examining a system without them. Of course, I've already moved away from the use of trees with the new &lt;a href="http://gearon.blogspot.com/2008/04/writing-2-columns-in-my-last-post-i.html"&gt;statement store design&lt;/a&gt;, but I still thought that the data pool still had to be ordered, and hence, no hash tables.&lt;br /&gt;&lt;br /&gt;Now I can see the utility of using hash tables in this part of the system, providing you are prepared to using filtering for your results. Jena was always designed around these principles (it's easy to use, it's easy to implement, and it's &lt;em&gt;correct&lt;/em&gt;), so I understand why Andy would be attracted to it. However, I know that range queries are a big deal in Mulgara, so we really do need a tree somewhere.&lt;br /&gt;&lt;br /&gt;But perhaps we can mitigate some of the expense of tree indexes?&lt;br /&gt;&lt;br /&gt;Trees are really only needed for two types of query: ranges of data (meaning literals); and selecting strings or URIs by prefix. Neither of these are common operations, and are certainly not needed during the time-consuming load operation. So perhaps loads could be done entirely with a fast hash index, and afterwards a slow tree-based indexer could come through to order everything. Background indexing is nothing new, and even AllegroGraph does it, though I'm not sure how to manage a range query while waiting for an index to proceed.&lt;br /&gt;&lt;br /&gt;Another possibility would be to do inserts into a tree index, and simultaneously index the tree node with a hash index. After all, the tree nodes are not being reclaimed, and while their position in a tree may change, their data does not. This would require another seek/write during writing, but would save on &lt;em&gt;log(N)&lt;/em&gt; seeks when looking to see if a string or URI exists, which is the single most common operation during a load. That way there would be no background indexing to worry about waiting for, and the most common task drops from &lt;em&gt;log(N)&lt;/em&gt; to a single seek. Now &lt;em&gt;that&lt;/em&gt; has promise. I'll have to see if I can think of a decent Hadoop angle for it.&lt;br /&gt;&lt;br /&gt;So now I need to write the hash table file. We already have a few things that are close, so maybe I can leverage off one of those?&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Other Stuff&lt;/h3&gt; There's a LOT to write about with Mulgara, but this year I've tended to do the work rather than write about it. I believe that this is a false economy, since writing about things provides me with an invaluable log of what I did and when, and also helps me work out just what I need to be doing.&lt;br /&gt;&lt;br /&gt;On the other hand, late at night is not the time for me to be writing, especially when a baby is going to be waking me at various times between now and morning.&lt;br /&gt;&lt;br /&gt;All the same, I'll mention that I now have a couple of cute little servlets that let me do "HTTP GET" requests with &lt;a href="http://www.w3.org/TR/rdf-sparql-protocol/"&gt;SPARQL protocol&lt;/a&gt; parameters, and I get back either XML or &lt;a href="http://www.json.org/"&gt;JSON&lt;/a&gt; (depending on the value of an optional parameter called &lt;em&gt;out&lt;/em&gt;. Hmmm, maybe I should have called it &lt;em&gt;format&lt;/em&gt;?). One of the servlets is for TQL queries, while the main one is for SPARQL.&lt;br /&gt;&lt;br /&gt;These servlets also accept "HTTP POST" requests. In this case, the TQL servlet will allow commands that update data. The SPARQL servlet will eventually do this too, but not until I've implemented "&lt;a href="http://jena.hpl.hp.com/~afs/SPARQL-Update.html"&gt;SPARQL/Update&lt;/a&gt;". They will also accept MIME encoded files containing RDF data (RDF/XML, N3 and I think Turtle) and will load them into the default graph, which can be specified with the &lt;em&gt;default-graph-uri&lt;/em&gt; parameter.&lt;br /&gt;&lt;br /&gt;I haven't committed all of this code yet, since I ran into a bug when loading an RDF file. It turned out that this file finishes with the line:&lt;pre&gt;&lt;code&gt;&amp;lt;/rdf:RDF&amp;gt;&lt;/code&gt;&lt;/pre&gt; This line does not finish with a newline character, and this is confusing the ARQ parser we are using. Of course, I could just wrap the &lt;code&gt;InputStream &lt;/code&gt; object in something that appends a newline, but this is an unnecessary (and &lt;em&gt;horrible&lt;/em&gt;) hack, so I decided to look for the source of the problem.&lt;br /&gt;&lt;br /&gt;At this point I realized that we are still on Jena 2.1, while the world has moved on to &lt;a href="http://jena.sourceforge.net/downloads.html"&gt;2.5.6&lt;/a&gt;. Hopefully a move to 2.5.6 will fix this issue, so I decided to upgrade the Jar. Of course, this led to 2 other jars (&lt;code&gt;icu.jar&lt;/code&gt; and &lt;code&gt;arq.jar&lt;/code&gt;) along with &lt;em&gt;other&lt;/em&gt; tests failing (I think they were trying to compensate for a timezone bug, but this has been fixed now).&lt;br /&gt;&lt;br /&gt;While trawling through the Mulgara XSD classes I found what I think is the problem (compensation code for Jena not handling 0 months, though now it should). While there, I also learnt that despite parsing everything needed, the same data was being send to a Jena object for parsing. This seems quite redundant. It is also one of the few places that Jena classes are used (as opposed to just the ARP parser), so it would be great to drop this dependency if I can.&lt;br /&gt;&lt;br /&gt;So now a simple bug fix (not handling a missing newline character) seems to be leading me into all sorts of updates. Story of my life.&lt;br /&gt;&lt;br /&gt;OK, now I'm falling asleep between words, and have even caught myself starting to type something I started dreaming on 3 occasions. I think I've overstayed on my blog.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6848574-6135747305180855637?l=gearon.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://gearon.blogspot.com/2008/09/disclaimer-new-babies-are-wonderful-but.html</link><author>noreply@blogger.com (Quoll)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6848574.post-6531274686443076623</guid><pubDate>Thu, 31 Jul 2008 20:32:00 +0000</pubDate><atom:updated>2008-07-31T18:01:34.711-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">classpath</category><category domain="http://www.blogger.com/atom/ns#">JAR</category><category domain="http://www.blogger.com/atom/ns#">WAR</category><category domain="http://www.blogger.com/atom/ns#">Jetty</category><category domain="http://www.blogger.com/atom/ns#">Mulgara</category><category domain="http://www.blogger.com/atom/ns#">class path</category><title /><description>&lt;h3&gt;SPARQL&lt;/h3&gt; Perpetual coding doesn't leave much time for blogging. I'm in the middle of a long-running set of tests, so I figured I should take the time to write, even if I'm too tired.  :-)&lt;br /&gt;&lt;br /&gt;SPARQL on Mulgara always seems to have more to do than I have time or mandate for. That should be OK, given that SPARQL is now available through the SAIL API, but it's never quite that simple.&lt;br /&gt;&lt;br /&gt;To properly work with Sesame/SAIL we need to build (or at least deploy) Mulgara using Maven. Now I understand what Maven does... I've just never used it. On top of that, we have the &lt;em&gt;horrible&lt;/em&gt; build scripts that go into Mulgara, making the whole notion of re-creating the build system a little daunting. All the same, I've learned about creating a pom.xml, along with modules and inheritance, but I still need to read more docs on the topic. I'd like to get to this soon, but there are so many other pressing things.&lt;br /&gt;&lt;br /&gt;So working with SAIL isn't an out-of-the-box distribution yet, which is an impediment to using SPARQL. At this stage I think the Mulgara SAIL API is more of an advantage to Sesame than it is to us. Another reason why it would be good to get SPARQL going is because people are always &lt;em&gt;asking&lt;/em&gt; me for it. So even if I don't get 100% conformance, I should try to get it close. Anyone who needs it perfect can use the SAIL API.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Web Services&lt;/h3&gt; The best way to get SPARQL compliance is to run the test suite. That means you need some way to issue the queries and check the results. Now, I &lt;em&gt;could&lt;/em&gt; write the code to do this, but I know that other systems for running the test suite exist out there, and it would be better to use one of those if I could. However, those systems will all be using the SPARQL protocol for issuing queries, and that's one part I hadn't really touched yet.&lt;br /&gt;&lt;br /&gt;Fortunately, the protocol is just a web service, and Mulgara is already running web services. The response is just in XML, and I've written some code to do that already (though it's not checked in anywhere yet). I just need to glue it to a web service.&lt;br /&gt;&lt;br /&gt;Looking at it, the protocol is so simple that the service should be implementable with a relatively straightforward servlet. Servlets are quite easy to write, but deploying them is system dependent, so I thought I'd get the deployment part going first. I built a simple "hello world" servlet with the intent of expanding it into the real thing once it was integrated correctly.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Servlets&lt;/h3&gt; To start with, I followed the directions given for deploying a servlet in the &lt;a href="http://docs.codehaus.org/display/JETTY/Embedding+Jetty"&gt;Quick Start&lt;/a&gt; guide, and it all worked fine. Then I went to Mulgara to see how this would work.&lt;br /&gt;&lt;br /&gt;Now I'd been aware that Jetty hadn't been updated in Mulgara for a while, and I thought that this would be a good chance to update it. However the existing version was 4.2.19, while the latest (released) version is 6.1.19. Some of the APIs appeared to be completely incompatible, and while there was an upgrade guide from Jetty 5 to Jetty 6, there was nothing about Jetty 4. Obviously this task had been left for too long.&lt;br /&gt;&lt;br /&gt;So the first order of the day was &lt;strong&gt;not&lt;/strong&gt; to get a servlet deployed in Mulgara, but rather to upgrade Mulgara to use the latest Jetty. This also dovetailed with another task I've been wanting to do for some time, which was to clean up the file where all of the Jetty configuration happens: &lt;code&gt;EmbeddedMulgaraServer&lt;/code&gt;.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Upgrade&lt;/h3&gt; I eventually want to completely remove EmbeddedMulgaraServer and replace it with a lightweight program that loads up configurable modules. This will give us the benefits of having those modules ready for other types of deployment (another request I often get) as well as letting people customize the server, which is currently monolithic and unwieldy. I don't have time to get all of that done right now, but at least I got to tidy the code up to the point where this will be less intimidating. It also gave me a better view of what was going on in there (it regularly confuses developers who look at it).&lt;br /&gt;&lt;br /&gt;Mulgara had been deploying two sets of static pages and 2 web services in Jetty. The static pages included the documentation that is both obsolete (to be replaced by the gradually expanding Wiki), and available on the website. The other pages are all data files, which I believe are used for example scripts. I think it's a terrible idea to have these in the system, so I ripped them out. Moments later I thought better of it, and so I emailed the list to see what people thought. I was bemused to see that not only was this a welcome move, people wanted to get rid of the HTTP server altogether! (These people obviously want to access those individual modules I mentioned earlier). So then I created both an option in the config file, and a system property which can both disable the server (the system property takes precedence).&lt;br /&gt;&lt;br /&gt;That just left me with the 2 web applications in &lt;strong&gt;W&lt;/strong&gt;eb &lt;strong&gt;AR&lt;/strong&gt;chive files to deploy. This is where I came unstuck.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;WAR Files&lt;/h3&gt; I could not find any documentation on how to deploy a WAR file using the APIs in Jetty. So I muddled through the JavaDocs, picking up anything that looked promising. After an entire night of this, I eventually got something I thought might work, replacing &lt;code&gt;WebApplicationContext&lt;/code&gt; class with the &lt;code&gt;WebAppContext&lt;/code&gt; and trying to translate the differences in their APIs. I immediately got back an &lt;code&gt;IllegalStateException&lt;/code&gt; that occurred while the system was accessing the WAR file. While trying to work it out I delved into the Java libraries, and discovered that something had closed off the archive file while it was still in the process of reading it. It seemed too far down in the system to be anything I could have caused (or prevented), so I went searching online to see if anyone knew about it.&lt;br /&gt;&lt;br /&gt;It didn't take me long to see people mentioning this bug in relation to Jetty 5 about 2 years ago. It seemed strange that there wouldn't be a more recent reference, but that was the best I could get. Unfortunately, the response at the time was that the problem was indeed a bug with some of the Apache libraries that were used for this, which meant I was out of luck (sure, I could fix it, but that won't get me a deployed version of those libs any time soon).&lt;br /&gt;&lt;br /&gt;I saw Brian online (apparently traveling as a passenger in a car) and he told me that he'd heard of the problem, and suggested that I "expand" the archive to deploy it. I did this by manually pulling the WAR files into a temporary directory before pointing the WebAppContext at it. This avoided the IllegalStateException.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Class Paths&lt;/h3&gt; The deployment of these WAR files into Jetty 4 had a few things that didn't translate so well. The first was the configuration of something called a &lt;code&gt;SocketListener&lt;/code&gt;, which I figured out was replaced a &lt;code&gt;Connector&lt;/code&gt;. The second was in setting up the class paths. The code for this used to be:&lt;pre&gt;&lt;code&gt;  HttpContext contexts[] = httpServer.getContexts();&lt;br /&gt;  for (int i = 0; i &amp;lt; contexts.length; i++) {&lt;br /&gt;    contexts[i].setParentClassLoader(this.getClass().getClassLoader());&lt;br /&gt;  }&lt;/code&gt;&lt;/pre&gt;This seemed reasonable, though I wasn't sure why it was being done. I was about to learn.&lt;br /&gt;&lt;br /&gt;Jetty 6 no longer has the &lt;code&gt;Context.setParentClassLoader()&lt;/code&gt; method, though it is now possible to set the actual class loader for the context. However, the class loader I had available in that context (&lt;code&gt;this.getClass().getClassLoader()&lt;/code&gt;) was the same one that was already being used by that class. So I wasn't sure what to replace this with. Unfortunately, I made the mistake of choosing to set the class loader here anyway.&lt;br /&gt;&lt;br /&gt;When I tried running the program again, I was immediately being told of missing classes. Of course, neither these classes, nor any code for them existed on my system. I eventually worked out that these were classes that were generated from Java Servlet Pages (JSPs), which took me into the configuration for generating these pages.&lt;br /&gt;&lt;br /&gt;I hadn't realized we had JSPs in the system (will the cruft never end?!?) and I'd eventually like to get rid of these, even if I keep the web applications they're a part of. But for the moment, I had to upgrade those libs, and then update various build scripts which were trying to refer to the libs by name, and not with a generic variable (which we do for everything else - this lets us change versions relatively easily). I also discovered a "Tag" library for accessing Mulgara from JSPs. We don't seem to use it anywhere ourselves, and it just seems to be provided as a utility for users. The presence of this has me feeling reluctant to remove JSPs, but I'm still considering it.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Embedded JARs&lt;/h3&gt; Once the JSPs were running, I started getting errors about missing libraries that I expected were already in the class path. However, when I checked, I found that those libraries had NOT been included. It used to work, so I kept searching, and it didn't take me long to find them in the WAR file.&lt;br /&gt;&lt;br /&gt;So &lt;em&gt;this&lt;/em&gt; was the reason for the fancy classloader stuff. The classloader was supposed to find these JARs in the WAR file, and include them in its search. Only there was no such class loader in place. Hence my error.&lt;br /&gt;&lt;br /&gt;The Javadoc mentions a class called &lt;code&gt;WebAppClassLoader&lt;/code&gt;, which looked like an obvious candidate. However, the documentation made it appear that this class may not do very much, as it just extended the standard library class &lt;code&gt;URLClassLoader&lt;/code&gt;. All the same, I tried it, but it didn't seem to do anything. (This was my big mistake).&lt;br /&gt;&lt;br /&gt;I finally started adding the sources for all my libraries into my Eclipse environment, so I could debug it and see exactly what was happening. While time-consuming, it finally got me over the line. I also had a nice side benefit of learning just how the architecture of Jetty 6 works.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Deployed At Last&lt;/h3&gt; Tracing through the program, I found that a &lt;code&gt;WebAppContext&lt;/code&gt; calls &lt;code&gt;configureClassLoader&lt;/code&gt; on a &lt;code&gt;WebInfConfiguration&lt;/code&gt; that it creates. This explicitly checks if the class loader is a &lt;code&gt;WebAppClassLoader&lt;/code&gt;, and if it is, then it goes through the lib/ directory of the application, and adds any JAR files that it finds into its classpath.&lt;br /&gt;&lt;br /&gt;Since the configuration is checking for this specific class loader, then this is obviously the only way to do it, unless you write a class loader for yourself. The application never creates one for you, which seems strange. The creation of the object is also strange in that it needs to be provided the web application that it works on (so it knows where to find the classes and libs), and it has to be explicitly set as the class loader for that application. So you need to say something like:&lt;pre&gt;&lt;code&gt;  webapp.setClassLoader(new WebAppClassLoader(webapp));&lt;/code&gt;&lt;/pre&gt;I'm confused why &lt;code&gt;WebAppContext&lt;/code&gt; doesn't create automatically create a &lt;code&gt;WebAppClassLoader&lt;/code&gt; for itself, giving it a &lt;em&gt;this&lt;/em&gt; reference. You can always override it, but it would be rare to need to.&lt;br /&gt;&lt;br /&gt;Anyway, I now knew what to do, and so I did it. Of course, it still didn't work. More debugging. That was when I ran headlong into that class loader code I wrote back at the start of this process. After setting the class loader for the &lt;code&gt;WebAppContext&lt;/code&gt; this code was setting it back to the normal system class loader. That'll teach me for including code blindly.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Threads&lt;/h3&gt; So now everything was running "error free". I decided to throw a web browser at the WebUI application. Only, it wouldn't respond at all. I got a connection to the server, but it just sat there doing nothing.&lt;br /&gt;&lt;br /&gt;Finally, I tried duplicating what I was doing in a short application using a simple servlet. It all looked OK, so I wen through step by step, making sure I had it exactly the same... and it locked up there too. So then I started changing settings one at a time until I found the one that was causing the problem.&lt;br /&gt;&lt;br /&gt;On Jetty 4, two of the options we were setting on the &lt;code&gt;SocketListener&lt;/code&gt; were &lt;em&gt;minThreads&lt;/em&gt; and &lt;em&gt;maxThreads&lt;/em&gt;, however neither of these were options for &lt;code&gt;Connector&lt;/code&gt;. So I decided to make do with &lt;code&gt;AbstractConnector.setAcceptors(int)&lt;/code&gt;, which does a similar thing. However, I made the mistake of setting the number of acceptors to our previous &lt;em&gt;madThreads&lt;/em&gt; value, which was 255.&lt;br /&gt;&lt;br /&gt;If the number of acceptors is set this high, then the server is guaranteed to lock up. So I looked for the threshold at this this occurred. It turned out that the maximum value I could use was 24. It consistently works fine right up to this level, but any more and the system just blocks indefinitely. I checked out the source code, and discovered that all the acceptors are &lt;code&gt;Runnable&lt;/code&gt; objects that get invoked by threads in a thread pool, but there is nothing about the size of that pool or anything else I could see that would create this limit of 24.&lt;br /&gt;&lt;br /&gt;It also doesn't seem to matter what kind of Connector I'm using either, as the Acceptors are always the same.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;A New Servlet&lt;/h3&gt; I'm finally at a point where the system works as well as it did at the beginning of the week, only now it's doing it with Jetty 6. It needed to happen, but I wish it hadn't been so painful.&lt;br /&gt;&lt;br /&gt;I have other things to get to now, but I'll be trying to write this new SPARQL servlet soon. At least I have a modern framework to do it with now.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6848574-6531274686443076623?l=gearon.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://gearon.blogspot.com/2008/07/sparql-perpetual-coding-doesnt-leave.html</link><author>noreply@blogger.com (Quoll)</author><thr:total>0</thr:total></item></channel></rss>

