<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" gd:etag="W/&quot;D0AGR3w6fip7ImA9WxBTE0k.&quot;"><id>tag:blogger.com,1999:blog-6848574</id><updated>2009-12-09T02:02:06.216-06:00</updated><title>Working notes</title><subtitle type="html">Day to day notes on what I'm doing at work</subtitle><link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="http://gearon.blogspot.com/feeds/posts/default" /><link rel="alternate" type="text/html" href="http://gearon.blogspot.com/" /><link rel="hub" href="http://pubsubhubbub.appspot.com/" /><link rel="next" type="application/atom+xml" href="http://www.blogger.com/feeds/6848574/posts/default?start-index=26&amp;max-results=25&amp;redirect=false&amp;v=2" /><author><name>Quoll</name><uri>http://www.blogger.com/profile/03653112583629043593</uri><email>noreply@blogger.com</email></author><generator version="7.00" uri="http://www.blogger.com">Blogger</generator><openSearch:totalResults>379</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/atom+xml" href="http://feeds.feedburner.com/WorkingNotes" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><entry gd:etag="W/&quot;DUAERn07fip7ImA9WxJRGUk.&quot;"><id>tag:blogger.com,1999:blog-6848574.post-3040619251796237722</id><published>2009-05-21T13:15:00.004-05:00</published><updated>2009-05-21T18:15:07.306-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-05-21T18:15:07.306-05:00</app:edited><title /><content type="html">&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;</content><link rel="replies" type="application/atom+xml" href="http://gearon.blogspot.com/feeds/3040619251796237722/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=6848574&amp;postID=3040619251796237722" title="4 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6848574/posts/default/3040619251796237722?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6848574/posts/default/3040619251796237722?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/WorkingNotes/~3/9hUnGlLpCgg/federated-queries-long-time-ago-tks.html" title="" /><author><name>Quoll</name><uri>http://www.blogger.com/profile/03653112583629043593</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="17348260940898309335" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">4</thr:total><feedburner:origLink>http://gearon.blogspot.com/2009/05/federated-queries-long-time-ago-tks.html</feedburner:origLink></entry><entry gd:etag="W/&quot;Ck4DRHo6eSp7ImA9WxVWF0Q.&quot;"><id>tag:blogger.com,1999:blog-6848574.post-1365826457813077288</id><published>2009-02-27T12:37:00.002-06:00</published><updated>2009-02-27T21:16:15.411-06:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-02-27T21:16:15.411-06:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="OWL" /><category scheme="http://www.blogger.com/atom/ns#" term="integration" /><category scheme="http://www.blogger.com/atom/ns#" term="RLog" /><category scheme="http://www.blogger.com/atom/ns#" term="description logic" /><category scheme="http://www.blogger.com/atom/ns#" term="SKOS" /><category scheme="http://www.blogger.com/atom/ns#" term="RDF" /><category scheme="http://www.blogger.com/atom/ns#" term="Mulgara" /><category scheme="http://www.blogger.com/atom/ns#" term="logic" /><title /><content type="html">&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;</content><link rel="replies" type="application/atom+xml" href="http://gearon.blogspot.com/feeds/1365826457813077288/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=6848574&amp;postID=1365826457813077288" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6848574/posts/default/1365826457813077288?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6848574/posts/default/1365826457813077288?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/WorkingNotes/~3/N1yfw1IdXCI/more-programmable-logic-in-last-post-i.html" title="" /><author><name>Quoll</name><uri>http://www.blogger.com/profile/03653112583629043593</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="17348260940898309335" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://gearon.blogspot.com/2009/02/more-programmable-logic-in-last-post-i.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A08GQnc9eCp7ImA9WxVWF0g.&quot;"><id>tag:blogger.com,1999:blog-6848574.post-2523761822983983225</id><published>2009-02-27T10:46:00.003-06:00</published><updated>2009-02-27T12:37:03.960-06:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-02-27T12:37:03.960-06:00</app:edited><title /><content type="html">&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;</content><link rel="replies" type="application/atom+xml" href="http://gearon.blogspot.com/feeds/2523761822983983225/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=6848574&amp;postID=2523761822983983225" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6848574/posts/default/2523761822983983225?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6848574/posts/default/2523761822983983225?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/WorkingNotes/~3/UBM79lt0xHA/programmable-logic-i-had-hoped-to-blog.html" title="" /><author><name>Quoll</name><uri>http://www.blogger.com/profile/03653112583629043593</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="17348260940898309335" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://gearon.blogspot.com/2009/02/programmable-logic-i-had-hoped-to-blog.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEcGSXk4eCp7ImA9WxVWEE8.&quot;"><id>tag:blogger.com,1999:blog-6848574.post-7513571316750121818</id><published>2009-02-19T00:34:00.002-06:00</published><updated>2009-02-19T00:47:08.730-06:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-02-19T00:47:08.730-06:00</app:edited><title /><content type="html">&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;</content><link rel="replies" type="application/atom+xml" href="http://gearon.blogspot.com/feeds/7513571316750121818/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=6848574&amp;postID=7513571316750121818" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6848574/posts/default/7513571316750121818?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6848574/posts/default/7513571316750121818?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/WorkingNotes/~3/gbYQuz2dS9s/is-it-me-after-struggling-against.html" title="" /><author><name>Quoll</name><uri>http://www.blogger.com/profile/03653112583629043593</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="17348260940898309335" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">2</thr:total><feedburner:origLink>http://gearon.blogspot.com/2009/02/is-it-me-after-struggling-against.html</feedburner:origLink></entry><entry gd:etag="W/&quot;AkICSX0zeSp7ImA9WxVXGEg.&quot;"><id>tag:blogger.com,1999:blog-6848574.post-6773794379073821893</id><published>2009-02-17T00:48:00.003-06:00</published><updated>2009-02-17T02:16:08.381-06:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-02-17T02:16:08.381-06:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="REST" /><category scheme="http://www.blogger.com/atom/ns#" term="RDF" /><title /><content type="html">&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;</content><link rel="replies" type="application/atom+xml" href="http://gearon.blogspot.com/feeds/6773794379073821893/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=6848574&amp;postID=6773794379073821893" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6848574/posts/default/6773794379073821893?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6848574/posts/default/6773794379073821893?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/WorkingNotes/~3/saCfv6-8fHc/resting-ive-had-couple-of-drinks-this.html" title="" /><author><name>Quoll</name><uri>http://www.blogger.com/profile/03653112583629043593</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="17348260940898309335" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://gearon.blogspot.com/2009/02/resting-ive-had-couple-of-drinks-this.html</feedburner:origLink></entry><entry gd:etag="W/&quot;AkIAQXs6fSp7ImA9WxVXFUk.&quot;"><id>tag:blogger.com,1999:blog-6848574.post-8431227637282433975</id><published>2009-02-13T09:02:00.003-06:00</published><updated>2009-02-13T12:09:00.515-06:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-02-13T12:09:00.515-06:00</app:edited><title /><content type="html">&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;</content><link rel="replies" type="application/atom+xml" href="http://gearon.blogspot.com/feeds/8431227637282433975/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=6848574&amp;postID=8431227637282433975" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6848574/posts/default/8431227637282433975?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6848574/posts/default/8431227637282433975?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/WorkingNotes/~3/vBs6BQHc9NQ/prodding-going-back-through-recent.html" title="" /><author><name>Quoll</name><uri>http://www.blogger.com/profile/03653112583629043593</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="17348260940898309335" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://gearon.blogspot.com/2009/02/prodding-going-back-through-recent.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0ANQnc5eSp7ImA9WxRbEkU.&quot;"><id>tag:blogger.com,1999:blog-6848574.post-4698312072094959141</id><published>2008-12-02T22:29:00.002-06:00</published><updated>2008-12-02T23:23:13.921-06:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-12-02T23:23:13.921-06:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="indexing" /><title /><content type="html">&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;</content><link rel="replies" type="application/atom+xml" href="http://gearon.blogspot.com/feeds/4698312072094959141/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=6848574&amp;postID=4698312072094959141" title="4 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6848574/posts/default/4698312072094959141?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6848574/posts/default/4698312072094959141?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/WorkingNotes/~3/mlyGBMD2hzY/dropping-indexes-one-of-optimizations.html" title="" /><author><name>Quoll</name><uri>http://www.blogger.com/profile/03653112583629043593</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="17348260940898309335" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">4</thr:total><feedburner:origLink>http://gearon.blogspot.com/2008/12/dropping-indexes-one-of-optimizations.html</feedburner:origLink></entry><entry gd:etag="W/&quot;AkIMQ307eyp7ImA9WxRbEko.&quot;"><id>tag:blogger.com,1999:blog-6848574.post-1789534819774988294</id><published>2008-12-02T22:20:00.002-06:00</published><updated>2008-12-02T22:29:42.303-06:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-12-02T22:29:42.303-06:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="performance" /><category scheme="http://www.blogger.com/atom/ns#" term="disk" /><category scheme="http://www.blogger.com/atom/ns#" term="Graphs" /><title /><content type="html">&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;</content><link rel="replies" type="application/atom+xml" href="http://gearon.blogspot.com/feeds/1789534819774988294/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=6848574&amp;postID=1789534819774988294" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6848574/posts/default/1789534819774988294?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6848574/posts/default/1789534819774988294?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/WorkingNotes/~3/8TwK4djq0yk/size-disk-usage-is-probably-second-most.html" title="" /><author><name>Quoll</name><uri>http://www.blogger.com/profile/03653112583629043593</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="17348260940898309335" /></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 xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://gearon.blogspot.com/2008/12/size-disk-usage-is-probably-second-most.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DUcFSXk9eSp7ImA9WxRbEUg.&quot;"><id>tag:blogger.com,1999:blog-6848574.post-644599254200113973</id><published>2008-12-01T09:36:00.005-06:00</published><updated>2008-12-01T12:43:38.761-06:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-12-01T12:43:38.761-06:00</app:edited><title /><content type="html">&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;</content><link rel="replies" type="application/atom+xml" href="http://gearon.blogspot.com/feeds/644599254200113973/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=6848574&amp;postID=644599254200113973" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6848574/posts/default/644599254200113973?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6848574/posts/default/644599254200113973?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/WorkingNotes/~3/4buOcqBvKXA/mulgara-stats-one-question-everyone.html" title="" /><author><name>Quoll</name><uri>http://www.blogger.com/profile/03653112583629043593</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="17348260940898309335" /></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 xmlns:thr="http://purl.org/syndication/thread/1.0">2</thr:total><feedburner:origLink>http://gearon.blogspot.com/2008/12/mulgara-stats-one-question-everyone.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A0IDSX08cCp7ImA9WxRXEk0.&quot;"><id>tag:blogger.com,1999:blog-6848574.post-6135747305180855637</id><published>2008-09-18T22:57:00.004-05:00</published><updated>2008-10-16T21:12:58.378-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-10-16T21:12:58.378-05:00</app:edited><title /><content type="html">&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;</content><link rel="replies" type="application/atom+xml" href="http://gearon.blogspot.com/feeds/6135747305180855637/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=6848574&amp;postID=6135747305180855637" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6848574/posts/default/6135747305180855637?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6848574/posts/default/6135747305180855637?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/WorkingNotes/~3/uBmU3tLVZO4/disclaimer-new-babies-are-wonderful-but.html" title="" /><author><name>Quoll</name><uri>http://www.blogger.com/profile/03653112583629043593</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="17348260940898309335" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://gearon.blogspot.com/2008/09/disclaimer-new-babies-are-wonderful-but.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0UNRXk6eSp7ImA9WxdUFUk.&quot;"><id>tag:blogger.com,1999:blog-6848574.post-6531274686443076623</id><published>2008-07-31T15:32:00.003-05:00</published><updated>2008-07-31T18:01:34.711-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-07-31T18:01:34.711-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="classpath" /><category scheme="http://www.blogger.com/atom/ns#" term="JAR" /><category scheme="http://www.blogger.com/atom/ns#" term="WAR" /><category scheme="http://www.blogger.com/atom/ns#" term="Jetty" /><category scheme="http://www.blogger.com/atom/ns#" term="Mulgara" /><category scheme="http://www.blogger.com/atom/ns#" term="class path" /><title /><content type="html">&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;</content><link rel="replies" type="application/atom+xml" href="http://gearon.blogspot.com/feeds/6531274686443076623/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=6848574&amp;postID=6531274686443076623" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6848574/posts/default/6531274686443076623?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6848574/posts/default/6531274686443076623?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/WorkingNotes/~3/X4AU0BmcRck/sparql-perpetual-coding-doesnt-leave.html" title="" /><author><name>Quoll</name><uri>http://www.blogger.com/profile/03653112583629043593</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="17348260940898309335" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://gearon.blogspot.com/2008/07/sparql-perpetual-coding-doesnt-leave.html</feedburner:origLink></entry><entry gd:etag="W/&quot;AkcFQH0zeSp7ImA9WxdQF0s.&quot;"><id>tag:blogger.com,1999:blog-6848574.post-4089886937172218415</id><published>2008-06-18T00:32:00.002-05:00</published><updated>2008-06-18T00:46:51.381-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-06-18T00:46:51.381-05:00</app:edited><title /><content type="html">&lt;h3&gt;TV&lt;/h3&gt; Know what would make the &lt;a href="http://www.apple.com/appletv/"&gt;Apple TV&lt;/a&gt; a no-brainer for me? Allow it to &lt;a href="http://docs.info.apple.com/article.html?artnum=307319"&gt;share a DVD&lt;/a&gt; from your desktop machine, like the MacBookAir can, and start include BluRay as a shareable disc type.&lt;br /&gt;&lt;br /&gt;But no. I bet that interferes with a business model somewhere. :-(&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6848574-4089886937172218415?l=gearon.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://gearon.blogspot.com/feeds/4089886937172218415/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=6848574&amp;postID=4089886937172218415" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6848574/posts/default/4089886937172218415?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6848574/posts/default/4089886937172218415?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/WorkingNotes/~3/gHbxEFuBfxc/tv-know-what-would-make-apple-tv-no.html" title="" /><author><name>Quoll</name><uri>http://www.blogger.com/profile/03653112583629043593</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="17348260940898309335" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://gearon.blogspot.com/2008/06/tv-know-what-would-make-apple-tv-no.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkQEQH87fyp7ImA9WxdQEUs.&quot;"><id>tag:blogger.com,1999:blog-6848574.post-3606862386089652557</id><published>2008-06-10T23:03:00.002-05:00</published><updated>2008-06-10T23:58:21.107-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-06-10T23:58:21.107-05:00</app:edited><title /><content type="html">&lt;h3&gt;Thesis&lt;/h3&gt; I've finally started writing my thesis, so don't expect to see me blog much in the near term. I know I haven't been blogging much at all this year, but I'm guessing I'm about to get worse (or who knows? Maybe I'll procrastinate and blog more).&lt;br /&gt;&lt;br /&gt;I'm still in the introductory chapters, so I'm reviewing everyone else's work. I have a stack of references from a few years ago, but need to update some of it, and finally read some of the papers I put off all that time ago.&lt;br /&gt;&lt;br /&gt;One of the really startling things is reading about stuff that I had to discover for myself while implementing Mulgara. As a database developer you just do things because they seem pragmatic, and you figure that &lt;em&gt;everyone&lt;/em&gt; must do it that way. Then you read a paper where someone formalizes your assumptions and gives a name to it. I can think of several here, but the first that comes to mind is "DL-safe rules".&lt;br /&gt;&lt;br /&gt;DL-safe rules are simply rules where the variables in the head must also occur in the body. Well, building rules for OWL that meet this criteria seems obvious to me, but apparently it merited a &lt;a href="http://pellet.owldl.org/papers/kolovski06extending.pdf"&gt;couple&lt;/a&gt; of &lt;a href="http://www.comlab.ox.ac.uk/people/boris.motik/pubs/mss05query-journal.pdf"&gt;papers&lt;/a&gt; on the topic. For a start, I'm not sure how you'd even do this without making sure your variables in the head all come from the body. Second, the only way this would work (that I know of) is to start introducing blank nodes for existential statements.... and that way lies madness.&lt;br /&gt;&lt;br /&gt;For instance, if you define (somewhat informally):&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;#x2200;x &amp;#x2208; Man &amp;#x2192; &amp;#x2203;y : Man(y) &amp;#x22c0; father(y,x)&lt;br /&gt;&lt;br /&gt;Then simply by saying &lt;em&gt;Man(fred)&lt;/em&gt; you have an infinite loop. Incidentally, this is a trivial demonstration of how hard it can be to model the real world. The simple solution is to somehow incorporate a new type, like &lt;em&gt;Men-without-fathers&lt;/em&gt;, and put that in your rule (hmmm, doesn't the DL-Handbook mention something like that?). Whether you introduce an entity named &lt;em&gt;adam&lt;/em&gt; or somehow model evolution (good luck there) is up to you.&lt;br /&gt;&lt;br /&gt;Back to the example... Of course, in OWL you can just create a blank node for an unknown father, but if you're going to take it that far then you want to create a blank node for the father of the first blank node, etc. Maybe it's reasonable to simple create that first step, and not reason further on blank nodes, but now you're making a judgment call that:&lt;br /&gt;a) May not prove to be as useful as you'd envisaged.&lt;br /&gt;b) May have implications for your logic.&lt;br /&gt;&lt;br /&gt;Besides, what's the point in inferring a new node that you can't perform further inferences on? You'd just have a node there not saying anything except that it's a "father". But if you want to include it in a rule for determining &lt;em&gt;ancestor(x,y)&lt;/em&gt;, then suddenly it can be re-inferred on again, and you run the risk of an infinite loop once more.&lt;br /&gt;&lt;br /&gt;So DL-rules just make sense in OWL (at least, they do to me). It's strange to see people like Boris Motik take them so seriously.&lt;br /&gt;&lt;br /&gt;Speaking of Boris, he basically wrote the thesis I was hoping to write (well, sort of - fortunately I have a &lt;em&gt;few&lt;/em&gt; ideas of my own). I came to many of the same conclusions that he has, simply by virtue of implementing stuff for Mulgara (though by virtue of having another child, moving countries, interrupting my candidature, and holding down a full time job, I didn't publish anything in time). The difference between what I would have written and what Boris &lt;em&gt;did&lt;/em&gt; write, is that he knows the theory &lt;em&gt;way&lt;/em&gt; better than I'm every going to have the time for. I mean, I can follow it all, but it would never have occurred to me to give such algebraic formalism to everything the way he did. It's a little humbling to see someone do something like that so much better than you would have done.&lt;br /&gt;&lt;br /&gt;Oh well. I guess I'd better stop procrastinating and write some more.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6848574-3606862386089652557?l=gearon.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://gearon.blogspot.com/feeds/3606862386089652557/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=6848574&amp;postID=3606862386089652557" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6848574/posts/default/3606862386089652557?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6848574/posts/default/3606862386089652557?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/WorkingNotes/~3/HjnhAsIU0hM/thesis-ive-finally-started-writing-my.html" title="" /><author><name>Quoll</name><uri>http://www.blogger.com/profile/03653112583629043593</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="17348260940898309335" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://gearon.blogspot.com/2008/06/thesis-ive-finally-started-writing-my.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0MDRXwyeCp7ImA9WxdSGEs.&quot;"><id>tag:blogger.com,1999:blog-6848574.post-77846031883464424</id><published>2008-05-26T22:02:00.005-05:00</published><updated>2008-05-26T23:11:14.290-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-05-26T23:11:14.290-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="SPARQL" /><category scheme="http://www.blogger.com/atom/ns#" term="Mulgara" /><title /><content type="html">&lt;h3&gt;Mulgara Alpha&lt;/h3&gt; My last few weeks were spent trying to get Mulgara's &lt;a href="http://en.wikipedia.org/wiki/SPARQL" title="SPARQL" rel="wikipedia" target="_blank" class="zem_slink"&gt;SPARQL&lt;/a&gt; interfaces ready before the &lt;a href="http://www.semantic-conference.com/"&gt;Semantic Technology Conference 2008&lt;/a&gt;. I met the criteria Amit (from &lt;a href="http://www.topazproject.org/"&gt;Topaz&lt;/a&gt;) and I had agreed to beforehand, which allowed me to get out an &lt;a href="http://mulgara.org/news.html#date150508"&gt;Alpha release&lt;/a&gt; for the next version of Mulgara. There are still a couple of things missing, but the basics are all there now.&lt;br /&gt;&lt;br /&gt;The road to SPARQL took a couple of turns I hadn't expected.&lt;br /&gt;&lt;br /&gt;Back in February we were approached by &lt;a href="http://www.aduna-software.com/"&gt;Aduna&lt;/a&gt; who asked if we would be willing to support a level of integration between &lt;a href="http://www.openrdf.org/"&gt;Sesame&lt;/a&gt; and Mulgara. While none of the Mulgara developers had the time to work with them directly, we said that we would be very happy to try to support Aduna where we could. The majority of this work was done by &lt;a href="http://leighnet.ca/"&gt;James Leigh&lt;/a&gt; (a programmer who commands my respect more and more on a daily basis), and he was able to get it all done in remarkable time. Even more impressive was that his integration work is 100% SPARQL compliant, even though some of the underlying structure isn't quite there yet!&lt;br /&gt;&lt;br /&gt;My own work was to:&lt;ul&gt;&lt;li&gt;Parse SPARQL queries.&lt;/li&gt;&lt;li&gt;Convert this into the Mulgara Algebra.&lt;/li&gt;&lt;li&gt;Write new algebraic operations in the Mulgara query engine.&lt;/li&gt;&lt;/ul&gt;The work by Aduna was going to overcome the need for the first and second tasks, but I had already completed the first when we heard from Aduna, with most of the work left to be done required for both the &lt;a href="http://www.openrdf.org/doc/sesame/api/org/openrdf/sesame/sail/package-summary.html"&gt;SAIL&lt;/a&gt; interface and my own SPARQL implementation. Since this was the case, I decided to continue with my own interface, since there wasn't going to be much redundant work from that point onwards. Even with both interfaces working correctly, the SAIL API will be the one to use, as it also includes a SPARQL Protocol endpoint, which I haven't looked at yet.&lt;br /&gt;&lt;br /&gt;While the SAIL integration may have appeared to be independent from my own work, it turned out that James's contribution was invaluable. His need to pass all the SPARQL tests drove a lot of my query engine work, pointing out both missing features and bugs I was unaware of. I still have a couple of things to go, but James has been able to work around them at the higher layers for the time being. This has a performance penalty, but these will be dealt with in the next couple of weeks.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Notable Feature Implementations&lt;/h3&gt; &lt;h4&gt;Language Tags&lt;/h4&gt; One missing feature that completely floored me was that Mulgara was not supporting language tags on untyped literals. It turns out that this was slated for addition just as Tucana was closed, which is why it never made it. Even so, I must admit that I was surprised that it took that long for this feature to be scheduled!&lt;br /&gt;&lt;br /&gt;Fortunately, language tags were quick and easy to implement. The main issue was in the existing tests, as nearly half of our files use literals with language tags in them, and none of the "expected results" included them.&lt;br /&gt;&lt;br /&gt;&lt;h4&gt;Repeating Variables&lt;/h4&gt; Another issue was in "basic graph patterns" that use a repeating variable. Mulgara already had some code to deal with this, but it was failing in most cases. Unfortunately, I responded to this as a "bug report", and fell into the trap of fixing the existing code. I got it working after a day, only to be told the next day that it still failed if the variable is repeated in the position of the graph name.&lt;br /&gt;&lt;br /&gt;At that point I stepped back from the problem, and realized that the solution was actually quite easy. All you need do is replace the repeating variable with a set of unique names, and create a conjunction of the constraint repeated with the variables in rotating positions. After mentioning this to Andrae he informed me that he'd worked this out a few years before (even though someone else was implementing the code at the time), but he forgot to let me know. Oh well, at least I'm doing it correctly now.&lt;br /&gt;&lt;br /&gt;While looking to implement this fix, I realized that the best way to perform this substitution would be via Andrae's query transformation SPI. This lets you search through a query structure, and replace elements with something more appropriate for the engine to work with. It was while working with this I realized that it provides me with a tool that will let me solve a problem I've had for some time.&lt;br /&gt;&lt;br /&gt;&lt;h4&gt;Transitive&lt;/h4&gt; The &lt;em&gt;trans&lt;/em&gt; feature in Mulgara is a mechanism that lets the user mark the predicate in a constraint as &lt;em&gt;transitive&lt;/em&gt;. While it works really well, the syntax in TQL is ugly. However, the query transformer offers an alternative. Instead of wrapping a standard constraint in a &lt;em&gt;trans(...)&lt;/em&gt; operator, the predicate can be typed as being &lt;em&gt;transitive&lt;/em&gt; in a separate constraint. I was tempted to use the URI of &lt;code&gt;owl:TransitivePredicate&lt;/code&gt; for this task, but this will interfere with declarations in ontologies, so a local URI will be much more appropriate (something like &lt;code&gt;mulgara:TransitivePredicate&lt;/code&gt;). The &lt;em&gt;really&lt;/em&gt; cool thing is that this will be sharable with SPARQL queries as well. That means we can start opening some of our functionality up to SPARQL users, while not needing to extend the syntax of that language. In fact, there are a few functions we can implement in this way, allowing us to do a lot in SPARQL without sacrificing the speed and functionality of TQL.&lt;br /&gt;&lt;br /&gt;&lt;h4&gt;Date Times&lt;/h4&gt; One question I regularly received from James was about date times. Unfortunately, Mulgara stores these canonically (using UTC), and hence does not round-trip these values. The solution is to store the timezone offset along with the value. Another tricky thing is to record if a time of "midnight" is recorded as "00:00:00" or as "24:00:00", as both are valid, and both need to be returned as they were provided, and not in a normalized form. I haven't done this one yet, but I expect to get it done by the end of the week.&lt;br /&gt;&lt;br /&gt;I had a comment from Andy Seaborne that despite timezones being described in hours and minutes, this only requires a resolution of quarter-hour intervals, so I can probably squeeze this into some existing storage somewhere. I appreciate the advice, but it leaves me wondering which timezone appears with a 15 minute offset from its nearest neighbors!&lt;br /&gt;&lt;br /&gt;In the meantime, James got around the problem by removing the &lt;code&gt;xsd:dateTime&lt;/code&gt; specific code from the version of Mulgara he is working with, so it gets treated as an unknown type. This modification can be removed as soon as I fix the issue (which I expect to be by the end of this week).&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Memorial Day&lt;/h3&gt; There is still an enormous amount of information to cover on Mulgara, SPARQL, and especially the SemTech conference, but I'm falling asleep as I type. It's currently Memorial Day here in the USA, and since getting back from the conference on Friday night, I've had a huge weekend with my family. Yesterday I took both of the boys in a trailer for "&lt;a href="http://www.bikethedrive.org/"&gt;Bike the Drive&lt;/a&gt;", which is a lot more cycling than I've done for a few months. Swimming and running have kept me relatively fit, but it still tired me out! Consequently I just can't think now, so I'll pick this up again later.&lt;div class="zemanta-pixie" style="margin: 5px 0pt; width: 100%;"&gt;&lt;a class="zemanta-pixie-a" href="http://www.zemanta.com/" title="Zemified by Zemanta"&gt;&lt;img class="zemanta-pixie-img" src="http://img.zemanta.com/pixie.png?x-id=d609d394-58ad-44ee-a3eb-a6d4d7e94e85" style="border: medium none ; float: right;"&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6848574-77846031883464424?l=gearon.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://gearon.blogspot.com/feeds/77846031883464424/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=6848574&amp;postID=77846031883464424" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6848574/posts/default/77846031883464424?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6848574/posts/default/77846031883464424?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/WorkingNotes/~3/7WFpXyVEIyo/mulgara-alpha-my-last-few-weeks-were.html" title="" /><author><name>Quoll</name><uri>http://www.blogger.com/profile/03653112583629043593</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="17348260940898309335" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://gearon.blogspot.com/2008/05/mulgara-alpha-my-last-few-weeks-were.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A0YBRHw5fCp7ImA9WxZbEU4.&quot;"><id>tag:blogger.com,1999:blog-6848574.post-6102132533686860203</id><published>2008-04-13T14:01:00.002-05:00</published><updated>2008-04-13T21:12:35.224-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-04-13T21:12:35.224-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="indexing" /><category scheme="http://www.blogger.com/atom/ns#" term="XA2" /><category scheme="http://www.blogger.com/atom/ns#" term="RDF" /><title /><content type="html">&lt;h3&gt;Writing 2-columns&lt;/h3&gt; In my last post I described a scheme for representing 2 columns. But the moment I first thought of it, I decided it was too impractical. After all, each "triple" gets represented with 10 entries. If I want to include a graph identifier (i.e. a Quad store) then it goes up to 12 entries. If I want to cut down on disk seeking, then the idea seemed to be of little more than academic interest.&lt;br /&gt;&lt;br /&gt;Then a little while ago I was explaining this scheme to a friend (Inderbir), and in the process I tried to explain why this was going to be impractical, but in the course of the discussion a few things occurred to me.&lt;br /&gt;&lt;br /&gt;The statements to represent form a series of "doubles", which need to be indexed two ways: by each column. The data for a single statement will appear like this:&lt;pre&gt;&lt;code&gt;  Statement, _statement_x&lt;br /&gt;  SubjectIdentifier, _subject_x&lt;br /&gt;  PredicateIdentifier, _predicate_x&lt;br /&gt;  ObjectIdentifier, _object_x&lt;br /&gt;  _statement_x, _subject_x&lt;br /&gt;  _statement_x, _predicate_x&lt;br /&gt;  _statement_x, _object_x&lt;br /&gt;  _subject_x, my:subject&lt;br /&gt;  _predicate_x, my:predicate&lt;br /&gt;  _object_x, my:object&lt;/code&gt;&lt;/pre&gt;Where anything whose name starts with an underscore is a unique identifier. As I'd already mentioned, now that we use 64 bit identifiers in Mulgara, it makes sense to create these from an incrementing &lt;code&gt;long&lt;/code&gt; value.&lt;br /&gt;&lt;br /&gt;Given that each identifier only gets used for one statement, then the statement, subject, predicate, and object identifiers will all be allocated together, and will be consecutive. Indeed, if these identifiers are kept separate from the identifiers that will be allocated for the URIs and Literals of the statement, then the statement can be presumed to always be a multiple of 4, and the subject, predicate, and object identifiers will be 1, 2, and 3 greater, respectively. This means that the bottom two bits of the IDs can be used to represent the type of the ID, meaning that the first 4 statements in the above list can be inferred, rather than stored. Also, since the IDs for the subject, predicate, and object positions can be calculated by adding 1, 2, or 3, then the next three statements don't need to be stored either. Cutting the data down to 3 entries suddenly makes it look more interesting.&lt;br /&gt;&lt;br /&gt;I should note at this point that I still expect to represent URIs and Literals with IDs that can be mapped to or from the data they represent. While the mechanism for doing this in Mulgara needs to be improved, it is still an important concept, as it reduces redundant storage of strings, and the comparison of Long values allows for faster joins. However, I do intend to return to this idea.&lt;br /&gt;&lt;br /&gt;After reducing the data to be stored, we now have:&lt;pre&gt;&lt;code&gt;  _subject_x, my:subject&lt;br /&gt;  _predicate_x, my:predicate&lt;br /&gt;  _object_x, my:object&lt;/code&gt;&lt;/pre&gt;Indeed, since each of those IDs are consecutive, and always increasing, then in the index that is sorted by the first column, all three statements will go to the end of the file. This means that the file need not ever have a seek operation performed on it while it is being written to. Operating systems are usually optimized for append-only writing, so this is another bonus.&lt;br /&gt;&lt;br /&gt;It is also worth noting that since the predicates are always consecutive, there is no need to write each of them either. Instead, the following can be written for each statement:&lt;pre&gt;&lt;code&gt;  _statement_x, my:subject, my:predicate, my:object&lt;/code&gt;&lt;/pre&gt;With this data, all of the above can be inferred. Indeed, the need for the statement to take up an ID on it's own can be dropped, and the subject, predicate, and object IDs are calculated by adding 0, 1, and 2 to the first ID. This leaves space for a fourth element, such as a graph identifier, before needing more than 2 of the low-order bits to give the type of the identifier.&lt;br /&gt;&lt;br /&gt;On the other file, we will be storing the same data in reverse order:&lt;pre&gt;&lt;code&gt;  my:subject, _subject_x&lt;br /&gt;  my:predicate, _predicate_x&lt;br /&gt;  my:object, _object_x&lt;/code&gt;&lt;/pre&gt;In this case, the identifiers for the URIs, blank nodes, and literals of the subject, predicate and object will be all over the place (and will be regularly re-used), so there is no guarantee of ordering here. This means we have to go back to standard tree-based indexing of the data. However, we only have 3 search operations to go through here, which is significantly better than the searching we currently do in Mulgara.&lt;br /&gt;&lt;br /&gt;Note that all of the above applies to statements with more than 3 elements as well. Each new element in a statement increases the size of the single write on the first index by one more &lt;code&gt;long&lt;/code&gt; value, and adds one more seek/write operation to the second index. This is far less expensive than expanding the size of the "complete" indexes used in Mulgara.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Retrieving&lt;/h3&gt; I'll stop for a moment, and take a look at what a read operation looks like.&lt;br /&gt;&lt;br /&gt;The first index file is written to linearly. Each record is identical in size, and the ID that starts the record is monotonically increasing. If the store were write-once-read-many (WORM), then the ID could be skipped altogether as this information would be inferred from the offset within the file. This may be useful for some applications, but I'd prefer to delete information in place (rather than creating a white-out list for later merging), meaning that the ID is still required in this case.&lt;br /&gt;&lt;br /&gt;For this kind of structure, the file can be searched using a binary search. Also, the largest offset that an ID can appear at is the value of that ID multiplied by the size of a record, meaning that the number of seeks required for a search can be greatly reduced.&lt;br /&gt;&lt;br /&gt;The second index is a standard tree. B-Trees are well known for not seeking much, so for a first cut, I would suggest this (though Andrae have other plans further down the line).&lt;br /&gt;&lt;br /&gt;To find all statements that match one element (say, the predicate), then this requires a search on the tree-index, to find the first time that URI appears. The associated predicate ID is paired with a set of IDs that represent the use of that URI in statements (sometimes as predicate, sometimes as subject or object). These IDs are in consecutive order, and so can be merged with the first index as a linear operation. Adding in another element to search by (say, we are looking for a given predicate/object pair) then this becomes another search on the second index, and another linear merge.&lt;br /&gt;&lt;br /&gt;Linear merges aren't too bad here, as it is always a linear operation to go through all of the data anyway (meaning that it can't be avoided). The only case where this is an unnecessary expense is if the "count" of a set of statements is required.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Efficiency in the Tree&lt;/h3&gt; While considering the above structure, it occurred to me that this index is having to store identifiers for the RDF nodes over and over, even though they all appear next to one another. There are ways of compressing this, but it made me question the redundancy altogether. What if the item was just stored once, and the "satellite data" (to use the term for data associated with key) was instead it's own structure? I thought that maybe this could be a tree, but then it occurred to me that the data represents statement IDs, and will therefore always be inserted in increasing order. So a list is most appropriate.&lt;br /&gt;&lt;br /&gt;So now I could have each entry in this tree point to a list of statements that this RDF node participates in. Since the list will always be appended to, it makes sense that this is kept in another file, using a linked list of blocks. However, to cut down on seeks, the first few elements of the list would do well to appear with the node in the original tree.&lt;br /&gt;&lt;br /&gt;So what sort of satellite data should be stored? For reading, the head of the list has to be stored, though as just mentioned, I think that this should be inline with the satellite data. The tail of the list should also be stored, else it would require a linear seek to work out where to insert, and this is not scalable. To give some help with management of the list, the size should also be recorded. This also makes counting trivial.&lt;br /&gt;&lt;br /&gt;Up until now there has been a presumption that the identifiers of elements in a statement follow a particular bit pattern. However, if the satellite data contains three lists instead of one, then the number of the list is enough to indicate which position the node is used in. For instance, the node of &lt;code&gt;&amp;lt;rdf:type&amp;gt;&lt;/code&gt; may have a few entries in the list for &lt;em&gt;subject&lt;/em&gt; (indicating that it is the "subject" in just a few statements), may have a few entries in the &lt;em&gt;object&lt;/em&gt; list (indicating that there are a few statements which refer to this URI), but will have millions (or more) statements in the &lt;em&gt;predicate&lt;/em&gt; list, because this URI indicates a commonly used predicate.&lt;br /&gt;&lt;br /&gt;If the presence of a statement ID in one list or another indicates that this node is used in a particular capacity for that statement, then this means that the presumption of using the low order bits of the ID for this purpose is removed. That gives us a little more flexibility.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Data Pool&lt;/h3&gt; All of the above presumes that there exists a mechanism to map URIs, strings, and other literal data on to an ID, and to map those IDs back into the original data. Historically, Mulgara has referred to the the store that performed this operation as the "String Pool". Since URIs are encoded as a string, and the first iteration of Mulgara only stored literals in a lexical form, this name was accurate. However, with the inclusion of numbers, dates, and other datatypes, it might be more accurate to refer to this construct as a "Data Pool" instead.&lt;br /&gt;&lt;br /&gt;Part of the data pool structure of Mulgara uses a tree containing some (or all) of the data as a key, and a long value as the ID it is mapped to. Storing entries that are keyed on strings or other data is a lot like the second index just mentioned. So now I started to reconsider the presumption of a separate data pool altogether.&lt;br /&gt;&lt;br /&gt;Instead of writing to the linear file first, the idea is to write to the tree index first. This involves a search. If the data is found, then the statement ID will be appended to the end of the appropriate list (this updates the linked list block, possibly spilling over into a new block, and then rewrites the tail/size of this list in the tree). If the data is &lt;strong&gt;not&lt;/strong&gt; found, then a new entry is placed in the tree, two lists are initialized to nil, and the third is given the allocated statement ID. The list is not yet long enough to spill into the file full of linked lists, so this isn't too expensive. For a B-Tree with space, this will require writing of just a single block!&lt;br /&gt;&lt;br /&gt;Now it isn't feasible to store &lt;em&gt;everything&lt;/em&gt; in the tree as a key, so only the head of the data would need to go directly into the tree. The remainder of the data is still needed, but rather than trying to manage this data re-usably, the ideas from last post about keeping all the data in the pool can be adopted. In this case the data can simply be appended to a third file. The offset of this append then becomes the ID of that data. This ID is stored along with the rest of the satellite data in the tree. It is also the ID that gets stored in the first linear index file which can now be written to.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;More Efficiency&lt;/h3&gt; So now instead of a "Data Pool" and 2 files, the design is now for 4 files. Two of them are only ever appended to, one always has direct seeks before writing, and only one of them is a tree that requires searching before a write can happen. Given that this is the entire store, then that's not too shabby! It's a darn sight better than the 196 files in Mulgara, almost all of which need multiple seeks to do &lt;em&gt;anything&lt;/em&gt;.&lt;br /&gt;&lt;br /&gt;But can I do better?&lt;br /&gt;&lt;br /&gt;Andrae had already been looking at reworking the string/data pool, and a lot of things are quite obvious to do. For a start, any data that can fit into 54 bits (or so) ought to have its value encoded into its ID, with the top bits used for type identification. That many bits lets you encode all bytes, chars, shorts, ints and floats, as well as the majority of long values (and possibly a lot of doubles as well). Any date within a century of now will also fit in. This means that many items that are not strings don't need any extra storage. So along with the type bits, there would be another bit to indicate whether or not the data is encoded in the ID, or if it is found in the data file. Anything that can be encoded into the ID won't have to go into the data file, though it would still go into the indexes so statements using it can still be found. The main difference is that any statements discovered to contain one of these IDs would not require the extra seek to get the remaining information.&lt;br /&gt;&lt;br /&gt;Another significant change has already been proposed by Andrae over a year ago. In this case, the different types of the data will be stored in different indexes, which are each optimized to handle such data. This increases the number of files, but only one of these files will be accessed at a time. Also, since each of these types are literals, there is no need for lists describing &lt;em&gt;subject&lt;/em&gt; or &lt;em&gt;predicate&lt;/em&gt; statements.&lt;br /&gt;&lt;br /&gt;Similarly, blank nodes will have their own file, only they will not require any extra data beyond the lists, and no predicate list will be required.&lt;br /&gt;&lt;br /&gt;Getting back to the fundamental types of strings and URIs, Andrae pointed out that &lt;a href="http://en.wikipedia.org/wiki/Trie"&gt;Tries&lt;/a&gt; are an appropriate structure for reducing space requirements. This is perfect for managing the plethora of URIs that appear in the same namespace (or that just start with "http://"), as common prefixes to strings are not repeated in this structure. Like other tree structures, this would let us store arbitrary satellite data, meaning they are perfectly adaptable to this structure.&lt;br /&gt;&lt;br /&gt;Interestingly, if we expand the trie to become a suffix trie, then we can get full text searching, which is one of the most common requests that Mulgara gets.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Hashed Predicates&lt;/h3&gt; The example I gave above about how &lt;em&gt;&amp;lt;rdf:type&amp;gt;&lt;/em&gt; mostly participates in statements as a predicate, is common of many predicates. In many situations, the list of predicates to be used is quite small. In particular, there are likely to be just a few predicates that will be used the majority of the time, such as &lt;em&gt;&amp;lt;rdf:type&amp;gt;&lt;/em&gt;, &lt;em&gt;&amp;lt;rdfs:domain&amp;gt;&lt;/em&gt;, &lt;em&gt;&amp;lt;rdfs:range&amp;gt;&lt;/em&gt;, as well as many application specific values.&lt;br /&gt;&lt;br /&gt;Since these URIs are going to be accessed all the time, there isn't a lot of point in burying them deep in the URI tree. Instead, the most common URIs could each be given their own file, which indicates the "predicate statement list" for those URIs. Those URIs can be included in the tree for their subject and object lists, but the code that searches for predicates would skip the tree and go directly to the file instead. Any operations which require iterating over all the predicates can insert these values in via the algorithm, rather than getting it from the tree structure.&lt;br /&gt;&lt;br /&gt;However, which URIs would be stored this way? This may vary from one application to another. So instead of hard coding the values in, they could be placed in a configuration file. Then the application would know to map these values directly to their own files instead. Since the filenames can be allocated by the system, they can be created with a hashing algorithm, or possibly be placed in the configuration file along with the predicate URI list.&lt;br /&gt;&lt;br /&gt;I'd still prefer to configure this rather than allow ALL predicates to be done this way, as any predicates that are not used so commonly will not take the resources of another file. It also allows the system to have an arbitrary number of predicates beyond the most commonly used. But by having these files dedicated to common predicates, any requests for statements with a given predicate will require a single seek to the start of that file, and will immediately give the list, along with its size.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Comparisons&lt;/h3&gt; The evening after I presented this to the Mulgara/Topaz developers back in March, I happened to attend a presentation given on applying columnar databases to RDF. This described storing subject/object pairs in files, with one file per predicate. This particular optimization is similar, but it has a good fallback for when you run out of files for your predicates (after all, searching in good-sized B-Tree typically only requires a couple of seeks). This scheme also provides the ability to search for statements on subject or predicate, which apparently is less efficient in the presented system.&lt;br /&gt;&lt;br /&gt;A nice feature that is shared by both this scheme and the columnar scheme is that selecting statements always gives sorted values that can be joined with linear merge-joins.&lt;br /&gt;&lt;br /&gt;However, given the flexibility of this structure, I've been encouraged to write it up and let people know about it. Well, I've started that, but I thought it would be good to get &lt;em&gt;something&lt;/em&gt; out there straight away, hence this post.&lt;br /&gt;&lt;br /&gt;In the meantime, in amongst my SPARQL work I'm trying to build a proof-of-concept. I've done the complexity calculations to see both the worst case and the expected case, but it doesn't take much effort to see that it involves a massive reduction in the seeking, reading and writing done by Mulgara at the present. I won't be including all the optimizations discussed here, but I still expect it to be around two orders of magnitude faster, and to take up a couple of orders of magnitude less space.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Final Notes&lt;/h3&gt; None of the above discusses deletions, transactions, or any of that other stuff needed to make a database useful in the real world. These issues haven't been forgotten, but in order to present the structure I wanted to concentrate on the minimalism in reading and writing to the structure.&lt;br /&gt;&lt;br /&gt;My plan for deletions is to go through the various lists and mark them with invalid identifiers (e.g. -1). These will have to be skipped linearly during read operations, which means that removing data has little impact on speed (except that blank IDs will never need to be converted into URIs, Literals, etc). At a later time, either by an explicit cleanup operation, or a background task, a cleanup thread will compact the data by shifting it all down to fill the gaps. Of course, this will require some locking for consistency, though since everything is ordered, there may be a chance to minimize locking by skipping any data that repeats or appears out of order.&lt;br /&gt;&lt;br /&gt;Andrae has also spent a lot of time working on a theoretic framework for concurrent write transactions in RDF. His work is quite detailed and impressive. Fortunately, the engineering application of this work is completely consistent with this framework, so we hope to eventually integrate the two. In the meantime, Andrae's work will form the basis for XA2, which in turn will be taking a few avenues to permit this scheme to be easily integrated at a later date.&lt;br /&gt;&lt;br /&gt;So for now, I have to get SPARQL up and running, while also looking for time to finish the proof of concept and writing everything up. I suppose I should be doing that instead of blogging.  :-)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6848574-6102132533686860203?l=gearon.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://gearon.blogspot.com/feeds/6102132533686860203/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=6848574&amp;postID=6102132533686860203" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6848574/posts/default/6102132533686860203?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6848574/posts/default/6102132533686860203?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/WorkingNotes/~3/rZFG-WJVEzI/writing-2-columns-in-my-last-post-i.html" title="" /><author><name>Quoll</name><uri>http://www.blogger.com/profile/03653112583629043593</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="17348260940898309335" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total><feedburner:origLink>http://gearon.blogspot.com/2008/04/writing-2-columns-in-my-last-post-i.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A08HR3syeSp7ImA9WxZUF0g.&quot;"><id>tag:blogger.com,1999:blog-6848574.post-6149780138894045592</id><published>2008-04-08T23:35:00.003-05:00</published><updated>2008-04-09T11:50:36.591-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-04-09T11:50:36.591-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="indexing" /><category scheme="http://www.blogger.com/atom/ns#" term="64 bit" /><category scheme="http://www.blogger.com/atom/ns#" term="storage" /><category scheme="http://www.blogger.com/atom/ns#" term="RDF" /><category scheme="http://www.blogger.com/atom/ns#" term="Mulgara" /><title /><content type="html">&lt;h3&gt;Indexing&lt;/h3&gt; I'm in the process of writing a number of things up at the moment, including the following description of RDF storage. But since academic papers take so long to write, and they're boring, I thought I'd blog the main bit of one of the things I'm writing about.&lt;br /&gt;&lt;br /&gt;This all came about due to &lt;a href="http://gearon.blogspot.com/2004/08/proof-reading-once-again-its-way-too.html"&gt;a description&lt;/a&gt; I wrote a few years ago about the number of columns needed to store data that was &lt;em&gt;N&lt;/em&gt; columns wide. (Wow! Is it really 4 years?) It came down to a process and equation, of finding the minimum value of an expression, as &lt;em&gt;S&lt;/em&gt; varies from 1 to &lt;em&gt;N&lt;/em&gt;:&lt;pre&gt;min&lt;sub&gt;S=1..N&lt;/sub&gt; (&lt;em&gt;N&lt;/em&gt;!/(&lt;em&gt;N&lt;/em&gt;-&lt;em&gt;S&lt;/em&gt;)!&lt;em&gt;S&lt;/em&gt;!)&lt;/pre&gt;This gives a result of 3 indices for &lt;em&gt;symmetrically&lt;/em&gt; storing triples, 6 indices for quads, 10 indices for quintuples, and so on. Note that this is the number of indices needed if you want to be able to use &lt;em&gt;any&lt;/em&gt; search criteria on your tuples. This may indeed be the case for triples and quads, but if an element of the tuple becomes a unique ID (like it does for reification), then there is no need for symmetric indexing.&lt;br /&gt;&lt;br /&gt;The rapid growth of this equation is a clear indicator that we want to keep the number of columns as low as possible. For expediency Mulgara moved from 3 columns to 4, so that we could encode graph identifiers with the triples, but that came at the expense of doubling the number of indices. This is really a big deal, as each index in Mulgara takes several files for managing the resources in the index, and for holding the index itself. Each piece of information that has to be read or written means another disk seek. This can be mitigated by read and write-back caching by the operating system, but as the amount of data exceeds what can be handled in memory, then these benefits evaporate. So keeping the number of indices down is a big deal.&lt;br /&gt;&lt;br /&gt;Ronald Brachman's work in '77 shaped the future direction of description logics, including the use of the idea that everything can be represented using binary and unary predicates. RDF is defined using binary predicates, and unary predicates are simulated using the &lt;code&gt;rdf:type&lt;/code&gt; predicate, which means that RDF is inherently capable of representing description logics, and indeed, any kind of knowledge representation. The issue is that it can be inefficient to represent certain kinds of structures.&lt;br /&gt;&lt;br /&gt;The RDF representation of &lt;a href="http://www.w3.org/TR/rdf-schema/#ch_reificationvocab"&gt;reification&lt;/a&gt; requires 3 statements for reification (plus one that can be inferred) and these are independent of the actual statement itself. An extra column can eliminate these 3 statements altogether, but the indexes grow accordingly. Graph membership can be accomplished using extra statements as well, and again, this can be trivially eliminated with an extra column. The question is, when do the extra columns (with the consequent factorial growth) become more expensive than adding in more statements? Should the number of indices be limited to 4? To 3?&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;2 Columns&lt;/h3&gt; I always found it interesting that the equation above has a solution for &lt;em&gt;N&lt;/em&gt;=2. I considered this to be an artifact of the equation, but it bugged me all the same. So then a couple of years ago I gave it some thought, and realized that it is indeed possible to represent a triple using "doubles". Of course, once a triple can be represented, then anything can be represented. The question is efficiency.&lt;br /&gt;&lt;br /&gt;If the indices were to contain only 2 columns, then this means that only unary predicates could be used. This implies that the predicates define a type. After some thought I realized that I could use unique types to identify each element of an RDF statement, and then a unique type to represent the statement itself. Of course, there is nothing new under the sun, and just recently I discovered that the &lt;a href="http://citeseer.comp.nus.edu.sg/36655.html"&gt;CLASSIC&lt;/a&gt; system introduced unique atomic concepts for each individual in the system in a similar way.&lt;br /&gt;&lt;br /&gt;To map the following triple:&lt;pre&gt;&lt;code&gt;  &amp;lt;my:subject&amp;gt; &amp;lt;my:predicate&amp;gt; &amp;lt;my:object&amp;lt;&lt;/code&gt;&lt;/pre&gt; to unary predicates, I used a scheme like the following:&lt;pre&gt;&lt;code&gt;  Statement(_statement_x)&lt;br /&gt;  SubjectIdentifier(_subject_x)&lt;br /&gt;  PredicateIdentifier(_predicate_x)&lt;br /&gt;  ObjectIdentifier(_object_x)&lt;br /&gt;  _statement_x(_subject_x)&lt;br /&gt;  _statement_x(_predicate_x)&lt;br /&gt;  _statement_x(_object_x)&lt;br /&gt;  _subject_x(my:subject)&lt;br /&gt;  _predicate_x(my:predicate)&lt;br /&gt;  _object_x(my:object)&lt;/code&gt;&lt;/pre&gt;Where each of &lt;code&gt;_statement_x&lt;/code&gt;, &lt;code&gt;_subject_x&lt;/code&gt;, &lt;code&gt;_predicate_x&lt;/code&gt; and &lt;code&gt;_object_x&lt;/code&gt; are unique identifiers, never to be used again. In fact, my use of underscores as a prefix here indicates that I was thinking of them as a kind of blank node: unique, but without a distinguishing label.&lt;br /&gt;&lt;br /&gt;When I first came up with this scheme, I thought it a curiosity, but hardly useful. It seemed that significant work would need to be done to reconstruct a triple, and indexing so many items would require a lot of seeking on disk. I was also concerned about the "reckless" use of the address space for identifiers in creating unique IDs for so many elements.&lt;br /&gt;&lt;br /&gt;Then recently I was describing this scheme to a friend, and I realized that when I considered some other ideas I'd been working on lately, then there was something to this scheme after all.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Disk Seeking&lt;/h3&gt; I've been very disappointed with Mulgara's loading speed on certain types of data recently. If the data has a lot of unique URIs and strings, then the size of the store was getting too large, and the length of time taken to store the data was too long. I was also surprised at the gigabytes of file storage being used when the data files were only a few hundred megabytes. Mulgara is supposed to be scalable, and this wasn't acceptable behavior.&lt;br /&gt;&lt;br /&gt;Consequently, I've been doing more work with algorithms and data structures recently. I have not been trying to supplant &lt;a href="http://mulgara.org/trac/wiki/XA2Proposals"&gt;Andrae's work&lt;/a&gt; but was instead hoping to tweak the existing system a little in order to improve performance.&lt;br /&gt;&lt;br /&gt;The first thing that becomes apparent is that the plethora of files in Mulgara is a real bottleneck. Each file on its own may be efficient (not all are), but cumulatively they cause a disk to seek all over the place. Since this is probably the single most expensive action a computer can take (other than a network request), then reducing the seeks is a priority.&lt;br /&gt;&lt;br /&gt;Profiling the code led to a couple of improvements (these have been rolled into the &lt;a href="http://mulgara.org/news.html#date030408"&gt;Mulgara 1.2 release&lt;/a&gt;), but also showed that the biggest issue is the String Pool (more properly called the "Data Pool" since it now stores any kind of data). This is a facility that maps any kind of data (like a URI or a string) to a unique number, and maps numbers into the data they represent. With a facility like this, Mulgara is able to store triples (or quads) as groups of numbers. We call these numbers "Graph Nodes", or &lt;em&gt;gNodes&lt;/em&gt;.&lt;br /&gt;&lt;br /&gt;The string pool was spending a lot of time just searching to see if a URI or string to be inserted into the graph was already mapped to a number, and inserted it if not. Some work was also being done to keep track of what had been allocated in a given transaction phase, so that any allocated resources (like disk blocks) could be freed and reallocated if the data were ever removed. However, items are rarely removed from the string pool. Removals mostly occur when an entire graph is dropped, and these graphs are often dropped just before a slightly modified version of the same data is to be inserted. In this case, the same data will be removed from the string pool, and then re-inserted. That's a lot of work for nothing. It makes much more sense to leave everything in the string pool, and only remove unused items when explicitly requested, or perhaps as a background task. (Unused items can be easily identified since they don't exist in the statement indices).&lt;br /&gt;&lt;br /&gt;If the string pool were changed to be a write-once-read-many pool, then a lot of the structures that support resource reuse (Free Lists, which are a few files each) can be removed from the string pool. Of course, the reduced reading/writing involved with removing and re-inserting data would also benefit. So this looked promising.&lt;br /&gt;&lt;br /&gt;Another idea is to take any data that fits into less than 64 bits (say, 58 bits) and store it directly in the ID number instead of in the pool. The top bits can then indicate the type of the value, and whether or not it is "stored" or if it is simply encoded in the ID. This covers a surprising range of required numbers, and most dates as well. This idea was mentioned to me in SF last year, and it sounded good, only I had &lt;em&gt;completely&lt;/em&gt; forgotten that Andrae had already proposed it a year before (sorry Peter, you weren't first). But wherever the idea came from, it promised to dramatically help dates and numbers. In fact, it helps all the data, since the tree no longer has as many elements stored in it.&lt;br /&gt;&lt;br /&gt;There were also other ideas, such as moving the tree type of the index. We mitigated the use of AVL trees in the indices by using pointers to large blocks of data. However, this becomes a subtraction of a constant in the complexity analysis, while a wider tree becomes a division by a constant. Constants don't usually mean much in complexity analysis, but when each operation represents a disk seek, then the difference becomes significant. While this is something that must be looked at, it didn't make sense when we knew that XA2 is coming, and that the trees will change anyway.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Address Space&lt;/h3&gt; You may have noticed that I'm talking a lot about resource reallocation, and 64 bits in the same breath. This shows some of the history of Mulgara. The system originally ran on 32 bits, where not reusing resources was a guaranteed way to wrap around in the number space and cause no end of problems. When the system was upgraded to 64 bits, it still made sense to manage resources for reallocation, as some resources were still limited. However, resources that represented IDs in an address space were not reconsidered, and they ought to have been. Looking at what literals could be encoded in a 64 bit value (and how many bits should be reserved for type data) was the impetus I needed to make me look at this again.&lt;br /&gt;&lt;br /&gt;Given that every resource we allocated took a finite time that was often bounded by disk seeks, it occurred to me that we were not going to run out of IDs. If we only used 58 bits, then we could still allocate a new resource every microsecond and not run out of IDs for over 9000 years. A more reasonable design period is 100 years (yes, this is a wide margin of safety), and constant allocation of resources at a microsecond per resource means that we still only need 52 bits. So we're safe not reusing IDs, and indeed, we have over a byte of information we can use in this ID to do some interesting engineering tricks.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Structure&lt;/h3&gt; So I had a number of these lessons fresh in mind when I recently tried to describe just why a 2 column store was inefficient. During the course of the conversation I started seeing ways in which I could apply some of these techniques in a useful way. It took a while for it to come together, but I now have something that really shows some promise.&lt;br /&gt;&lt;br /&gt;The details here are reasonably detailed, so it makes sense to take a break here, and write it all up in a fresh post in the next day or so. A little more sleep might also help prevent the rambling that I've noticed coming into this post.  :-)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6848574-6149780138894045592?l=gearon.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://gearon.blogspot.com/feeds/6149780138894045592/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=6848574&amp;postID=6149780138894045592" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6848574/posts/default/6149780138894045592?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6848574/posts/default/6149780138894045592?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/WorkingNotes/~3/tQLOV1pqBpg/indexing-im-in-process-of-writing.html" title="" /><author><name>Quoll</name><uri>http://www.blogger.com/profile/03653112583629043593</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="17348260940898309335" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">2</thr:total><feedburner:origLink>http://gearon.blogspot.com/2008/04/indexing-im-in-process-of-writing.html</feedburner:origLink></entry><entry gd:etag="W/&quot;Dk4GR3w8eCp7ImA9WxZUEUw.&quot;"><id>tag:blogger.com,1999:blog-6848574.post-8793337319364749737</id><published>2008-04-01T23:24:00.002-05:00</published><updated>2008-04-02T00:42:06.270-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-04-02T00:42:06.270-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="OWL" /><category scheme="http://www.blogger.com/atom/ns#" term="RDF" /><title /><content type="html">&lt;h3&gt;Collections&lt;/h3&gt; So I'm trying to work out what is necessary in OWL, and what is necessary and sufficient. Actually, I just want "necessary and sufficient", but knowing the difference helps.  :-)&lt;br /&gt;&lt;br /&gt;Anyway, while working through this blog, I worked it out. But it probably won't hurt to write it down anyway...&lt;br /&gt;&lt;br /&gt;I had narrowed my problem down to the following:&lt;br /&gt;&lt;br /&gt;If I had a Collection like:&lt;pre&gt;  &amp;lt;rdf:Description rdf:about="http://example.org/basket"&amp;gt;&lt;br /&gt;    &amp;lt;ex:hasFruit rdf:parseType="Collection"&amp;gt;&lt;br /&gt;    &amp;lt;rdf:Description rdf:about="ex:banana"/&amp;gt;&lt;br /&gt;    &amp;lt;rdf:Description rdf:about="ex:apple"/&amp;gt;&lt;br /&gt;    &amp;lt;rdf:Description rdf:about="ex:pear"/&amp;gt;&lt;br /&gt;  &amp;lt;/ex:hasFruit&amp;gt;&lt;/pre&gt;Then this is translated to:&lt;pre&gt;&amp;lt;ex:basket&amp;gt; &amp;lt;ex:hasFruit&amp;gt; _:l1 .&lt;br /&gt;_:l1 &amp;lt;rdf:first&amp;gt; &amp;lt;ex:banana&amp;gt; .&lt;br /&gt;_:l1 &amp;lt;rdf:rest&amp;gt; _:l2 .&lt;br /&gt;_:l2 &amp;lt;rdf:first&amp;gt; &amp;lt;ex:apple&amp;gt; .&lt;br /&gt;_:l2 &amp;lt;rdf:rest&amp;gt; _:l3 .&lt;br /&gt;_:l3 &amp;lt;rdf:first&amp;gt; &amp;lt;ex:pear&amp;gt; .&lt;br /&gt;_:l3 &amp;lt;rdf:rest&amp;gt; &amp;lt;rdf:nil&amp;gt; .&lt;/pre&gt;Now is this list open or closed? This is an important question for OWL, since collections are used to construct sets such as intersections.&lt;br /&gt;&lt;br /&gt;If it's open, then I could add in another piece of fruit...&lt;pre&gt;&amp;lt;ex:basket&amp;gt; &amp;lt;ex:hasFruit&amp;gt; _:l0 .&lt;br /&gt;_:l0 &amp;lt;rdf:first&amp;gt; &amp;lt;ex:orange&amp;gt; .&lt;br /&gt;_:l0 &amp;lt;rdf:rest&amp;gt; _:l1 .&lt;/pre&gt;This would work, but it implies that I can infer that every element of the list can be directly connected to the basket.  i.e.&lt;pre&gt;&amp;lt;ex:basket&amp;gt; &amp;lt;ex:hasFruit&amp;gt; _:l0 .&lt;br /&gt;&amp;lt;ex:basket&amp;gt; &amp;lt;ex:hasFruit&amp;gt; _:l1 .&lt;br /&gt;&amp;lt;ex:basket&amp;gt; &amp;lt;ex:hasFruit&amp;gt; _:l2 .&lt;br /&gt;&amp;lt;ex:basket&amp;gt; &amp;lt;ex:hasFruit&amp;gt; _:l3 .&lt;/pre&gt;Now this makes sense to me, but I don't recall seeing it anywhere in RDF. For instance, it's not in the &lt;a href="http://www.w3.org/TR/rdf-mt/"&gt;semantics document&lt;/a&gt; for RDF or RDFS. The &lt;a href="http://www.w3.org/TR/rdf-mt/#collections"&gt;section on Collections&lt;/a&gt; does say that RDF does not require any well-formedness on the structure of the list (indeed, branched structures are explicitly mentioned), but since only OWL-Full allows arbitrary RDF structures, it isn't generally applicable to what I'm interested in.&lt;br /&gt;&lt;br /&gt;I'd come to this question while I was checking that an owl:intersectionOf with "complete" modality was necessary and sufficient. I presumed that it was, but it doesn't hurt to check. After all, I've been caught out in the open world before. :-)&lt;br /&gt;&lt;br /&gt;I first went to the abstract syntax for &lt;a href="http://www.w3.org/TR/owl-semantics/syntax.html#owl_Class_syntax"&gt;class axioms&lt;/a&gt; to find out how "partial" modalities were encoded, vs. "complete". The &lt;a href="http://www.w3.org/TR/owl-semantics/mapping.html#owl_equivalentClass_mapping"&gt;triples encoding of the abstract syntax&lt;/a&gt; shows that "partial" is simply a list of rdfs:subClassOf statements for each element in the intersection, while "complete" uses an RDF collection. Actually, the expression "SEQ" is used, but sequences are then described as being of type rdf:List, and not rdf:Seq (which, incidentally, &lt;em&gt;are&lt;/em&gt; extensible, but no OWL aficionado will have anything to do with them, so I knew &lt;em&gt;that&lt;/em&gt; wasn't a possibility).&lt;br /&gt;&lt;br /&gt;Now to make sure that "complete" really &lt;em&gt;is&lt;/em&gt; complete, I needed to ensure that lists couldn't be extended.&lt;br /&gt;&lt;br /&gt;There &lt;em&gt;is&lt;/em&gt; a hint that lists can't be extended in OWL-DL in the &lt;a href="http://www.w3.org/TR/2004/REC-owl-guide-20040210/#differentFrom"&gt;OWL Guide&lt;/a&gt;:&lt;br /&gt;&lt;em&gt;"If we wanted to add a new winery in some other ontology and assert that it was disjoint from all of those that have already been defined, we would need to cut and paste the original owl:AllDifferent assertion and add the new maker to the list. There is not a simpler way to extend an owl:AllDifferent collection in OWL DL. In OWL Full, using RDF triples and the rdf:List constructs, other approaches are possible."&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;That raises the intriguing possibility that in OWL-Full an intersection can never be complete. But since OWL-Full is undecidable anyway, I guess that's not something I need to worry about.&lt;br /&gt;&lt;br /&gt;That then brought me back to the description for &lt;a href="http://www.w3.org/TR/2004/REC-owl-guide-20040210/#SetOperators"&gt;Set Operators&lt;/a&gt; which I haven't read in a while. And in reading this I realized that I was a moron for forgetting it...&lt;br /&gt;&lt;em&gt;The members of the class are completely specified by the set operation.&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;The text then goes on to describe that an individual that is a member of each element of an intersection is then a member of the intersection. In other words, membership in each element is a &lt;em&gt;necessary and sufficient&lt;/em&gt; condition for membership in the intersection. Had lists been open, then membership would have merely been necessary, but not sufficient, since there could be another class in the intersection that has not been asserted (yet).&lt;br /&gt;&lt;br /&gt;So &lt;em&gt;complete&lt;/em&gt; is indeed "necessary and sufficient". But if I'd just looked at the Guide in the first place I could have saved myself a bit of time. Sometimes I feel like an idiot... and then I go and compound it by writing about my stupidity on my blog.&lt;br /&gt;&lt;br /&gt;Oh well, this SPARQL implementation won't write itself. I'm down to OPTIONAL - which I expect to take about an hour, and the algebra integration. I'd better make that transformation clean, as I expect to be doing it again soon for the &lt;a href="http://www.openrdf.org/doc/sesame2/api/org/openrdf/query/algebra/package-summary.html"&gt;Sesame algebra&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Somehow I also need to find some time to finish writing that paper about 2 column RDF indexes. Did I mention that I think they're a cool idea?  :-)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6848574-8793337319364749737?l=gearon.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://gearon.blogspot.com/feeds/8793337319364749737/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=6848574&amp;postID=8793337319364749737" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6848574/posts/default/8793337319364749737?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6848574/posts/default/8793337319364749737?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/WorkingNotes/~3/53zOPA1iqog/collections-so-im-trying-to-work-out.html" title="" /><author><name>Quoll</name><uri>http://www.blogger.com/profile/03653112583629043593</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="17348260940898309335" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://gearon.blogspot.com/2008/04/collections-so-im-trying-to-work-out.html</feedburner:origLink></entry><entry gd:etag="W/&quot;Dk4HQH88fip7ImA9WxZWGEQ.&quot;"><id>tag:blogger.com,1999:blog-6848574.post-1419147329725354127</id><published>2008-03-18T20:59:00.003-05:00</published><updated>2008-03-18T21:48:51.176-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-03-18T21:48:51.176-05:00</app:edited><title /><content type="html">&lt;h3&gt;Functions&lt;/h3&gt; Whew! I've finally finished filter functions.&lt;br /&gt;&lt;br /&gt;I was just about done when I had two issues show up for me. First off, I realized that each parameter of &lt;a href="http://www.w3.org/TR/rdf-sparql-query/#funcex-regex"&gt;regex&lt;/a&gt; takes an expression that resolves to a simple literal. In other words, it is possible to calculate a different pattern and/or flag for every line &lt;em&gt;&amp;lt;shudder/&amp;gt;&lt;/em&gt;. OK, so I wouldn't do it, but the spec says it, so I did it. Not that it was hard. It just seems obtuse.&lt;br /&gt;&lt;br /&gt;While I'm on it, the &lt;a href="http://www.w3.org/TR/xpath-functions/#regex-syntax"&gt;flags&lt;/a&gt; for &lt;em&gt;regex&lt;/em&gt; don't quite match the flags in Java. Granted, they're ALMOST the same, but if I want to be a stickler about this things, then it's not quite there. The most apparent difference is that the "x" character is not the same as enabling the &lt;a href="http://java.sun.com/javase/6/docs/api/java/util/regex/Pattern.html#COMMENTS"&gt;COMMENTS&lt;/a&gt; flag in Java - though it's similar. In fact, in Java 5, the COMMENTS flag does not even appear as an option in the Javadoc, though a quick scan of the library source shows that it is.&lt;br /&gt;&lt;br /&gt;Once I found small differences (which frankly I expected to find) I decided not to look for any more. The point is that I am &lt;strong&gt;not&lt;/strong&gt; going to implement my own regex engine. Sure, it would be a great learning experience (I know that suffix trees get me part of the way - but I'd have to learn some more to get all of it), but it would take me months, and for no useful purpose. I'm surprised they didn't just choose a standard engine and say "use a standards-compliant regex engine, like &lt;em&gt;XXX&lt;/em&gt;". As it is, it looks like everyone will be &lt;em&gt;nearly&lt;/em&gt; there, but never quite make it.&lt;br /&gt;&lt;br /&gt;The next problem was that I hadn't looked carefully enough at the definition of &lt;a href="http://www.w3.org/TR/rdf-sparql-query/#func-RDFterm-equal"&gt;&lt;code&gt;equal&lt;/code&gt;&lt;/a&gt;. I was mostly right, but it turns out that if you compare two literals that are different, then you don't return false: you throw a &lt;em&gt;type&lt;/em&gt; exception. That just feels broken. Yes, I understand the semantics, but it's a perfectly common thing to do to check that two literals are the same. Having unexpected data throw an exception from a perfectly formed query might make the type theoreticians happy, but from the perspective of a software developer it looks like bad judgement.&lt;br /&gt;&lt;br /&gt;Ironically, you &lt;em&gt;CAN&lt;/em&gt; choose to return true for two different literals if you have a specific extension that handles direct comparisons between their types. For instance, you can check if "5"^^xsd:integer is equal to "5"^^xsd:long. Or perhaps you want to compare "5"^^temp:celsius and "41"^^temp:fahrenheit. If you want to get the same lexical form, then you use the &lt;code&gt;sameterm()&lt;/code&gt; function, so that case is covered. But what if you want to compare two literals to have the same semantic value, and simply return &lt;code&gt;false&lt;/code&gt; if they don't? Maybe I need to re-read this spec, because it doesn't work for me. Still, I've implemented it as asked, if it was more annoying to do so.&lt;br /&gt;&lt;br /&gt;So now I have a lot of unit tests to write. Yes, I know the &lt;acronym title="Test Driven Development"&gt;TDD&lt;/acronym&gt; purists will be out to get me, but the exact implementation and interfaces were still floating a little when I started, and besides, it &lt;em&gt;is&lt;/em&gt; faster to write code with the tests written after. This is mostly because you don't have to change the tests if you realize you need to change the interfaces. And time is something I'm working hard against at the moment.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Filter&lt;/h3&gt; Andrae had a go at me for looking to make filters annotations on the constraints in the &lt;acronym title="Abstract Syntax Tree"&gt;AST&lt;/acronym&gt; for the query. I didn't see a problem with this (and there is no operational difference) until Andrae pointed out that it would have a big impact on the optimizer and query re-writer, since each node can have more that one type: a filtered version and an unfiltered version.&lt;br /&gt;&lt;br /&gt;He was suggesting that I use the conjunction code to apply filters (and the concrete syntax of SPARQL &lt;a href="http://www.w3.org/TR/rdf-sparql-query/#GroupPatterns"&gt;almost seems to imply&lt;/a&gt; that FILTER is added in as a conjunction - though this might just be to allow alternative syntaxes) but I pointed out that this will get awkward as the &lt;a href="http://www.w3.org/TR/rdf-sparql-query/#func-bound"&gt;&lt;code&gt;BOUND()&lt;/code&gt;&lt;/a&gt; function requires that variables not be guaranteed to be pre-bound. This led to a discussion of the use of &lt;code&gt;BOUND()&lt;/code&gt;, and I was able to show that it is often used in conjunction with &lt;code&gt;NOT&lt;/code&gt; and &lt;code&gt;OPTIONAL&lt;/code&gt; to emulate &lt;code&gt;subtraction&lt;/code&gt; functionality. When he saw what I meant, he was quite congratulatory of SPARQL for taking a &lt;em&gt;log(n)&lt;/em&gt; operation and making it linear in &lt;em&gt;n&lt;/em&gt;.&lt;br /&gt;&lt;em&gt;(For any non-Australians reading this.... yes, that was sarcasm)&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;At least this conversation made me realize that filtering the output of each &lt;code&gt;Tuple&lt;/code&gt; would be a mistake (good thing I haven't written this yet). Instead I'll be implementing FILTER in the AST as a new constraint element that wraps another constraint (this makes it easy for the optimizer and transformer to ignore) and to create a new operation akin to &lt;code&gt;MINUS&lt;/code&gt; that will do the work. Currently &lt;code&gt;MINUS&lt;/code&gt; removes elements on the left that match (via variable bindings) elements on the right. The new code will remove them based on failing the &lt;code&gt;FILTER&lt;/code&gt; test.  Simple.  :-)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6848574-1419147329725354127?l=gearon.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://gearon.blogspot.com/feeds/1419147329725354127/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=6848574&amp;postID=1419147329725354127" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6848574/posts/default/1419147329725354127?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6848574/posts/default/1419147329725354127?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/WorkingNotes/~3/biS9MBEutcQ/functions-whew-ive-finally-finished.html" title="" /><author><name>Quoll</name><uri>http://www.blogger.com/profile/03653112583629043593</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="17348260940898309335" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://gearon.blogspot.com/2008/03/functions-whew-ive-finally-finished.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CUcAQXc8eCp7ImA9WxZWF0U.&quot;"><id>tag:blogger.com,1999:blog-6848574.post-2562630207413132643</id><published>2008-03-15T12:05:00.004-05:00</published><updated>2008-03-17T14:44:00.970-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-03-17T14:44:00.970-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="types" /><category scheme="http://www.blogger.com/atom/ns#" term="SPARQL" /><category scheme="http://www.blogger.com/atom/ns#" term="filter" /><title /><content type="html">&lt;h3&gt;Writing&lt;/h3&gt; I've been trying to sit down and write for over a week, but each time I try I end up writing code instead. I've even fallen behind reading &lt;a href="http://slashdot.org/"&gt;Slashdot&lt;/a&gt;. I've been getting a lot of messages from people wanting to know what happened last week, what our plans are for Mulgara, etc, but I just haven't been able to respond. That's what happens when a developer tries to work in the real world. I handle the real world, and I can handle code, but not at the same time. :-(&lt;br /&gt;&lt;br /&gt;For the moment, I have priorities with work that I have to see to, so I'll be concentrating on technical things for a while. However, there &lt;em&gt;are&lt;/em&gt; a few things happening with Mulgara, so I'll try to mention them as I go. In the meantime, I'm working on SPARQL queries.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;SPARQL&lt;/h3&gt; The two main features that we're missing now are &lt;a href="http://www.w3.org/TR/rdf-sparql-query/#optionals"&gt;&lt;code&gt;OPTIONAL&lt;/code&gt;&lt;/a&gt; and &lt;a href="http://www.w3.org/TR/rdf-sparql-query/#termConstraint"&gt;&lt;code&gt;FILTER&lt;/code&gt;&lt;/a&gt;. Looking at &lt;code&gt;OPTIONAL&lt;/code&gt; some time ago I realized that it's a hybrid between &lt;code&gt;ConstraintConjunction&lt;/code&gt; (the inner join aspect), and &lt;code&gt;ConstraintDisjunction&lt;/code&gt; (matches on the left side leaving unbound columns). I worked on something similar when I did &lt;code&gt;ConstraintDifference&lt;/code&gt; a few years ago, so I know that this is easy. Hence, I put this part off until last.&lt;br /&gt;&lt;br /&gt;In the last week or so (in between the meeting in San Francisco, and getting a nasty virus) I've been on filters. Right now I'm down to some classes to represent the operator definitions for all the functions like &lt;a href="http://www.w3.org/TR/rdf-sparql-query/#func-bound"&gt;&lt;code&gt;bound()&lt;/code&gt;&lt;/a&gt;, &lt;a href="http://www.w3.org/TR/rdf-sparql-query/#func-isIRI"&gt;&lt;code&gt;isIRI()&lt;/code&gt;&lt;/a&gt; and &lt;a href="http://www.w3.org/TR/rdf-sparql-query/#funcex-regex"&gt;&lt;code&gt;regex()&lt;/code&gt;&lt;/a&gt;. I already have the functionality implemented, but you still need to represent it in an abstract syntax if you're going to construct expressions at query time. So it's all just some boiler plate code to represent the parameters and pass the context on down to any variables that need resolving. After that, I'm on to the unit tests. In an ideal world, I'd test &lt;em&gt;everything&lt;/em&gt; but in reality I have less time than that. Many of the functions are so similar that I'll just be testing a good sample of each of them.&lt;br /&gt;&lt;br /&gt;Looking at the list in the SPARQL definition, you might think that there aren't too many functions at all, but you would be wrong. For a first approximation, many of the functions have to be reimplemented for each type of parameter. I've even gone to the effort of making sure that working on an &lt;code&gt;&amp;lt;xsd:int&amp;gt;&lt;/code&gt; returns an &lt;code&gt;&amp;lt;xsd:int&amp;gt;&lt;/code&gt; (when appropriate), and that an &lt;code&gt;&amp;lt;xsd:short&amp;gt;&lt;/code&gt; returns an &lt;code&gt;&amp;lt;xsd:short&amp;gt;&lt;/code&gt;. Since I was already trying to keep floating point numbers and integers apart, then this seemed to be a natural extension. Then I have to consider the types of numbers typed into the SPARQL query, literal numbers typed in to the query, and variables that get bound to numbers during processing. This raises the complexity considerably.&lt;br /&gt;&lt;br /&gt;My first attempt had me doing largish methods that have copious "&lt;code&gt;if (value instanceof ...)&lt;/code&gt;" statements in them. This is clunky and brittle. The moment I went to do it a second time, I decided to throw it out, and do it all with maps to functors (where are &lt;a href="http://blogs.sun.com/jag/date/20080131"&gt;closures&lt;/a&gt;?!?). This actually worked well, and has the advantage of giving short and simple functions, and consistent patterns to follow in implementations. I'd have liked to use generics a little more, but they are really suited for interpreting code you are writing, rather than code that is being structured from a parser. Consequently, in one class I ended up writing a little &lt;a href="http://www.ruby-lang.org/en/"&gt;Ruby&lt;/a&gt; script to write the series of functor classes I needed for arithmetic operations! Scary, I know, but it works quite well.  It was either that or a series of if/then/else blocks taking me down dark passages I never want to enter.&lt;br /&gt;&lt;br /&gt;The frustrating thing is that via autoboxing, you can write the same arithmetic over and over again, and have it do different things. For instance, the expression:&lt;pre&gt;&lt;code&gt;x * y&lt;/code&gt;&lt;/pre&gt; can result it totally different return types depending on whether x and y are Doubles, Floats, Integers, etc. This is common when programming in Java using the native types (like &lt;code&gt;double&lt;/code&gt; and &lt;code&gt;int&lt;/code&gt;) but this must be established at compile time, not when processing query. That means you want to have access to every combination of parameters at run time. This can be done with autoboxing, and defining classes with interfaces that return &lt;code&gt;java.lang.Number&lt;/code&gt;s. Then the code &lt;code&gt;x*y&lt;/code&gt; can be written over and over, and it means something different each time. &lt;a href="http://java.sun.com/j2se/1.5.0/docs/guide/language/generics.html"&gt;Java generics&lt;/a&gt; are nice, but they are a long way short of C++ templates, a fact especially obvious when you want to use them on native types (along with a hundred other reasons). But Generics + &lt;a href="http://java.sun.com/j2se/1.5.0/docs/guide/language/autoboxing.html"&gt;Autoboxing&lt;/a&gt; can sometimes get you some of the way.&lt;br /&gt;&lt;br /&gt;OK, so that gave me access to each combination of parameters, but surely there's a better way to do it dynamically? Well, not in Java. The only approaches I've seen in the past either use heuristics to work out which version of arithmetic to run, or else it promotes everything into a standard type (like Double). The latter has arithmetic problems, and gives an inappropriate type for the result.  The former can just be complex to read, write, and verify.&lt;br /&gt;&lt;br /&gt;The problem comes back the CPU having different instructions for the different forms of arithmetic. A compiler has no problems selecting which one to use, but that is because it has access to the entire library of instructions. Conversely, a parser is not expected to have access to all instructions, leading to the problems I'm talking about. So you either choose a subset of instructions to work with (ie. upcast everything), or else you provide all instructions in a library, and then map the parameters into the correct instruction - either with the heuristic tree or something like a hash map.&lt;br /&gt;&lt;br /&gt;Dynamic languages have a much easier time of it. For a start, they usually have all instructions at their disposal in the interpreter. Many (though not all) of them also simplify their numeric types to only a couple of types. Whatever they use, the poor programming schmuck writing his own interpreter (that would be me) need only write &lt;code&gt;x*y&lt;/code&gt; and let the dynamic language developer work out what he wanted. At the very least, we can emit it in a string and do an &lt;code&gt;eval()&lt;/code&gt;.&lt;br /&gt;&lt;br /&gt;Oh well, I shouldn't complain. I have all the functions written out (via Ruby) and a hash map that lets me get what I need trivially. With the exception that there is a lot of machine generated code that looks like the same thing over and over, the whole system comes down to just a few lines of easily verifiable code - which is what I like to see. Following the code path you'll see that any kind of operation just goes through a few steps and it's done.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6848574-2562630207413132643?l=gearon.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://gearon.blogspot.com/feeds/2562630207413132643/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=6848574&amp;postID=2562630207413132643" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6848574/posts/default/2562630207413132643?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6848574/posts/default/2562630207413132643?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/WorkingNotes/~3/la_uzUqcLgc/writing-ive-been-trying-to-sit-down-and.html" title="" /><author><name>Quoll</name><uri>http://www.blogger.com/profile/03653112583629043593</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="17348260940898309335" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://gearon.blogspot.com/2008/03/writing-ive-been-trying-to-sit-down-and.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CUYGQn87fCp7ImA9WxZWEUs.&quot;"><id>tag:blogger.com,1999:blog-6848574.post-903178916431797225</id><published>2008-03-09T12:30:00.003-05:00</published><updated>2008-03-10T10:32:03.104-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-03-10T10:32:03.104-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="job" /><category scheme="http://www.blogger.com/atom/ns#" term="Google" /><category scheme="http://www.blogger.com/atom/ns#" term="Mulgara" /><title /><content type="html">&lt;h3&gt;Review&lt;/h3&gt; You know you've been lax keeping up with your blog when your mother comments that you haven't updated it in a while.&lt;br /&gt;&lt;br /&gt;Part of the reason for my silence has been due to a lot of changes going on for me lately, some of which I was obliged to keep quiet about at the time. More recently, I've been working hard on Mulgara, and when it's come to a choice between coding or blogging, then coding had a higher imperative. But today I find myself in &lt;a href="http://www.flysfo.com/"&gt;SFO&lt;/a&gt; feeling to wrung out to code, so it seems like a good opportunity to play some catch up on my blog.&lt;br /&gt;&lt;h3&gt;Talis&lt;/h3&gt; Way back in the middle of 2007 I was contacted by &lt;a href="http://www.talis.com/"&gt;Talis&lt;/a&gt; who were wondering if I would be interested in working with them on semantic web systems, and possibly on Mulgara. My job at the time (with &lt;a href="http://www.herzumsoftware.com/"&gt;Herzum Software &lt;/a&gt; and the spin-off &lt;a href="http://www.fourthcodex.com/"&gt;fourthcodex&lt;/a&gt;) was supposed to be based on Semantic Web technology, with a sizable proportion devoted to &lt;a href="http://mulgara.org/"&gt;Mulgara&lt;/a&gt;. However, this had not happened for the 2 years I had been there, and so I was willing to consider this proposal. Also, I was getting great enjoyment and occasional inspiration from Paul Miller's &lt;a href="http://talk.talis.com/"&gt;Talking with Talis&lt;/a&gt; interviews (and even gaining an interest in libraries, courtesy of Richard Walis's productions). I'd also met &lt;a href="http://iandavis.com/blog/about"&gt;Ian Davis&lt;/a&gt; at &lt;a href="http://www.semantic-conference.com/"&gt;SemTech&lt;/a&gt; earlier in the year, and had noted with interest that &lt;a href="http://dannyayers.com/"&gt;Danny Ayers&lt;/a&gt; had recently made the move as well.&lt;br /&gt;&lt;br /&gt;So in August I took a few days from work and flew to England for an interview. I was really impressed with the guys in Birmingham, both technically and personally, and had a great time. While my understanding of the details has changed at various times, it seems that Talis have an approach of investing in Semantic Web technology without an requirement of immediate return. They are also providing support to a growing Semantic Web community with the expectation that this will lead to a data infrastructure on which they can layer semantic applications at a higher level than is possible today. To me this seems to be both very forward thinking, as well as operating for the mutual benefit of themselves and the community at large. As an Australian I also found that the similarities in culture with the British gave me a level of comfort beyond what I usually have here in America.&lt;br /&gt;&lt;br /&gt;Whether I would be working in semantics, or in the storage layer to enable semantic work by others, this really seemed like a place I'd enjoy working. However, the position would be telecommuting, and I need a visa sponsor while I live here in the USA. Talis were aware of this, and though they said they were in the process of setting up a legal entity over here, the delays this brought about have led to events overtaking this opportunity.&lt;br /&gt;&lt;br /&gt;That said, I'm still trying to keep channels open with everyone there, and I'm hoping that I'll be able to work with them in the future, in whatever capacity that may be.&lt;br /&gt;&lt;h3&gt;Google&lt;/h3&gt; Shortly before the trip to England, I found myself thinking of distributing immutable tree nodes (from Mulgara's internal storage) over a cluster, with the idea of improving scalability of speed and size for RDF storage. These thoughts led to ideas of leveraging a system like the &lt;a href="http://research.google.com/archive/gfs-sosp2003.pdf"&gt;GFS&lt;/a&gt; or &lt;a href="http://research.google.com/archive/bigtable-osdi06.pdf"&gt;BigTable&lt;/a&gt;. &lt;a href="http://hadoop.apache.org/"&gt;Hadoop&lt;/a&gt; is also interesting in this regard, but not as advanced or scalable as the systems at Google. With this in mind, and being particularly frustrated at work, I checked out the &lt;a href="http://www.google.com/intl/en/jobs/index.html"&gt;Google jobs page&lt;/a&gt;, and discovered that they had engineering positions available in Chicago. So I filled in their online forms and sent it off. Disappointingly, the next day I received a form-reply email explaining that I wasn't what they were after.&lt;br /&gt;&lt;br /&gt;A few weeks later I met &lt;a href="http://www.ericjohnolson.com/blog/"&gt;Eric Olson&lt;/a&gt; at &lt;a href="http://techcocktail.com/"&gt;Tech Cocktail&lt;/a&gt;. Eric was still working at Google at the time, and said that he'd mention my name. I have no idea if he did or not, but a couple of weeks later, a Google recruiter in California rang me and asked if I would be available for a phone interview. This was delayed while I went to England, and then delayed further as that recruiter left and another took on my case, but it finally happened in September. It was very strange to do an interview again, when I've conducted so many in the last couple of years. I've also managed to avoid the "normal" interview process for most of the last decade, since I have usually been interviewed or offered positions by people who already knew me, either personally or by reputation.&lt;br /&gt;&lt;br /&gt;All the same, this interview went well, as did the next phone interview. So Google organized tickets for me to fly out to Mountain View and interview on site. I hadn't seriously considered a job with them to this point, but I thought it would be interesting to follow the process through.&lt;br /&gt;&lt;br /&gt;Visiting the Mountain View campus was quite an experience. It is vast, and has been gradually subsuming the surrounding business district in recent years. Getting around is often done by shuttle bus, or bicycle. People bring their own bikes, but there are a number of Google bikes parked around the place, with helmets available in large bins in the lobby of each building. Not having been given a building number to go to, I started at the central building, where I was quickly spotted and assisted by a security guard. Indeed, I was very impressed at the rapid and efficient response of on-campus security, especially as they were also very helpful and courteous.&lt;br /&gt;&lt;br /&gt;The receptionist I was directed to was also helpful, showing where I needed to go, arranging a shuttle bus, providing a visitor's badge and directions, and a fruit juice (Google have large fridges full of &lt;a href="http://www.nakedjuice.com/"&gt;Naked&lt;/a&gt; juice in every lobby I saw. They also have more exotic flavors available than I have seen anywhere before or since).&lt;br /&gt;&lt;br /&gt;Passing by the truck that had come to provide cheap haircuts to staff, I proceeded by a central courtyard which had a full sized Tyrannosaurus Rex skeleton (with &lt;a href="http://blogs.sun.com/jag/entry/rip_pink_flamingo_1957_2006"&gt;pink flamingo&lt;/a&gt; in it's mouth - several of it's cousins scattered the lawn) and a large sign proclaiming that there would be a Farmers' Market there at 11am that day.&lt;br /&gt;&lt;br /&gt;One bus trip later, I was where I needed to be, and being given a tour of the building. The variety of free coffee and other beverages was really impressive, as was the local version of Google's famous cafeterias. But the thing that really got me was seeing a projected list of Google's text searches scrolling up the wall. These are not done in real time (they would go by too fast) and have been filtered for inappropriate content (no searches for pornography, for instance), but they still served to drive home exactly where you were. This was ground zero. Those searches were resolved &lt;strong&gt;here&lt;/strong&gt;.&lt;br /&gt;&lt;br /&gt;The queries were also interesting to watch go by. There were questions on movies, Britney Spears, medical conditions, landmarks, and many questions in foreign languages, some of which were in foreign character sets, like Simplified Chinese. Watching these going by, it is immediately apparent where ideas like &lt;a href="http://www.google.com/zeitgeist"&gt;Google Zeitgeist&lt;/a&gt; came from.&lt;br /&gt;&lt;br /&gt;I then went on to have my interviews. There were about 4 of them, with a break for lunch which I had with one of the people I'd had a phone interview with. While a few of the questions were more general, most of them were about how I'd solve programming problems, with an emphasis on doing things to a "Google level of scaling". Funnily enough, my last few years of Mulgara work were perfect for this. On a couple of occasions I even found myself describing code I had written, rather than describing an abstract answer. I also got the chance to ask more about how Google works, and what it's like to be there. I was impressed by everyone's enthusiasm for their work, and for the company culture in general. A couple of people I spoke with also had children, and while they admitted that in the past Google had not been very good at supporting people with young children, in recent years this had improved significantly. But the thing that everyone talked about the most was the "perks". These extend into areas you couldn't imagine, and they are constantly evolving. Unlike most companies who occasionally institute a perk for their staff, possibly guided by a suggestion box, Google has a department whose sole mission it is to identify and implement perks.&lt;br /&gt;&lt;br /&gt;Finally the day came to an end, and I was able to head up to San Francisco. I had a very enjoyable evening with &lt;a href="http://fotap.org/~osi/"&gt;Peter&lt;/a&gt; and Trish, and the next day spent several hours having Mulgara discussions with Amit and Ronald at &lt;a href="http://www.topazproject.org/"&gt;Topaz&lt;/a&gt;. I was very pleased to get in this last meeting, and had shuffled things around with Google to make sure it could happen.&lt;br /&gt;&lt;br /&gt;As most of my friends know, a few weeks later Google made me an offer. While the base salary was simple enough, I was bemused at the complexity of the arrangements for paying bonuses, stock options, and common stock. It is the first job offer I've ever had that came with a set of equations attached. While not going into details, I &lt;em&gt;will&lt;/em&gt; say that it was very lucrative - if you came close to meeting your goals. I hadn't really considered accepting an offer until this point, but an offer like that would make anyone seriously reconsider. Consequently I agonized over this for a couple of weeks, right up to the deadline that Google set. In the meantime, I visited the Chicago site (where I insisted I would want to work, despite being asked several times if I'd move to Mountain View), and again was impressed with their setup. In fact, I've had a few people suggest that the setup at Mountain View is getting a little out of control in some ways, but this was not an issue for Chicago at all.&lt;br /&gt;&lt;br /&gt;I finally decided to turn Google down, and let them know as soon as I got back from Thanksgiving. I'd had advice from a few people, including some from inside of Google, who all pointed out that my work in the Semantic Web would be totally subsumed by working at Google. I had thought to do something with the "&lt;a href="http://googleblog.blogspot.com/2006/05/googles-20-percent-time-in-action.html"&gt;20% projects&lt;/a&gt;" that Google is known for, but it was pointed out that because bonuses are based on meeting (and exceeding) goals, then the option to use 20% of your time on something not related to your immediate work was often forgone. You also have to wonder how much of your bonuses, options, and common stock you'd get to see if you tried to keep a balanced lifestyle and didn't achieve your annual goals (apparently these are supposed to be set at a level that is challenging to achieve).&lt;br /&gt;&lt;br /&gt;Another serious consideration was one I hadn't expected. Despite having signed an &lt;acronym title="Non Disclosure Agreement"&gt;NDA&lt;/acronym&gt;, I learned nothing about Google that isn't already known to the public. Consequently, to an outsider it looked like the company was not doing anything really "interesting". I'm sure they are, but there was nothing inspiring about what they had to tell me. For most of the things I considered to be "cool" technology, I was told that those things were pretty much done, and the work they now do is in different areas altogether. In fact, the majority of the people I spoke to worked in AdWords and Billing. They were very enthusiastic about their work, and given the novelty of their service and the scale they have to work at, then I'm sure it's challenging and interesting work, but it didn't inspire me at all.&lt;br /&gt;&lt;br /&gt;Most of all, I've spent my career working with people who know a lot more than I do, to my enjoyment and benefit, and yet, no one I spent time with really impressed me with their knowledge of skills. Don't get me wrong - they were all quite competent and intelligent people. But I really expect something special out of the people I work with, if they are to bring out the best in me. Now I &lt;em&gt;know&lt;/em&gt; that Google has employed some of the brightest people in the industry, but the sheer size of the company convinced me that I'm unlikely to find myself working with those people.&lt;br /&gt;&lt;br /&gt;For those not paying attention, these last few paragraphs are all a means of justifying to myself that I made the right choice. It wasn't an easy choice to make, since Google &lt;em&gt;does&lt;/em&gt; seem like a cool company, the perks were huge, and the remuneration was potentially substantial. But I'm pretty sure I did the right thing, and as one friend said, he thinks it is &lt;em&gt;much&lt;/em&gt; cooler to say that you've turned down a Google offer than to have accepted one.  :-)&lt;br /&gt;&lt;h3&gt;Fedora Commons&lt;/h3&gt; Coming up to Christmas, I was finally getting a chance to do some Mulgara work during office hours. This was a huge thing for me, as I had been getting more and more frustrated about it for the previous two years when I was supposed to be doing this. Then in the final days before Christmas my boss, and several others I worked with in fourthcodex, decided that they wanted to do something different in semantic technologies, and resigned. Without a team to work with, there wasn't a lot of scope for me to do semantic work any more, and I was told to stop working on Mulgara again. &lt;em&gt;Sigh&lt;/em&gt;.&lt;br /&gt;&lt;br /&gt;While some semantic options were being pursued, the fact remained that Herzum Software desperately needed some more senior coders, and it looked very much like I would end up on projects that were of little interest to me. A notable one here was a .Net project that would have me working on site in Pittsburgh. This was something that nobody wanted, including my family, and everyone I was working with on Mulgara.&lt;br /&gt;&lt;br /&gt;Talis tried to help at this point (and I'm very grateful that they did), but their interim solution would have made it illegal for Anne to keep her &lt;a href="http://www.rumsumsum.com/"&gt;new business&lt;/a&gt; running, and I couldn't do that to her. But then, &lt;a href="http://www.topazproject.org/"&gt;Topaz&lt;/a&gt; and &lt;a href="http://www.fedora-commons.org/"&gt;Fedora Commons&lt;/a&gt; came back to me with an offer to work for them (which distinct organizations, there is an administrative relationship between them, and both are contributing to the &lt;a href="http://www.plos.org/"&gt;Public Library of Science&lt;/a&gt;). I've already written about my decision to accept this, which brings me up to today.&lt;br /&gt;&lt;br /&gt;I've officially been working for Fedora Commons for about a month now. I've been dividing my time between the &lt;a href="http://www.w3.org/TR/rdf-sparql-query/"&gt;SPARQL&lt;/a&gt; implementation and responding to support and debugging requests. However, this week has been different. We got all the developers from Topaz and Fedora Commons together, to discuss our plans for the year, and how to manage the process. Mulgara has also been generating some more external interest again, and since we form the core of the active developers, we wanted to discuss ways in which we can work with the community, particularly developers.&lt;br /&gt;&lt;h3&gt;Features&lt;/h3&gt; The most important features we are implementing in the coming year are SPARQL, multiple concurrent writers, and significantly greater scalability. We have been talking about the last one for a long time, but no one has had the time (or money) to do anything about it. This has now changed, and the work is commencing very soon now. It's been a long time in coming, so I'm quite inspired to get it done now.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://netymon.blogspot.com/"&gt;Andrae&lt;/a&gt; was present for the meeting, and presented some very impressive results to his research on transactionality for multiple writers on an &lt;acronym title="Resource Description Framework"&gt;RDF&lt;/acronym&gt; graph. Not only has he demonstrated a mathematically sound foundation for this work, but he has also included an impressive level of engineering for scalability in his designs.&lt;br /&gt;&lt;br /&gt;In the meantime, I have come up with a new scheme for indexing RDF, which appears to have significantly better complexity results than what we currently do. Fortunately, the majority of this work is orthogonal to Andrae's designs, with the consequence that the improvement to scalability will be cumulative between both redesigns. I'm pretty chuffed at this.  :-)  I will be writing more on the indexing shortly, but I have been under some pressure to write this up as an academic paper as well, so that may take priority over my blog.&lt;br /&gt;&lt;br /&gt;Significantly, we had James Leigh from &lt;a href="http://www.aduna-software.com/"&gt;Aduna&lt;/a&gt; at the meeting as well. Aduna are the company behind the &lt;a href="http://www.openrdf.org/"&gt;Sesame RDF store&lt;/a&gt;, which has been one of the big open source alternatives to Mulgara. They are interested in merging our systems to a certain extent, to the benefit of both. After hearing James out, it sounds like a really good idea (though I may end up throwing away the SPARQL parsing that I've finished - &lt;em&gt;sigh&lt;/em&gt; again). I'm not sure when it will happen as everyone as a lot of immediate priorities to get through, but everyone has expressed support for implementing the &lt;a href="http://www.openrdf.org/doc/sesame2/api/org/openrdf/sail/package-summary.html"&gt;SAIL&lt;/a&gt; API on Mulgara. This is very significant for us, as it will provide a host of new reasoning features, the ability for existing Sesame users to easily try Mulgara, and a SPARQL protocol interface (I'd just been working on the query language for the moment). In turn, I'm hoping that we can demonstrate these new levels of scalability and concurrency for Sesame.&lt;br /&gt;&lt;br /&gt;A lot more came out of the meeting, but that was the crux of it. Rather than pre-empt some of the things that are still in motion, I'll let others explain their end of things.&lt;br /&gt;&lt;br /&gt;I'm very happy to see this level of interest in Mulgara, and I'm excited to see all these new features starting to be realized at last.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6848574-903178916431797225?l=gearon.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://gearon.blogspot.com/feeds/903178916431797225/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=6848574&amp;postID=903178916431797225" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6848574/posts/default/903178916431797225?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6848574/posts/default/903178916431797225?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/WorkingNotes/~3/VoULl9SiF_w/review-you-know-youve-been-lax-keeping.html" title="" /><author><name>Quoll</name><uri>http://www.blogger.com/profile/03653112583629043593</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="17348260940898309335" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://gearon.blogspot.com/2008/03/review-you-know-youve-been-lax-keeping.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0EFR38_cCp7ImA9WxZSEkk.&quot;"><id>tag:blogger.com,1999:blog-6848574.post-3307821216995406546</id><published>2008-01-24T23:41:00.000-06:00</published><updated>2008-01-25T00:13:36.148-06:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-01-25T00:13:36.148-06:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="JRDF" /><category scheme="http://www.blogger.com/atom/ns#" term="Mulgara" /><title /><content type="html">&lt;h3&gt;More Correspondence&lt;/h3&gt; Going back through my emails with Andy, I realize there's still a lot that might be of interest to include here. Hopefully the parts I choose to copy/paste don't appear to disjoint.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;JRDF&lt;/h3&gt; Andy was confused about the role of &lt;a href="http://jrdf.sourceforge.net/"&gt;JRDF&lt;/a&gt; in Mulgara, as well he might be. He was trying to work with a minimal set of classes, yet he kept needing JRDF even when he wasn't using the JRDF interfaces.&lt;br /&gt;&lt;br /&gt;You can think of JRDF as having 2 faces.  First, it provides definitions for classes that represent RDF nodes - URIResource, Literal, BlankNode.  Second, there's an interface for inserting and querying for RDF statements.  Initially, someone decided to use JRDF as the definition for nodes (I think it was Andrew, and I think he chose to use it since he'd already written this code while he was at home, and it made sense for him to reuse it).  Some time later, Andrew decided that the interfaces for manipulating and querying for statements should also be implemented, since we were already using the JRDF code. (Now this is in my blog, I'm sure Andrew will clarify this point!)&lt;br /&gt;&lt;br /&gt;So internally, yes we use JRDF.  It's mostly for the interfaces and abstract classes associated with &lt;code&gt;URIResource&lt;/code&gt;, &lt;code&gt;Literal&lt;/code&gt;, and &lt;code&gt;BlankNode&lt;/code&gt;.  There are also interfaces for &lt;code&gt;SubjectNode&lt;/code&gt;, &lt;code&gt;PredicateNode&lt;/code&gt;, and &lt;code&gt;ObjectNode&lt;/code&gt; which are used when putting triples in and out of Mulgara.  At the lower levels, Mulgara is 100% symmetric around all 4 nodes (it used to be 3 nodes, but as most people should know now, we moved it up to 4).  However, when the data gets pushed through these interfaces, this imposes certain type restrictions.  This is why Mulgara won't let you use a literal as a subject, or a blank node as a predicate.&lt;br /&gt;&lt;br /&gt;For this reason, you'll need the JRDF classes, even if you never use the JRDF interfaces.  Yes, I know it's annoying.  One of the many reasons I want to reimplement a lot of Mulgara (another big reason is that I want to use a less restrictive licence - specifically &lt;a href="http://www.opensource.org/licenses/apache2.0.php"&gt;Apache&lt;/a&gt;).&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Blank Nodes&lt;/h3&gt; Blank nodes can have any label an implementor chooses to use, so long as it meets certain criteria. In Mulgara, they are shown as an underscore, colon, and then a number. Andy was trying to figure out the significance of the numbers shown here, and how they get allocated.&lt;br /&gt;&lt;br /&gt;These numbers are actually the raw graph node identifiers (a 64 bit &lt;em&gt;long&lt;/em&gt;), or &lt;em&gt;gNodes&lt;/em&gt;. All gNodes are allocated from the Node Pool, which is just a Free List.&lt;br /&gt;&lt;br /&gt;... describing free lists..... Oh boy.....&lt;br /&gt;&lt;br /&gt;To start with, any new requests for gNodes just come from an incrementing long.  However, if you ever delete all the statements that use a gNode, then that gNode will be "released", meaning that it's added to the FreeList.  So now, whenever you ask for a new gNode, the FreeList will try to give you any released gNodes first before it returns the incremented internal long value.&lt;br /&gt;&lt;br /&gt;However, that's a vast simplification.  If you released a gNode in the current transaction, then these will be given back to you first (until exhausted).  Next, it will try to give you any nodes released in old transactions that are not part of a currently "open" result set.  Once all open resources that refer to a set of gNodes have been closed, then the FreeList is able to hand them out.  Finally, it uses the incrementing long.&lt;br /&gt;&lt;br /&gt;All of this reflects the 32 bit thinking that the system started with.  There is little need to re-use gNode values when you have a 64 bit system (if you allocate a gNode every millisecond, then it will take you half a billion years to use them all up, so I think we're safe).  We need to update it, but unfortunately, there are arrays which are indexed by the gNode ID, meaning we can't just increment the long all the time.  With the 32 bit approach this was OK, since the ID values were packed from the bottom.  But if we move to an incrementing number for gNodes (simplifying things greatly - and speeding them up) then we will need a new on-disk structure for this array.&lt;br /&gt;&lt;br /&gt;OK, this isn't describing Mulgara now. It's really my recent musings on making it all faster.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;The Server&lt;/h3&gt; Andy was waiting for the server to start up, and his TQL client appeared to be getting confused with the intermediate startup state. There wasn't a lot said here, but I want to reiterate it anyway.&lt;br /&gt;&lt;br /&gt;IMHO The server is WAY too heavy.  I'm all for the services provided... but I think they need to be provided in an external framework, and let the database be a module that gets loaded by that framework.  The fact that it starts so many services really bothers me.  I'd fix this, if I had time.&lt;br /&gt;&lt;br /&gt;Mind you, I'm being a bit harsh when I say "fix".  It works.  It's just I believe it needs to be made of smaller parts, which are either independent, or build on one another.  The current server is monolithic.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6848574-3307821216995406546?l=gearon.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://gearon.blogspot.com/feeds/3307821216995406546/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=6848574&amp;postID=3307821216995406546" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6848574/posts/default/3307821216995406546?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6848574/posts/default/3307821216995406546?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/WorkingNotes/~3/Js-JgGtCHC0/more-correspondence-going-back-through.html" title="" /><author><name>Quoll</name><uri>http://www.blogger.com/profile/03653112583629043593</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="17348260940898309335" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://gearon.blogspot.com/2008/01/more-correspondence-going-back-through.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A0EMQH45cCp7ImA9WxZSEk4.&quot;"><id>tag:blogger.com,1999:blog-6848574.post-1475954423439578881</id><published>2008-01-24T22:40:00.000-06:00</published><updated>2008-01-24T23:41:21.028-06:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-01-24T23:41:21.028-06:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="performance" /><category scheme="http://www.blogger.com/atom/ns#" term="memory map" /><category scheme="http://www.blogger.com/atom/ns#" term="RDF" /><title /><content type="html">&lt;h3&gt;Current Work&lt;/h3&gt; Since I can't do much at work during my "two weeks notice", I've been asked to stay at home this week. I'm still being paid, and have to be available if I'm needed, but in reality it's just a holiday. With the visa interview next week I'm not as relaxed as I'd like, but it's been a good week. I've enjoyed spending more time with Anne and the boys, along with my mother-in-law, who left here on Tuesday. But after having a few days to clear my head, I'm trying to get back to Mulgara. Unfortunately, my new computer has not arrived yet, so I'm back to my old G4 PowerBook in the meantime. It's fine for use with &lt;a href="http://www.vim.org/"&gt;VIM&lt;/a&gt; and even Safari, but it's choking whenever I try to do real work on it.&lt;br /&gt;&lt;br /&gt;I've spent a couple of days trying to catch up on email, and now I'm looking at getting back to actual coding. I &lt;em&gt;should&lt;/em&gt; be doing SPARQL (and I'm looking forward to that), but I allowed myself to get side-tracked on some performance code.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;String Pools&lt;/h3&gt; Indy offered to do some profiling of a large load, and immediately came back to show me that we spend most of our time reading the string pool. This makes sense, as every triple that gets inserted needs to be "localized" into internal graph nodes (&lt;em&gt;gNodes&lt;/em&gt;). This means searching for the URI or literal, and getting back the associated gNode, or creating one if it doesn't exist.&lt;br /&gt;&lt;br /&gt;There are two ways to index something like a string and map it to something else. You can use a hashmap, or a tree. Hashmaps are much faster with constant complexity, but have a number of problems. They take up a lot of disk space, they can be expensive if they need to expand, and they provide no ordering, making it impossible (well, not impossible, but you have to do tricky things) to get ranges of values.  Trees don't suffer from any of these problems, but they have logarithmic complexity, and require a lot of seeking around the disk.&lt;br /&gt;&lt;br /&gt;For the moment, the string pool maps URIs and literals to gNodes by storing them in a tree. It's an AVL tree, to reduce write complexity to O(1), though we don't store multiple values per node (unlike the triple indices), meaning the tree is very deep.&lt;br /&gt;&lt;br /&gt;The code has many, many possibilities for optimization. We'll be re-architecting this soon in XA2 (there's going to be a big meeting about it in SF next month), but for the moment, we're working with what we have.&lt;br /&gt;&lt;br /&gt;The first thing that Indy noticed was some code in &lt;code&gt;Block.get(int,ByteBuffer)&lt;/code&gt;. This was iterating its way through copying bytes from one buffer to another. This seems ludicrous, especially when the documentation to &lt;a href="http://java.sun.com/javase/6/docs/api/java/nio/ByteBuffer.html#put(java.nio.ByteBuffer)"&gt;ByteBuffer.put(ByteBuffer)&lt;/a&gt; explicitly describes how it is faster than doing the same thing in an iterative loop. A simple fix to this apparently sped up loads by 30%! I wasn't profiling this, so I can't vouch for it, but Indy seemed certain of the results.&lt;br /&gt;&lt;br /&gt;Initially I had though that this couldn't have been code from David an myself, but I checked back in old versions of Kowari, and it's there too. All I can think of is that one of us must have been sick, and the other absent. At least it's fixed. I've also noticed a couple of other places where iterative copies seem to be happening. I'd like to fix them, but there may be no point. Instead I'll let the profiler guide me.&lt;br /&gt;&lt;br /&gt;After thinking about it for a while, I started wondering why one buffer was being copied into another in the first place. The AVL trees in particular are memory mapped, whenever possible, and memory mapping is explicitly supposed to avoid copying between buffers. Buffer copies may seem cheap compared to disk seeks, but these are regularly traversed indices, so the majority of the work will be done in cached memory.&lt;br /&gt;&lt;br /&gt;A little bit of inspection showed me what was going on. The first part of a URI or strong (or any kind of literal) is kept in the AVL tree, while anything that overflows 72 bytes is kept in another file. The code that does comparisons loads the first part of the data into a fresh buffer, and appends the remainder if it exists, before working with it. However, much of the time the first part is all that is needed. When this is the case there is no need to concatenate 2 separate buffers together, meaning that the original (hopefully memory mapped) buffer can be used. I fixed this in one place, but I think it's appearing in other areas as well. I'll have to work through this, but again I shouldn't go down any paths that the profiler doesn't deem necessary.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Dublin Core PURL&lt;/h3&gt; After making my adjustments, I tried running the tests, and was upset to see that 5 had failed. This seemed odd, since I'd worked on such fundamental code that a failure in my implementation should have prevented anything from working at all, rather than stopping only 5 tests. I had to go out this morning, so it bothered me for hours until I could check the reason.&lt;br /&gt;&lt;br /&gt;It turned out that the problem was coming from tests which load RDF from a URL: &lt;a href="http://purl.org/dc/elements/1.1"&gt;http://purl.org/dc/elements/1.1&lt;/a&gt;. &lt;a href="http://purl.org/"&gt;Purl.org&lt;/a&gt; is the home of persistent URLs, so if a document ever changes location, the URL for it does not need to be changed. So using this URL in a test seems appropriate, providing you can assume an internet connection while testing. But unexpectedly, the contents of this file changed just last week, which led to the problems.&lt;br /&gt;&lt;br /&gt;Given that this is a document describing a standard for Dublin Core, and given that it has a version associated with it, I am startled to see that the contents of the file changed. Shouldn't the version number increase? While I find it bizarre, at least I found it before people started complaining about it. It will be in the next release.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Moving On&lt;/h3&gt; Now that I've addressed the initial profiling black spots, I can move on to the things I ought to be doing, namely SPARQL (being an engineer I would prefer to be squeezing every last drop of performance out of this thing, but I have to manage priorities). I have to talk to a few people about Mulgara tomorrow, but aside from that, I'll be working in the JavaCC file most of the day.... I hope.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6848574-1475954423439578881?l=gearon.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://gearon.blogspot.com/feeds/1475954423439578881/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=6848574&amp;postID=1475954423439578881" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6848574/posts/default/1475954423439578881?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6848574/posts/default/1475954423439578881?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/WorkingNotes/~3/BKa0GsNeI2w/current-work-since-i-cant-do-much-at.html" title="" /><author><name>Quoll</name><uri>http://www.blogger.com/profile/03653112583629043593</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="17348260940898309335" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total><feedburner:origLink>http://gearon.blogspot.com/2008/01/current-work-since-i-cant-do-much-at.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0YNRnwyfip7ImA9WxZTEkQ.&quot;"><id>tag:blogger.com,1999:blog-6848574.post-8515229346979139052</id><published>2008-01-13T17:39:00.000-06:00</published><updated>2008-01-14T00:13:17.296-06:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-01-14T00:13:17.296-06:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="pool" /><category scheme="http://www.blogger.com/atom/ns#" term="AVL" /><category scheme="http://www.blogger.com/atom/ns#" term="JavaCC" /><category scheme="http://www.blogger.com/atom/ns#" term="CST" /><category scheme="http://www.blogger.com/atom/ns#" term="AST" /><category scheme="http://www.blogger.com/atom/ns#" term="SPARQL" /><category scheme="http://www.blogger.com/atom/ns#" term="architecture" /><category scheme="http://www.blogger.com/atom/ns#" term="Mulgara" /><title /><content type="html">&lt;h3&gt;Mulgara Correspondence&lt;/h3&gt; Recently I've been in a few email discussions with &lt;a href="http://seaborne.blogspot.com/"&gt;Andy Seaborne&lt;/a&gt; about the architecture of Mulgara. He's been looking at a new &lt;a href="http://seaborne.blogspot.com/2008/01/jena-mulgara-example-of-implementing.html"&gt;Jena-Mulgara bridge&lt;/a&gt;, but when he's had the time it appears he's been looking into how Mulgara works. There are certainly areas where Mulgara could be a &lt;em&gt;lot&lt;/em&gt; better (distressingly so), so we will be changing a number of things in the not-to-distant-future. But in the meantime I'm more than happy to explain how things currently work. It's been a worthwhile exchange, as Andy knows what he's on about, so he's given me some good ideas. It's also nice to talk about some of the issues with indexing with someone who understands the needs, and can see the trade offs.&lt;br /&gt;&lt;br /&gt;Since I wrote so much detail in some of these emails, I asked Andy (just before he suggested it himself) if he'd mind me posting some of the exchange up here. One could argue that if I hadn't been writing to him then I'd have had the time to write here, but the reality is that his questions got me moving whereas the self-motivation required for blogging has failed me of late.&lt;br /&gt;&lt;br /&gt;There will be a lack of context from the emails, but hopefully I'll be able to edit it into submission. I should also issue a warning that what I wrote presumes you have some idea of what RDF is, and that you can look at the &lt;a href="http://mulgara.org/svn/mulgara/trunk/"&gt;Mulgara code&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;AVL Trees&lt;/h3&gt; If you want to keep read/write data on disk, and have it both ordered and efficient to search at the same time, then a &lt;a href="http://www.nist.gov/dads/HTML/tree.html"&gt;tree&lt;/a&gt; is usually the best approach.  There are other things you can do, but they all involve a tradeoff.  Trees are usually considered the best thing to go with.&lt;br /&gt;&lt;br /&gt;Databases usually have &lt;a href="http://www.nist.gov/dads/HTML/btree.html"&gt;B-trees&lt;/a&gt; of some type (there are a few types). These work well, but Mulgara instead opted to go with &lt;a href="http://www.nist.gov/dads/HTML/avltree.html"&gt;AVL trees&lt;/a&gt;, with a sorted list associated with each node. This structure is much more efficient for writing data, but less efficient for deletion. This suits us well, as RDF is often loaded in bulk, and it gets updated regularly, but bulk deletions are less frequent. I mention the complexity of this later on.&lt;br /&gt;&lt;br /&gt;Andy asked about our AVL trees, with comments showing that he was only looking at one of their uses.  I think that understanding a particular application of this structure is easier if the general structure is understood first.&lt;br /&gt;&lt;br /&gt;AVL trees are used in two places: The triple indexes (indices), and the "StringPool" (which is really an Object pool now).&lt;br /&gt;&lt;br /&gt;The trees themselves don't hold large amounts of data.  Instead each node holds a "payload" which is specific to the thing they are being used to index.  In the case of the "triples" indexes, this payload includes:&lt;ul&gt;&lt;li&gt;The number of triples in the block being referenced.&lt;/li&gt;&lt;li&gt;The smallest triple stored in the block.&lt;/li&gt;&lt;li&gt;The largest triple stored in the block.&lt;/li&gt;&lt;li&gt;The ID of the 8K block where the triples are stored (up to 256 of them).&lt;/li&gt;&lt;/ul&gt;I'm only using the word "triple" because that's what we stored once upon a time (circa 2001).  In reality, we store quads.  On the first pass, the fourth value was a set of security values, but this quickly became a graph ID.  Unfortunately, this happened back when everyone referred to graphs as "models", so you'll see the code uses the name "model" instead of "graph" everywhere.  (I'd like to change this).&lt;br /&gt;&lt;br /&gt;There is also some inefficiency, as we use a lot of 64 bit values, which means that there are a lot of bits set to zero.  There are plans to change the on-disk storage this year to make things much more efficient.  Fortunately, the storage is completely modular, so all we need to do to use a new storage mechanism is to enter the factory classes into an XML configuration file.&lt;br /&gt;&lt;br /&gt;The code in &lt;code&gt;org.mulgara.store.statement.xa.XAStatementStoreImpl&lt;/code&gt;, shows that there are 6 indices.  These are ordered according to "columns" 0, 1, 2, and 3, with the following patterns:  0123, 1203, 2013, 3012, 3120, 3201.  The numbers here are just a mapping of:  Subject=0, Predicate=1, Object=2, Model=3.  Of course, using this set of indices lets you find the result of any "triple pattern" (in SPARQL parlance) as a range inside the index, with the bounds of the range being found with a pair of binary searches.&lt;br /&gt;&lt;br /&gt;We use AVL trees because they are faster for writing than B-Trees.  This is because they have an O(1) complexity for write operations when doing insertions.  They can have O(log(n)) complexity while deleting, but since RDF is supposed to be about asserting data rather than removing it, then the extra cost is usually OK.  :-)&lt;br /&gt;&lt;br /&gt;The other important thing to know about Mulgara AVL trees is that they are stored in &lt;em&gt;phases&lt;/em&gt;.  This means we have multiple roots for the trees, with each root representing a &lt;em&gt;phase&lt;/em&gt;.  All phases are read-only, except the most recent.  The moment a phase updates a node, then it does a copy-on-write for that node, and all parents (transitively) up to a node that has already been copied for the current phase, or the root (whichever comes first).  In this way, there can be multiple representations of the data on disk, meaning that old read operations are always valid, no matter what write operations have occurred since then.  Results of a query are therefore referencing phases, the nodes of which can be reclaimed and reused when the result is closed, or garbage collected (we log a warning if the &lt;acronym title="Garbage Collector"&gt;GC&lt;/acronym&gt; cleans up a phase).&lt;br /&gt;&lt;br /&gt;Because all reads and writes are done on phases, the methods inside &lt;code&gt;TripleAVLFile&lt;/code&gt; are of less interest than the methods in the inner class &lt;code&gt;TripleAVLFile.Phase&lt;/code&gt;.  Here you will find the find methods that select a range out of an index, based on one, two, or three fixed values.&lt;br /&gt;&lt;br /&gt;The String Pool also uses an AVL tree (just one), though it has a very different payload.  However, the whole phase mechanism is still there.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Object Pool&lt;/h3&gt; Andy noted that the comments for the &lt;code&gt;ObjectPool&lt;/code&gt; class say that it is for reducing constructor overhead, but a cursory inspection revealed that they did more.&lt;br /&gt;&lt;br /&gt;There's some complexity to avoid pool contention between multiple threads.  Each pool contains an array of "type pools" (see the inner type called &lt;code&gt;ObjectStack&lt;/code&gt;), indexed by an (manually) enumerated type.  You want an object of type ID=5, then you go to element 5 in that array, and you get a pool for just that type.  This pool is an &lt;code&gt;ObjectStack&lt;/code&gt;, which is just an array that is managed as a stack.&lt;br /&gt;&lt;br /&gt;Whenever a new &lt;code&gt;ObjectPool&lt;/code&gt; is created it is chained onto a singleton &lt;code&gt;ObjectPool&lt;/code&gt; called the &lt;code&gt;SHARED_POOL&lt;/code&gt;.  To avoid a synchronization bottleneck, each thread uses the pool that it created, but will fall back to using the "next" pool in the chain (almost always the &lt;code&gt;SHARED_POOL&lt;/code&gt;) if it has run out of objects for some reason.  Since this is only a fallback, then there shouldn't be much waiting.&lt;br /&gt;&lt;br /&gt;I know that some people will cringe at the thought of doing object pooling with modern &lt;acronym title="Java Virtual Machine"&gt;JVM&lt;/acronym&gt;s. However, when Mulgara was first written (back when it was called &lt;acronym title="Tucana Knowledge Store"&gt;TKS&lt;/acronym&gt;) this sort of optimization was essential for efficient operation. With more recent JVMs, we have been advised to drop this pooling, but there have been a few reasons to hold back on making this change. First, we have tried to maintain a level of portability into new versions of the JVM (this is not always possible, but we have tried nonetheless), and this change could destroy performance on an older JVM. Second, we do some level of caching of objects while pooling them. This means that we don't always have to initialize objects when they are retrieved. Since some of this initialization comes from disk, and we aren't always comfortable relying on the buffer cache having what we need, then this may have an impact. Finally, it would take some work to remove all of the pooling we do, and recent profiles have not indicated that it is a problem for the moment. I'd hate to do all that work only to find that it did nothing for us, or worse, that it slowed things down.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;32/64 Bits and Loading&lt;/h3&gt; Andy was curious about our rate of loading data on 32 bit system or 64 bit systems, given simple data of short literals and URIs (&lt;100 characters or so). Unfortunately, I didn't have many answers here.&lt;br /&gt;&lt;br /&gt;In 2004 Kowari could load 250,000,000 triples of the type described in under an hour on a 64 bit Linux box (lots of RAM, and a TB of striped disks).  However, it &lt;em&gt;seems&lt;/em&gt; that something happened in 2005 that slowed this down. I don't know for certain, but I've been really disappointed to see slow loads recently.  However, I don't have a 64 bit Linux box to play with at the moment, so it's hard to compare apples with apples.  After the SPARQL implementation is complete, profiling the loads will be my highest priority.&lt;br /&gt;&lt;br /&gt;64 bit systems (excluding Apples, since they don't have a 64 bit JVM) operate differently to 32 bit systems.  For a start, they memory map all their files (using an array of maps, since no single map can be larger than 2GB in Java).  Also, I &lt;em&gt;think&lt;/em&gt; that the "&lt;code&gt;long&lt;/code&gt;" native type is really an architecturally  native 64 bit value, instead of 2x32 bit values like they have to be on a 32 bit system.  Since we do &lt;strong&gt;everything&lt;/strong&gt; with 64 bit numbers, then this helps a lot.&lt;br /&gt;&lt;br /&gt;After writing this, Inderbir was able to run a quick profile on a load of this type. He immediately found some heavily used code in &lt;code&gt;org.mulgara.store.xa.Block&lt;/code&gt; where someone was doing a copy from one &lt;code&gt;ByteBuffer&lt;/code&gt; to another by iterating over characters. I cannot imagine who would have done this, since only DavidM and I have had a need to ever be in there, and we certainly would not have done this. I also note that the operation involves copying the contents of &lt;code&gt;ByteBuffer&lt;/code&gt;s, but this doesn't make a lot of sense either, since the class was built an an abstraction to avoid exactly that (whenever possible).&lt;br /&gt;&lt;br /&gt;I haven't seen the profile, but Inderbir said that a block copy gave him an immediate improvement of about 30%. I'd also like to check the stack trace to confirm if a block copy is really needed here anyway. Thinking about it, it might be needed for copying one part of a memory-mapped file to another, but it should be avoided for files that are being accessed with read/write operations.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Embedded Servers&lt;/h3&gt; Andy was also intrigued at the (sparse) documentation for Embedded Mulgara Servers. While on this track, he pointed out that &lt;code&gt;LocalSession&lt;/code&gt; has "DO NOT USE" written across it. I've seen this comment, but don't know why it's there. I should look into what &lt;code&gt;LocalSession&lt;/code&gt; was supposed to do. In the meantime, I recommended not worrying about it - I don't.&lt;br /&gt;&lt;br /&gt;The &lt;code&gt;Session&lt;/code&gt; implementation needed for local (non-client-server) access is &lt;code&gt;org.mulgara.resolver.DatabaseSession&lt;/code&gt;. It should be fine, as this is what the server is using.&lt;br /&gt;&lt;br /&gt;When doing &lt;acronym title="Remote Method Invocation"&gt;RMI&lt;/acronym&gt;, you use &lt;code&gt;RemoteSessionWrapperSession&lt;/code&gt;. I didn't name these things, but the standard here is that the part before "&lt;em&gt;Wrapper&lt;/em&gt;" is the interface being wrapped, and the thing after "&lt;em&gt;Wrapper&lt;/em&gt;" is the interface that is being presented. So &lt;code&gt;RemoteSessionWrapperSession&lt;/code&gt; means that it's a &lt;code&gt;Session&lt;/code&gt; that is a wrapper around a &lt;code&gt;RemoteSession&lt;/code&gt;.  The idea is to make the &lt;code&gt;Session&lt;/code&gt; look completely local.  The reason for wrapping is to pick up the &lt;code&gt;RemoteException&lt;/code&gt;s needed for RMI and convert them into local exceptions. At the server end, you're presenting a &lt;code&gt;SessionWrapperRemoteSession&lt;/code&gt; to RMI. This is wrapping a &lt;code&gt;Session&lt;/code&gt; to look like a &lt;code&gt;RemoteSession&lt;/code&gt; (meaning that all the methods declare that they throw &lt;code&gt;RemoteException&lt;/code&gt;). Obviously, from the server's perspective, the &lt;code&gt;Session&lt;/code&gt; being wrapped here must be local.  And the session that is local for the server is &lt;code&gt;DatabaseSession&lt;/code&gt;.  So to "embed" a database in your code, you use a &lt;code&gt;DatabaseSession&lt;/code&gt;.&lt;br /&gt;&lt;br /&gt;The way to get one of these is to create an &lt;code&gt;org.mulgara.resolver.Database&lt;/code&gt;, and call &lt;code&gt;Database.newSession()&lt;/code&gt;. Databases need a lot of parameters, but most of them are just configuration parameters that are handled automatically by &lt;code&gt;org.mulgara.resolver.DatabaseFactory&lt;/code&gt;.  Look in this factory for the method:&lt;pre&gt;&lt;code&gt; public static Database newDatabase(URI uri, File directory, MulgaraConfig config);&lt;/code&gt;&lt;/pre&gt;A &lt;code&gt;MulgaraConfig&lt;/code&gt; is created with using the URL of an XML configuration file.  By default, we use the one found in &lt;em&gt;conf/mulgara-x-config.xml&lt;/em&gt;, which is loaded into the jar:&lt;pre&gt;&lt;code&gt; URL configUrl = ClassLoader.getSystemResource("conf/mulgara-x-config.xml");&lt;br /&gt; MulgaraConfig config = MulgaraConfig.unmarshal(new InputStreamReader(configUrl.openStream()));&lt;br /&gt; config.validate();&lt;/code&gt;&lt;/pre&gt;(configUrl has a default of:  &lt;em&gt;jar:file:/path/to/jar/file/mulgara-1.1.1.jar!/conf/mulgara-x-config.xml&lt;/em&gt;)&lt;br /&gt;&lt;br /&gt;As an aside, it's supposed to be possible to do all of this by creating an &lt;code&gt;EmbeddedMulgaraServer&lt;/code&gt; with a &lt;code&gt;ServerMBean&lt;/code&gt; parameter that isn't doing RMI.  Unfortunately, there are no such &lt;code&gt;ServerMBeans&lt;/code&gt; available.  (Maybe I should write one?)&lt;br /&gt;&lt;br /&gt;Also, I believe that the purpose of the embedded-dist Ant target is to create a Jar that has these classes along with all the supporting code, but without anything related to RMI.  So the embedded Jar should be all you need for this, but I haven't used it myself, so I'm just making an educated guess.  :-)&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;SPARQL&lt;/h3&gt; Since I had been working on this up until mid-December, it is worth noting where I am with it.&lt;br /&gt;&lt;br /&gt;&lt;acronym title="Tucana Query Language"&gt;TQL&lt;/acronym&gt; includes graph names as a part of the query, and graph names have been URLs (not URIs) - meaning that they include information on how to find the server containing the graph.  Unfortunately, the guys who wrote TQL integrated the session management into the query parsing (if that doesn't make you shake your head in disbelief then you're a more forgiving person than I am).  I've successfully decoupled this, and now return an &lt;acronym title="Abstract Syntax Tree"&gt;AST&lt;/acronym&gt; that a session manager can work with.  This also means that graph names no longer have to describe the location of a server, meaning we can now support arbitrary URIs as graph names.  This now puts the burden on the session manager to find a server, but that's easy enough to set up with configuration, a registry, or scanning the AST for graph names if we want backward compatibility.&lt;br /&gt;&lt;br /&gt;The next part has been parsing SPARQL.  (Something that Andy should be intimately familiar with, given that his name is all over the &lt;a href="http://www.w3.org/TR/rdf-sparql-query/"&gt;documents&lt;/a&gt; I reference).&lt;br /&gt;&lt;br /&gt;With so many people talking about extensions to SPARQL, and after discussing this with a few other people, we decided to go with an &lt;a href="http://en.wikipedia.org/wiki/LALR"&gt;LALR parser&lt;/a&gt;.  This means I've had to write my own lexer/parser definition, instead of going with one of the &lt;a href="http://www.w3.org/2001/sw/DataAccess/rq23/parsers/"&gt;available definitions&lt;/a&gt;, like the &lt;a href="http://www.w3.org/2001/sw/DataAccess/rq23/parsers/sparql.jj"&gt;JavaCC definition&lt;/a&gt; written by Andy.  We do have &lt;a href="http://sablecc.org/"&gt;SableCC&lt;/a&gt; already in Mulgara, but everyone present agrees that this is a BAD LALR parser so I had to use something new.  I chose &lt;a href="http://beaver.sourceforge.net/"&gt;Beaver&lt;/a&gt;/&lt;a href="http://jflex.de/"&gt;JFlex&lt;/a&gt;.  It's going well, but I still have a lot of classes to write for the &lt;acronym title="Concrete Syntax Tree"&gt;CST&lt;/acronym&gt;.  The time taken to do this has me wondering if everyone is being a little too particular about the flexibility of an LALR solution, and maybe I should just go back to Andy's JavaCC definition. OTOH, I really like Beaver/JFlex and having an independent module that can do SPARQL using this parser may be a good thing.&lt;br /&gt;&lt;br /&gt;Fortunately the SPARQL spec now has a pretty good grammar specification and terminals, though one or two elements seemed redundant, and I've jumped over them (such as &lt;a href="http://www.w3.org/TR/rdf-sparql-query/#rPNAME_LN"&gt;PNAME_LN&lt;/a&gt;.  Instead I defined &lt;code&gt;IRIref ::= IRI_REF | PNAME_NS PN_LOCAL?&lt;/code&gt; ).  I've been getting some simple CSTs out of it so far, but have a way to go yet.&lt;br /&gt;&lt;br /&gt;Once I have it all parsing, of course, I have to transform the result into an AST.  Fortunately, most of the SPARQL AST is compatible with Mulgara.  The only exceptions are the &lt;a href="http://www.w3.org/TR/rdf-sparql-query/#termConstraint"&gt;FILTER&lt;/a&gt; operator (SPARQL's "constraints") and the &lt;a href="http://www.w3.org/TR/rdf-sparql-query/#optionals"&gt;OPTIONAL&lt;/a&gt; operator.  I'm pretty sure I can handle OPTIONAL as a cross between a disjunction (which can leave unbound variables) and conjunctions (which matches variables between the left and the right).  Filters should be easy, since all our resolutions are performed through nested, lazy evaluation of conjunctions and disjunctions.  Handling the syntax of filters is another matter, but I expect it to be more time consuming than difficult.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Holdup&lt;/h3&gt; Since writing these comments about implementing SPARQL, I haven't had time to work on it again. Hopefully that will change soon with the new job. But in the meantime, the loss of time has me thinking that I should reconsider using a pre-built SPARQL definition for a less expressive parser, and come back to Beaver/JFlex at a later date.&lt;br /&gt;&lt;br /&gt;I've heard that the &lt;a href="http://jena.sourceforge.net/"&gt;Jena&lt;/a&gt; JavaCC grammar may be a little heavily geared towards Jena, but I've been given another definition by my friend &lt;a href="http://fotap.org/~osi/"&gt;Peter&lt;/a&gt; which is more general and apparently passes all the relevant tests. I suppose I should go and learn &lt;a href="https://javacc.dev.java.net/"&gt;JavaCC&lt;/a&gt; now.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6848574-8515229346979139052?l=gearon.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://gearon.blogspot.com/feeds/8515229346979139052/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=6848574&amp;postID=8515229346979139052" title="3 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6848574/posts/default/8515229346979139052?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6848574/posts/default/8515229346979139052?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/WorkingNotes/~3/2NqepXwRPO4/mulgara-correspondence-recently-ive.html" title="" /><author><name>Quoll</name><uri>http://www.blogger.com/profile/03653112583629043593</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="17348260940898309335" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">3</thr:total><feedburner:origLink>http://gearon.blogspot.com/2008/01/mulgara-correspondence-recently-ive.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DE8ASXY8eip7ImA9WxZTEUs.&quot;"><id>tag:blogger.com,1999:blog-6848574.post-4851658162208329748</id><published>2008-01-12T12:22:00.000-06:00</published><updated>2008-01-12T13:40:48.872-06:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-01-12T13:40:48.872-06:00</app:edited><title /><content type="html">&lt;h3&gt;Work&lt;/h3&gt; Between the realities of working hours, young children, the need for exercise, etc, I just don't make the time to blog that I used to.  But the main reason I rarely blog now is because of my job. It can be hard to  know what you can talk about when you work in a closed source world. However, there have been a few changes here lately.&lt;br /&gt;&lt;br /&gt;In the latter part of last year, I was asked to write a SPARQL implementation for Mulgara. Two and a half years ago I was told I'd get to do a reasonable amount of Mulgara work, but when it came down to it I could only write for Mulgara in my evenings and weekends. I know that most open source developers are limited like this, but it's still not easy when you have small children. It was also frustrating, given that I had different expectations.&lt;br /&gt;&lt;br /&gt;So I was pleased to be given this new task. SPARQL is sorely needed, and I was more than happy to do it during working hours. Since I was back to open source work, I &lt;em&gt;could&lt;/em&gt; have blogged more, but I was trying to use all my spare moments on the computer to get ahead with the project. That isn't always as productive as it appears, as the process of blogging can really help with programming, but it can work for a short term push.&lt;br /&gt;&lt;br /&gt;Then just before Christmas, a number of people left the company I work for, including the guy who authorized me to work on Mulgara. So I was asked to stop, while everything was worked out. With all of the Semantic Web staff leaving except for me, the company can't really continue in this area. The word I was getting over the break was that the owner of the company didn't "know what to do" with me. I can speculate on what might happen as a result, but I won't do that here. It certainly wouldn't involve Mulgara work.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Fedora Commons&lt;/h3&gt; There is a lot I want to accomplish on Mulgara in the near term, as I think an open source framework with the capabilities we are aiming for will enable a number of significant developments. If I can participate in getting Mulgara there, then perhaps I can play a part in what happens later. To this end, I have accepted a position with &lt;a href="http://www.fedora-commons.org/"&gt;Fedora Commons&lt;/a&gt; to work on Mulgara full time.&lt;br /&gt;&lt;br /&gt;Fedora have been building their code on top of Mulgara (and Kowari before that) for some years. They work with the &lt;a href="http://www.topazproject.org/trac/"&gt;Topaz Project&lt;/a&gt; and together these groups have provided technical infrastructure for the &lt;a href="http://www.plos.org/"&gt;Public Library of Science&lt;/a&gt; (PLoS) (see the &lt;a href="http://www.plosone.org/"&gt;PLoS-ONE&lt;/a&gt; open access journal for an example of a deployment that uses Topaz and Fedora, along with Mulgara). I'm just starting to get a feel for the various relationships, so I'll leave the description there.&lt;br /&gt;&lt;br /&gt;The important thing from my perspective is that both Topaz and Fedora Commons have a charter that supports the use and deployment of open source software. Also, PLoS is about making research material available to the entire community, enabling research to reach everyone who should see it. Despite commercial interests to the contrary, there are many people who think this needs to happen (a good interview on this is &lt;a href="http://talk.talis.com/archives/2007/05/peter_murrayrus.html"&gt;here&lt;/a&gt;), as even the US government has &lt;a href="http://slashdot.org/article.pl?sid=07/12/27/0219228"&gt;made moves in this direction&lt;/a&gt;. So this work not only fits in with my own goals, it also helps enable something I really believe in.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Role&lt;/h3&gt; In the course of negotiating this position with Fedora Commons, I realized that an exact statement of my roles and responsibilities had not been made. So I thought about exactly what I'd &lt;strong&gt;like&lt;/strong&gt; to do, and proposed that. While I knew that our goals were aligned, I was still pleasantly surprised to have them come back and agree with me completely. I'm pretty happy about this... I've never been in a position to name exactly what I wanted to do before.  :-)&lt;br /&gt;&lt;br /&gt;So my work will basically come down to 3 things:&lt;ul&gt;&lt;li&gt;Mulgara development.&lt;/li&gt;&lt;li&gt;Consulting with Topaz and Fedora Commons on architecture and design.&lt;/li&gt;&lt;li&gt;Supporting and growing the Mulgara community.&lt;/li&gt;&lt;/ul&gt;Of course, all of these are to be done in alignment with Fedora Commons priorities, but this has already the case for some time with my after hours work (Fedora Commons and Topaz are the heaviest users of Mulgara at the moment). The second point I put in because I am always happy to do this whenever asked, and I think it is important to keep my hand in when it comes to the bigger picture. And the last point? Well, that's what makes this new position so cool.  :-)&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Visa&lt;/h3&gt; Of course, I need to get a new visa for the new position. Since visas are only issued expeditiously by a US consulate, then I need to travel to Canada in order to get it (it takes 6 months if I don't want to travel). It &lt;strong&gt;ought&lt;/strong&gt; to be easy, but if for some reason the application gets denied, then I'm not even allowed back in the USA in order to "settle my affairs". Of course, that would be a nightmare for Anne, having to pack up our house while looking after two children under 4. I understand the risk is small, but with such dire consequences I'm feeling a little nervous. I don't think I'll feel really happy about the new job until I have the visa paperwork that guarantees it for me.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Notice&lt;/h3&gt; So I've handed in my two weeks notice. I made sure I had met all my commitments before resigning, and my current boss is traveling overseas for 3 weeks starting tomorrow, so I have no idea what I'll be doing for the next 14 days. If I can, I'll start on SPARQL again. After all, the company I'm leaving is still using Mulgara in some of it's projects, so they'll still benefit from the work. I guess I'll find out for sure on Friday.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6848574-4851658162208329748?l=gearon.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://gearon.blogspot.com/feeds/4851658162208329748/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=6848574&amp;postID=4851658162208329748" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6848574/posts/default/4851658162208329748?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6848574/posts/default/4851658162208329748?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/WorkingNotes/~3/JpmQom7MYSc/work-between-realities-of-working-hours.html" title="" /><author><name>Quoll</name><uri>http://www.blogger.com/profile/03653112583629043593</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="17348260940898309335" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://gearon.blogspot.com/2008/01/work-between-realities-of-working-hours.html</feedburner:origLink></entry><entry gd:etag="W/&quot;AkAGQ346fyp7ImA9WB9VFkg.&quot;"><id>tag:blogger.com,1999:blog-6848574.post-4136427749824845787</id><published>2007-12-02T22:46:00.000-06:00</published><updated>2007-12-02T23:12:02.017-06:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2007-12-02T23:12:02.017-06:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="tragedy" /><title /><content type="html">&lt;h3&gt;Tragedy&lt;/h3&gt; This evening I heard some &lt;a href="http://www.cleveland.com/news/plaindealer/index.ssf?/base/cuyahoga/119658854495020.xml&amp;coll=2&amp;thispage=1"&gt;tragic news&lt;/a&gt;, involving &lt;a href="http://www.semantic-conference.com/2007/sessions/r3.html"&gt;Chimezie Ogbuji&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;I don't really know Chime, though I've met his brother &lt;a href="http://zepheira.com/team/uche/"&gt;Uche&lt;/a&gt; a few times (to quote a friend, "A very stylish man").  Anyone who follows the semantic web mailing lists will have seen numerous messages from both men.&lt;br /&gt;&lt;br /&gt;I just want to express my deepest condolences to the Ogbuji family.  I also sincerely hope that the youngest will recover.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6848574-4136427749824845787?l=gearon.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://gearon.blogspot.com/feeds/4136427749824845787/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=6848574&amp;postID=4136427749824845787" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6848574/posts/default/4136427749824845787?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6848574/posts/default/4136427749824845787?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/WorkingNotes/~3/0ch5IbZd6j0/tragedy-this-evening-i-heard-some.html" title="" /><author><name>Quoll</name><uri>http://www.blogger.com/profile/03653112583629043593</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="17348260940898309335" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total><feedburner:origLink>http://gearon.blogspot.com/2007/12/tragedy-this-evening-i-heard-some.html</feedburner:origLink></entry></feed>
