[[PageOutline(1-3)]] = N3/Turtle Highlighting = In working with semantic web triples, [http://www.w3.org/TeamSubmission/turtle/ Turtle] is much easier to work with than rdf/xml. The lack of syntax highlighting for N3/Turtle has been a problem. I didn't find any good solutions so I offer two tools up for public consumption. Both follow my belief that highlighting should be based on the part of the statement. Subjects one color, predicates another and objects a different color (actually a couple of colors for literal vs resource objects). Coloring is to provide visual clues to the semantic web worker. A given qname could be a subject, predicate or object and should be colored accordingly. Not colored one way in all three cases and colored differently if the uri is put in in the place of the qname. That is the approach that both the following tools use. = Pygments = [http://pygments.org/ Pygments] is a fast, flexible [http://www.python.org/ python] based syntax highlighter. [[Image(htdocs:images/pygments_75.png,left)]]It is available for use in Trac and will be the default highlighter in release 0.11 . '''SPARQL''' highlighting has not yet been implemented here! == Installation == 1. Install [http://pygments.org/ Pygments] if you have not done so. 2. Grab `sw.py` from the [http://www.openvest.com/trac/browser/tools/trunk/pygments/lexers/sw.py source browser] or from the svn with: {{{ #From your pygments subdir like: # path-to-your/python2.x/site-packages/Pygments-0.x-py2.x.egg/pygments #execute svn co http://www.openvest.com/svn/public/tools/trunk/pygments/lexers }}} make sure do to that from within your `/some_path/some_dir/site-packages/??/pygments/lexers` directory. 3. To rebuild the lexers list, in that same subdir run: {{{ python _mapping.py }}} You should then be able to `pygmentize` an n3 file. === Trac Integration === Once pygments is setup for !n3SyntaxHighlighting you only need to begin n3 code like: {{{ {{{ #!n3 joseki:ProcessorSPARQL ... }}} }}} Within Trac you should be able to make n3 files look like: {{{ #!n3 joseki:ProcessorSPARQL rdfs:label "General SPARQL processor" ; rdf:type joseki:Processor ; module:implementation joseki:ImplSPARQL ; # Parameters - this processor processes FROM/FROM NAMED joseki:allowExplicitDataset "true"^^xsd:boolean ; joseki:allowWebLoading "true"^^xsd:boolean ; . joseki:ProcessorSPARQL_FixedDS rdfs:label "SPARQL processor for fixed datasets" ; rdf:type joseki:Processor ; module:implementation joseki:ImplSPARQL ; }}} Instead of: {{{ joseki:ProcessorSPARQL rdfs:label "General SPARQL processor" ; rdf:type joseki:Processor ; module:implementation joseki:ImplSPARQL ; # Parameters - this processor processes FROM/FROM NAMED joseki:allowExplicitDataset "true"^^xsd:boolean ; joseki:allowWebLoading "true"^^xsd:boolean ; . joseki:ProcessorSPARQL_FixedDS rdfs:label "SPARQL processor for fixed datasets" ; rdf:type joseki:Processor ; module:implementation joseki:ImplSPARQL ; }}} The exact coloring is under your control as Pygments has numerous color schemes. You can go to the SandBox and try it out. If there are highlighting errors please email me or create a ''New Ticket'' at the link above. '''Trac 0.10.x''' will require that you download and install the [http://trac-hacks.org/wiki/TracPygmentsPlugin TracPygmentsPlugin]. '''Trac 0.11''' already uses Pygments but you may have to modify your `trac.ini` file to include: {{{ [mimeviewer] mime_map = ...(some-stuff)...,application/x-turtle:n3 pygments_default_style = trac pygments_modes = application/x-turtle:n3:7 }}} === reStructuredText Integration === Code blocks in [http://docutils.sourceforge.net/rst.html reStructuredText] will also now be marked up for N3 code blocks. Just follow the [http://pygments.org/docs/rstdirective/ pygments/restructuredText integration] instructions. You can then have markup in Moin or where ever you use reStructuredText . = !TextMate = I have created a ''bundle'' for use with the [http://macromates.com/ TextMate] editor. [[Image(htdocs:images/textmate_64.png,left)]]If you edit [http://www.w3.org/DesignIssues/Notation3 N3] or [http://www.dajobe.org/2004/01/turtle/ Turtle] files on OSX, check it out. If you are not on OSX...move along, there is nothing to see here. To install whatever the current trunk, go to your !TextMate bundles dir and use: {{{ svn co http://www.openvest.com/svn/public/tools/trunk/N3.tmbundle/ }}} == Setup == The installation might leave you unimpressed. The Bundle does not reuse all pre-existing scopes and keywords. I just created subject, predicate and object scopes and gave them colors. You might see all black unless you create them in the preferences menu and the fonts and colors tab under that. Anyway for semantic web stuff, I thought the subject, predicate object scopes made a lot of sense. In my Mac Classic theme I have: || Element Name || Scope || Style || || rdf:statement || meta.statement || || || rdf:subject || meta.statement.subject || bold maroon || || rdf:predicate || meta.statement.predicate || italic darkgreen || || rdf:object || meta.statement.object || midnightblue || If you do that, you should start with N3 like: {{{ joseki:ProcessorSPARQL rdfs:label "General SPARQL processor" ; rdf:type joseki:Processor ; module:implementation joseki:ImplSPARQL ; # Parameters - this processor processes FROM/FROM NAMED joseki:allowExplicitDataset "true"^^xsd:boolean ; joseki:allowWebLoading "true"^^xsd:boolean ; . joseki:ProcessorSPARQL_FixedDS rdfs:label "SPARQL processor for fixed datasets" ; rdf:type joseki:Processor ; module:implementation joseki:ImplSPARQL ; # This processor does not accept queries with FROM/FROM NAMED joseki:allowExplicitDataset "false"^^xsd:boolean ; joseki:allowWebLoading "false"^^xsd:boolean ; }}} And see it as something like: [[Image(TxMtN3.png)]] == SPARQL == I've started to work on some basic [http://www.w3.org/TR/rdf-sparql-query/ SPARQL] markup. Check it out in trac(pygments based): {{{ #!sparql # Sample SPARQL of XBRL data prefix rdf: prefix usgaap: prefix xbrli: prefix xsd: SELECT ?cash ?date WHERE { [] rdf:type usgaap:CashAndCashEquivalentsAtCarryingValue ; rdf:value ?cash; xbrli:context [xbrli:entity [xbrli:identifier [xbrli:schema ; rdf:value "IBM"]; xbrli:period [xbrli:onDate ?date ]]]. FILTER (?date > ?some "2005-12-31"^^xsd:date) } }}} Can also check it out in restructured text [http://www.openvest.com/page/SparqlXbrlQuery here](also pygments). If you use !TextMate, check out that lexer also. In !TextMate, a macro that would take SPARQL and executed it against a SPARQL endpoint (like a [http://www.joseki.org/ Joseki] server) might be cool but I think I'd rather put that effort into Javascript for now. = Other Highlighting = === Emacs === Emacs has an [http://larve.net/people/hugo/2003/scratchpad/NotationThreeEmacsMode.html N3 Emacs mode] which I found disappointing to say the least. I am a long time emacs user but the lack of a good tool here is what motivated me to create the !TextMate bundle. === vim === VI has an [http://www.vim.org/scripts/script.php?script_id=944 N3 syntax script] available. I can't comment because I have never been a vim kind of guy. Vim users can also use the [http://www.vim.org/scripts/script.php?script_id=1835 RDF Namespace completion script]. (Maybe I should implement this for !TextMate)