RDF::Query and optional patterns

Greetings! Thank you for all your work on RDF.rb, and for helping me build a new repository adapter.

While writing unit tests for RDF::Repository#query_execute, I ran into an interesting corner-case: Optional patterns did not seem to generate matches. After writing some unit tests, I discovered that the logic in RDF::Query#execute didn't implement optional patterns with same semantics as SPARQL. Since there weren't any existing specs for optional patterns, I decided that this was probably an incomplete implementation, added some specs, and tweaked RDF::Query#execute to get the same answers as SPARQL.

Once that was done, I noticed an interesting issue with the ordering of 'optional' clauses, consulted the SPARQL specification again, and decided to punt on the issue. See the patch description for a discussion of what's going on here.

The client funding this work states "unlicense is ok with us for RDF.rf patches you provide", and I agree to the following statement:

"I dedicate any and all copyright interest in this software to the public domain. I make this dedication for the benefit of the public at large and to the detriment of my heirs and successors. I intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law."

If you need more than that, I'll ask my client.

Thank you for reviewing my patch, and please don't hesitate to ask me to make changes! RDF.rb is a lovely library, and I'm delighted to be working with it.