- From: Karl Dubost <karl@w3.org>
- Date: Sat, 3 Sep 2005 16:51:09 -0400
- To: www-archive@w3.org
This is an attempt to manage the list of open source software CMS in n3 http://www.la-grange.net/cms We used the DOAP Vocabulary designed by Edd Dumbill. Here's an example of a file in n3, a syntax of RDF to collect the information about each software. Important: All of this would not have been possible without the enlightment given by Sean B. Palmer <http://infomesh.net/sbp/> First a simple example of n3 file using the DOAP vocabulary with only two projects into it. The file is quite self describing. But let's there's something which is called a Project with a few metadata: Project - description of the project - the page where we can download it - the homepage of the project - the license - the name of the project - the programming language of the project Oh yes it's N3 then it doesn't matter the order in which you write the things. Then writing: [ a :Project; :homepage <http://www.flutterby.com/software/newwwsboy/>; :name "Newwwsboy"^^XML:string; ]. or writing: [ a :Project; :name "Newwwsboy"^^XML:string; :homepage <http://www.flutterby.com/software/newwwsboy/>; ]. is exactly the same. ok the file with two software which are described. # Open source CMS list in n3 # XHTML Version at: http://www.la-grange.net/cms # @prefix : <http://usefulinc.com/ns/doap#> . @prefix XML: <http://www.w3.org/2001/XMLSchema#> . [ a :Project; :description "Newwwsboy takes e-mail or text files as input and, using comments in HTML documents as a template, formats the e-mail and stuffs it into those documents."^^XML:string; :download-page <http://www.flutterby.com/software/newwwsboy/>; :homepage <http://www.flutterby.com/software/newwwsboy/>; :license <http://usefulinc.com/doap/licenses/bsd>; :name "Newwwsboy"^^XML:string; :programming-language "Perl"^^XML:string; ]. [ a :Project; :description "E-mail robot for adding news items to a webpage."^^XML:string; :download-page <http://www.daemon.de/HtnewsDownload>; :homepage <http://www.daemon.de/Htnews>; :license <http://usefulinc.com/doap/licenses/gpl>; :name "Htnews"^^XML:string; :programming-language "C"^^XML:string; ]. #ENDS We would like to extract from this file some values to reuse them in an HTML file for example. For this we will use the program cwm[1] which has query built-in features. If you install cwm on your computer, be careful to have python and PyXML[2] installed. I like to use n3 as a file format because it's easier to read for me than RDF. You can easily convert between this two syntax of RDF. Let's say you got a file in RDF: my_file.rdf Convert RDF to n3 cwm --rdf myfile.rdf --n3 > myfile.n3 Convert n3 to RDF cwm --n3 myfile.n3 --rdf > myfile.rdf Now let's create a file of rules in n3 that will help us to query our cms.n3 file which has the list of projects. We want for now to extract the name of each project and put it into a "h2" element. from cms.n3 :name "Newwwsboy"^^XML:string; to have <h2>Newwwsboy</h2> The way to do that is 1. to query every Project { [ a doap:Project; 2. Take the name and put it in a variable NAME doap:name ?NAME; 3. To create a variable TEXT mixing the NAME and the HTML ?TEXT string:concat ("<h2>" ?NAME "</h2>\n")} 4. To ouput the result of TEXT in the order given by "001" => { "001" log:outputString ?TEXT} . The full n3 file cms2html.n3 looks like: # cms2html.n3 # to query cms.n3 @prefix : <#> . @prefix doap: <http://usefulinc.com/ns/doap#> . @prefix log: <http://www.w3.org/2000/10/swap/log#> . @prefix string: <http://www.w3.org/2000/10/swap/string#> . { [ a doap:Project; doap:name ?NAME; ] . ?TEXT string:concat ("<h2>" ?NAME "</h2>\n)} => { "001" log:outputString ?TEXT} . #ENDS Then the command with cwm cwm cms.n3 cms2html.n3 --think --strings The ouput is <h2>Htnews</h2> <h2>Newwwsboy</h2> Let's say we want to query more than one variable and we want to add the description now # cms2html.n3 # to query cms.n3 @prefix : <#> . @prefix doap: <http://usefulinc.com/ns/doap#> . @prefix log: <http://www.w3.org/2000/10/swap/log#> . @prefix string: <http://www.w3.org/2000/10/swap/string#> . { [ a doap:Project; doap:name ?NAME; doap:description ?DESCRIPTION ] . ?TEXT string:concat ("<h2>" ?NAME "</h2>\n<p>" ?DESCRIPTION "</p> \n")} => { "001" log:outputString ?TEXT} . #ENDS Then the command with cwm cwm cms.n3 cms2html.n3 --think --strings The ouput is <h2>Htnews</h2> <p>E-mail robot for adding news items to a webpage.</p> <h2>Newwwsboy</h2> <p>Newwwsboy takes e-mail or text files as input and, using comments in HTML documents as a template, formats the e-mail and stuffs it into those documents.</p> This is a bit geeky, but you can foresee the principles. I'm pretty sure it would be possible to design an HTML templating system based on n3 rules and apply them to contents. [1] http://www.w3.org/2000/10/swap/doc/cwm.html [2] http://pyxml.sourceforge.net/ -- Karl Dubost - http://www.w3.org/People/karl/ W3C Conformance Manager *** Be Strict To Be Cool ***
Received on Saturday, 3 September 2005 20:51:44 UTC