RDF parsers implemented as Racket languages
This code is extremely broken.
#lang rdf/turtle
and #lang rdf/nt
use brag as a parser generator.
ttl-to-rkt
depends on librdf and rapper for fast parsing and conversion.
Run these or the equivalent for your setup if you want to use
ttl-to-rkt
or rkdf-convert-all
.
ln -s $(realpath ./bin/ttl-to-rkt) ~/bin/ttl-to-rkt
ln -s $(realpath ./bin/rkdf-convert-all) ~/bin/rkdf-convert-all
raco pkg install rkdf-lib/ rkdf/
Conveniently turtle comments allow us to include #lang rdf/turtle
in the first line of a turtle file. This is also true for nt, which will
accept the #lang rdf/nt
line. #lang rdf
defaults to turtle syntax.
To convert a single file run the following
ttl-to-rkt my-ontology-file.ttl my-ontology-file.rkt
ttl-to-rkt
runs raco make
automatically so if you
are converting a large file it may take some time.
rapper
supports many formats besides turtle, an they could be
included with minimal changes to ttl-to-rkt
.
The fastest way to convert RDF representations store in git into Racket is to use
rkdf-convert-all
. The process is in no way robust and may fail silently. Once the
conversion to rkt is complete raco make
is used to compile the outputs to speed
up loading by a few orders of magnitude. Note that convert-all
will exactly
duplicate the file hierarchy of the original repository inside the rkt/
folder.
To make files available as racket modules do the following
raco pkg install path/to/my/ontology/
cd path/to/my/ontology
rkdf-convert-all
It should then be possible require a single file using normal Racket require
syntax.
#lang racket/base
(require ontology/rkt/my-ontology-file)
Running raco make my-file.ttl
will make all future loads stupidly fast.
A faster parser would be preferred, but no time to implement that at the moment.
The BNF used for the turtle parser was a copy/paste fixup job from the turtle spec
and is not well written or optimized in the slightest.
https://bitbucket.org/nxg/racket-librdf is probably the correct solution, but is more complicated to install.