Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flycheck validation (Turtle) #30

Open
VladimirAlexiev opened this issue Mar 28, 2024 · 0 comments
Open

flycheck validation (Turtle) #30

VladimirAlexiev opened this issue Mar 28, 2024 · 0 comments

Comments

@VladimirAlexiev
Copy link
Collaborator

Turtle mode setup:

(autoload 'n3-mode "n3-mode")
(define-derived-mode Turtle-mode n3-mode "Turtle")
(add-hook 'Turtle-mode-hook 'turn-on-font-lock)

(add-to-list 'auto-mode-alist '("\\.ttl$"    . Turtle-mode))
(add-to-list 'auto-mode-alist '("\\.ttls$"   . Turtle-mode)) ; TODO: Extend for Turtle*. http://graphdb.ontotext.com/documentation/9.2/free/devhub/rdf-sparql-star.html#mime-types-and-file-extensions-for-rdf-in-rdf4j
(add-to-list 'auto-mode-alist '("\\.trig$"   . Turtle-mode))
(add-to-list 'auto-mode-alist '("\\.r2rml$"  . Turtle-mode))
(add-to-list 'auto-mode-alist '("\\.shacl$"  . Turtle-mode))
(add-to-list 'auto-mode-alist '("\\.n3$"     . Turtle-mode))
(add-to-list 'auto-mode-alist '("\\.nt$"     . Turtle-mode))
(add-to-list 'auto-mode-alist '("\\.owl$"    . Turtle-mode))

Turtle validation with jena riot.

(flycheck-define-checker rdf-riot
  "RDF syntax checker using riot and script riotval.pl to prepend prefixes.ttl."
  :command ("perl" "-S" "riotval.pl" source)
  :error-patterns
  ((error "ERROR riot " (* " ") ":: [line: " line ", col: " column (* " ") "] " (message)))
  :modes (n3-mode ttl-mode Turtle-mode))
(add-to-list 'flycheck-checkers 'rdf-riot)

This uses an extra script riotval.pl to prepend prefixes.ttl (as used by rdfpuml), then subtract its length from error messages:

#!perl -w
# Validate a turtle file with riot --validate; optionally prepending prefixes.ttl

my $file = shift or die "usage: riotval file.(ttl|trig)\n";
my $syntax = $file =~ m{\\.ttl$} ? "turtle" : "trig";
if (-e "prefixes.ttl") {
  my ($lines) = `wc -l prefixes.ttl` =~ m{(\d+)};
  my $out = `cat prefixes.ttl $file | riot --validate --syntax $syntax - 2>&1`;
  $out =~ s{(?<=:: \[line: )(\d+)}{$1 - $lines}ge;
  print $out
} else {
  print `riot --validate --syntax $syntax $file`
}

If you don't use prefixes.ttl then things get simpler:

  :command ("riot" "--validate" source)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant