<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Sparkles everywhere, CubicWeb gets fizzy (CubicWeb&#39;s Forge) RSS Feed</title>
    <description></description>
    <link>http://www.cubicweb.org/blogentry/344822</link>
<item>
<guid isPermaLink="true">http://www.cubicweb.org/blogentry/344822</guid>
  <title>Sparkles everywhere, CubicWeb gets fizzy</title>
  <link>http://www.cubicweb.org/blogentry/344822</link>
  <description>&lt;img alt=&quot;http://www.logilab.org/image/9845?vid=download&quot; class=&quot;align-right&quot; src=&quot;http://www.logilab.org/image/9845?vid=download&quot; style=&quot;width: 300px; height: 200px;&quot; /&gt;
&lt;p&gt;Last week, we finally took a few days to dive into &lt;a class=&quot;reference&quot; href=&quot;http://www.w3.org/TR/rdf-sparql-query/&quot;&gt;SPARQL&lt;/a&gt; in
order to transform any CubicWeb application into a potential
SPARQL endpoint.&lt;/p&gt;
&lt;p&gt;The first step was to get a parser. Fortunately
the w3c provides a &lt;a class=&quot;reference&quot; href=&quot;http://www.w3.org/TR/rdf-sparql-query/#grammar&quot;&gt;grammar&lt;/a&gt; definition and around 200 test
cases. There was a few interesting options around there: we
tried to reuse &lt;a class=&quot;reference&quot; href=&quot;http://www.rdflib.net/&quot;&gt;rdflib&lt;/a&gt;, &lt;a class=&quot;reference&quot; href=&quot;http://librdf.org/rasqal/&quot;&gt;rasqal&lt;/a&gt;, the &lt;cite&gt;sparql.g&lt;/cite&gt; version
designed for &lt;cite&gt;antlr3&lt;/cite&gt; and &lt;a class=&quot;reference&quot; href=&quot;http://simpleparse.sourceforge.net/&quot;&gt;SimpleParse&lt;/a&gt; but after two days of
work, we had nothing that worked well enough. We decided it was
not worth it and switched to &lt;a class=&quot;reference&quot; href=&quot;http://theory.stanford.edu/~amitp/yapps/&quot;&gt;yapps&lt;/a&gt; since we knew yapps and rql
already had a dependency on it.&lt;/p&gt;
&lt;p&gt;Maybe we&#39;ll consider changing the parser at some point later but
the priority was to get something working as soon as we could and
we finally came up with a version of &lt;a class=&quot;reference&quot; href=&quot;http://www.logilab.org/project/fyzz&quot;&gt;fyzz&lt;/a&gt; passing 90% of the
W3C test suite (of course, there might be some false positives).&lt;/p&gt;
&lt;p&gt;Fyzz parses the SPARQL query and generates something we decided to call an
AST although it&#39;s still a bit rough for now. Fyzz understands simple triples,
distincts, limits, offsets and other basic functionalities.&lt;/p&gt;
&lt;p&gt;Please note that &lt;a class=&quot;reference&quot; href=&quot;http://www.logilab.org/project/fyzz&quot;&gt;fyzz&lt;/a&gt; is &lt;strong&gt;totally independent of cubicweb&lt;/strong&gt; and it can
be reused by any project.&lt;/p&gt;
&lt;p&gt;Here&#39;s an example of how to use fyzz:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;fyzz.yappsparser&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;parse&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ast&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;parse&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;&amp;quot;&amp;quot;PREFIX doap: &amp;lt;http://usefulinc.com/ns/doap#&amp;gt;&lt;/span&gt;
&lt;span class=&quot;s&quot;&gt;... SELECT ?project ?name WHERE {&lt;/span&gt;
&lt;span class=&quot;s&quot;&gt;...    ?project a doap:Project;&lt;/span&gt;
&lt;span class=&quot;s&quot;&gt;...         doap:name ?name.&lt;/span&gt;
&lt;span class=&quot;s&quot;&gt;... }&lt;/span&gt;
&lt;span class=&quot;s&quot;&gt;... ORDER BY ?name LIMIT 5 OFFSET 10&lt;/span&gt;
&lt;span class=&quot;s&quot;&gt;... &amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ast&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;selected&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;SparqlVar&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;project&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SparqlVar&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;name&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)]&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ast&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;prefixes&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;doap&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;http://usefulinc.com/ns/doap#&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ast&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;orderby&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;[(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;SparqlVar&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;name&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;asc&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)]&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ast&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;limit&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ast&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;offset&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ast&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;where&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;[(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;SparqlVar&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;project&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;a&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;http://usefulinc.com/ns/doap#&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;Project&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)),&lt;/span&gt;
 &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;SparqlVar&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;project&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;http://usefulinc.com/ns/doap#&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;name&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SparqlVar&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;name&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))]&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This AST is then processed and transformed into a RQL query which
can finally be processed by CubicWeb directly.&lt;/p&gt;
&lt;p&gt;Here&#39;s what can be done in &lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;cubicweb-ctl&lt;/span&gt; shell&lt;/tt&gt; session (of course,
this can also be done in the web application) of our forge
cube:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;cubicweb.spa2rql&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Sparql2rqlTranslator&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;query&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;&amp;quot;&amp;quot;PREFIX doap: &amp;lt;http://usefulinc.com/ns/doap#&amp;gt;&lt;/span&gt;
&lt;span class=&quot;s&quot;&gt;... SELECT ?project ?name WHERE {&lt;/span&gt;
&lt;span class=&quot;s&quot;&gt;...    ?project a doap:Project;&lt;/span&gt;
&lt;span class=&quot;s&quot;&gt;...         doap:name ?name.&lt;/span&gt;
&lt;span class=&quot;s&quot;&gt;... }&lt;/span&gt;
&lt;span class=&quot;s&quot;&gt;... ORDER BY ?name LIMIT 5 OFFSET 10&lt;/span&gt;
&lt;span class=&quot;s&quot;&gt;... &amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;qinfo&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;translator&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;translate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;query&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rql&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;qinfo&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;finalize&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rql&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;Any&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;PROJECT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;NAME&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ORDERBY&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;NAME&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ASC&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;LIMIT&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;OFFSET&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;WHERE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;PROJECT&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;NAME&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;PROJECT&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;is&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Project&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;From the above example, we can notice two things. First, for
cubicweb to understand the &lt;tt class=&quot;docutils literal&quot;&gt;doap&lt;/tt&gt; namespace, we have to
declare the correspondance between the standard &lt;tt class=&quot;docutils literal&quot;&gt;doap&lt;/tt&gt; vocabulary
and our internal schema, this is done with &lt;tt class=&quot;docutils literal&quot;&gt;yams.xy&lt;/tt&gt;:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;yams&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;xy&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;xy&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;register_prefix&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;http://usefulinc.com/ns/doap#&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;doap&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;xy&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;add_equivalence&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;Project&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;doap:Project&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;xy&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;add_equivalence&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;Project name&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;doap:Project doap:name&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Secondly, for now, we notice that the case is not preserved during the
transformation : &lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;?project&lt;/span&gt;&lt;/tt&gt; becomes &lt;tt class=&quot;docutils literal&quot;&gt;PROJECT&lt;/tt&gt; in the rql query. This
is probably something that we&#39;ll need to tackle quickly.&lt;/p&gt;
&lt;p&gt;We&#39;ve also add a few views in CubicWeb to wrap that and it will
be available in the upcoming version &lt;a class=&quot;reference&quot; href=&quot;http://www.cubicweb.org/project/cubicweb/3.4.0&quot;&gt;3.4.0&lt;/a&gt; and is already
available through our pulic mercurial &lt;a class=&quot;reference&quot; href=&quot;http://www.cubicweb.org/cgi-bin/hgwebdir.cgi/cubicweb/&quot;&gt;repository&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The door is now open, the path is still long, stay tuned !&lt;/p&gt;
&lt;p&gt;&lt;em&gt;image under&lt;/em&gt; &lt;a class=&quot;reference&quot; href=&quot;http://creativecommons.org/licenses/by-sa/2.0/deed.en_GB&quot;&gt;creative commons&lt;/a&gt; &lt;em&gt;by&lt;/em&gt; &lt;a class=&quot;reference&quot; href=&quot;http://www.flickr.com/photos/beger/&quot;&gt;beger&lt;/a&gt; (&lt;a class=&quot;reference&quot; href=&quot;http://www.flickr.com/photos/beger/2335652487/&quot;&gt;original&lt;/a&gt;)&lt;/p&gt;
</description>
  <dc:date>2009-07-28T17:34-01:00</dc:date>
  <dc:creator>Adrien Di Mascio</dc:creator>
</item>
  </channel>
</rss>