Skip to content

hroptatyr/libttl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

libttl

Licence

A no-frills turtle/trig/ntriples/nquads parser.

Red tape

  • licensed under BSD3c
  • dependencies: POSIX system, C11 compiler

Motivation

Being a heavy user of (and occasional contributor) to raptor, the Redland Raptor RDF syntax library, has laid bare the short-comings of a reference implementation. Parsing feels heavy with so many knobs and levers that have to be pulled and turned: Input format has to be specified, input is always canonicalised, prefixes are expanded.

Show me parser code

The user facing bits of the parser are set up with 2 handlers:

static void prefix_handler(void *usr, ttl_iri_t nsdecl)
{
        ...
}

static void statement_handler(void *usr, const ttl_stmt_t *stmt, size_t i)
{
        /* do something with subjects */
        stmt[i].subj;
        /* do something with predicates */
        stmt[i].pred;
        /* do something with objects */
        stmt[i].obj;
        /* do something with the graph, might be (ttl_term_t){} */
        stmt[i].grph;
        ...
}

ttl_handler_t my_parser = {prefix_handler, statement_handler};

Then:

ttl_parser_t *p = ttl_make_parser();
p->hdl = my_parser;
ttl_parse_chunk(p, buffer, size);
...
ttl_free_parser(p);

The parser can switch between ntriples/nquads and turtle/trig on the fly which allows to consume a concatenation of .nt and .ttl files.

Namespaces don't need to be declared upfront because qnames are returned as such (i.e. unexpanded).

About

no-frills turtle/trig/ntriples/nquads parser library

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published