- From: Reto Bachmann-Gmuer <reto.bachmann@trialox.org>
- Date: Tue, 9 Feb 2010 12:35:10 +0100
- To: Danny Ayers <danny.ayers@gmail.com>
- Cc: Taylor Cowan <taylor_cowan@yahoo.com>, Semantic Web <semantic-web@w3.org>
- Message-ID: <bfcea8c71002090335r3bc46302o2c8334267a5a0d8f@mail.gmail.com>
Especially when traversing a Graph I found using a DSL makes things much
easier, in apache clerezza ScalaServerPages are typically used to render RDF
resources to HTML. The following would sort a list of concepts and generate
some XHTML from them
def skos(s: Any) = new UriRef("http://www.w3.org/2008/05/skos#"+s)
def cm(s: Any) = new UriRef("http://clerezza.org/2009/04/conceptmanager#"+s)
def rdfs(s: Any) = new UriRef("http://www.w3.org/2000/01/rdf-schema#"+s)
for (concept <- ((res/cm("conceptList"))!!)
.sort((a,b) => ((a/skos("prefLabel")*) <
(b/skos("prefLabel")*)))) yield {
<div>
{concept*}<br/>
{concept/skos("prefLabel")*}<br/>
{concept/skos("broader")/skos("prefLabel")*}<br/>
{concept/skos("narrower")/skos("prefLabel")*}<br/>
{concept/rdfs("comment")*}<br/>
</div>
}
What's happening?
- The slash ("/") operator returns the property values, (slash minus "/-"
would follow the property the other way round)
- the * operation returns the value of literals and the URI of resources
- the !! operation returns a scala list for an rdf:List as object
- There's an implicit conversion converting node-iterators to the first
element
The full scaladoc is here:
http://incubator.apache.org/clerezza/mvn-site/org.apache.clerezza.rdf.scala.utils/scaladocs/index.html
note that you can mix between the DSL shortcuts in RichGraphNode and the
standard GraphNode methods (see
http://incubator.apache.org/clerezza/mvn-site/org.apache.clerezza.rdf.utils/apidocs/index.htmlfor
the plain GraphNode)
Cheers,
reto
On Tue, Feb 9, 2010 at 12:40 AM, Danny Ayers <danny.ayers@gmail.com> wrote:
> On 8 February 2010 16:26, Taylor Cowan <taylor_cowan@yahoo.com> wrote:
>> Also see http://code.google.com/p/scardf/
>>
>> Looks like a DSL approach.
>
> Thanks, nice to see. Must admit I'm not altogether convinced such a
> wrapper is necessary - scripting with Scala over Jena is pretty
> straightforward (and fun) anyway.
>
> Cheers,
> Danny.
>
> --
> http://danny.ayers.name
>
>
Received on Tuesday, 9 February 2010 11:35:42 UTC