You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Jean-Marc Vanel <je...@gmail.com> on 2020/06/18 08:28:22 UTC

Check a plain literal by API

Literals can have annoying errors like "Illegal escape sequence value" .
These errors create exceptions by Turtle parser.
But the API does not check anything:
NodeFactory.createLiteral("ggg\\<br")

Event the org.apache.jena.riot.checker.CheckerLiterals is silent:

val handler =
org.apache.jena.riot.system.ErrorHandlerFactory.errorHandlerStrict
val checker = new org.apache.jena.riot.checker.CheckerLiterals(handler)
val obj = "ggg\\<br"
import org.apache.jena.graph._
val lit = NodeFactory.createLiteral(obj)
checker.check(lit, 1L, 1L)
res28: Boolean = true

So, is there a way to check a plain literal by API, other than creating a
fake triple and parse it ?

Note: the code samples are in Scala command line (REPL), but I think it's
easy to understand for Javaists ...

Jean-Marc Vanel
<http://semantic-forms.cc:9112/display?displayuri=http://jmvanel.free.fr/jmv.rdf%23me>
+33 (0)6 89 16 29 52
Twitter: @jmvanel , @jmvanel_fr ; chat: irc://irc.freenode.net#eulergui
 Chroniques jardin
<http://semantic-forms.cc:1952/history?uri=http%3A%2F%2Fdbpedia.org%2Fresource%2FChronicle>

Re: Check a plain literal by API

Posted by Jean-Marc Vanel <je...@gmail.com>.
Indeed I made a confusion between the actual literal content (unrestricted)
and the Turtle representation of it.

Jean-Marc Vanel
<http://semantic-forms.cc:9112/display?displayuri=http://jmvanel.free.fr/jmv.rdf%23me>
+33
(0)6 89 16 29 52


Le jeu. 18 juin 2020 à 13:36, Andy Seaborne <an...@apache.org> a écrit :

>
>
> On 18/06/2020 09:28, Jean-Marc Vanel wrote:
> > Literals can have annoying errors like "Illegal escape sequence value" .
> > These errors create exceptions by Turtle parser.
> > But the API does not check anything:
> > NodeFactory.createLiteral("ggg\\<br")
>
> "\\" is single \ in scala/java.
>
> That is illegal in Turtle syntax, not an illegal literal.
>
> \< is not a Turtle escape.
>
> [172s]  PN_LOCAL_ESC    ::=
> '\' ('_' | '~' | '.' | '-' | '!' | '$' | '&' | "'" | '(' | ')' | '*' |
> '+' | ',' | ';' | '=' | '/' | '?' | '#' | '@' | '%')
>
> But '\<' is a legal string in RDF - it is not an escape, RDF does not
> have escapes - syntaxes do.
>
>      Andy
>
> >
> > Event the org.apache.jena.riot.checker.CheckerLiterals is silent:
> >
> > val handler =
> > org.apache.jena.riot.system.ErrorHandlerFactory.errorHandlerStrict
> > val checker = new org.apache.jena.riot.checker.CheckerLiterals(handler)
> > val obj = "ggg\\<br"
> > import org.apache.jena.graph._
> > val lit = NodeFactory.createLiteral(obj)
> > checker.check(lit, 1L, 1L)
> > res28: Boolean = true
> >
> > So, is there a way to check a plain literal by API, other than creating a
> > fake triple and parse it ?
> >
> > Note: the code samples are in Scala command line (REPL), but I think it's
> > easy to understand for Javaists ...
> >
> > Jean-Marc Vanel
> > <
> http://semantic-forms.cc:9112/display?displayuri=http://jmvanel.free.fr/jmv.rdf%23me
> >
> > +33 (0)6 89 16 29 52
> > Twitter: @jmvanel , @jmvanel_fr ; chat: irc://irc.freenode.net#eulergui
> >   Chroniques jardin
> > <
> http://semantic-forms.cc:1952/history?uri=http%3A%2F%2Fdbpedia.org%2Fresource%2FChronicle
> >
> >
>

Re: Check a plain literal by API

Posted by Andy Seaborne <an...@apache.org>.

On 18/06/2020 09:28, Jean-Marc Vanel wrote:
> Literals can have annoying errors like "Illegal escape sequence value" .
> These errors create exceptions by Turtle parser.
> But the API does not check anything:
> NodeFactory.createLiteral("ggg\\<br")

"\\" is single \ in scala/java.

That is illegal in Turtle syntax, not an illegal literal.

\< is not a Turtle escape.

[172s] 	PN_LOCAL_ESC 	::=
'\' ('_' | '~' | '.' | '-' | '!' | '$' | '&' | "'" | '(' | ')' | '*' | 
'+' | ',' | ';' | '=' | '/' | '?' | '#' | '@' | '%')

But '\<' is a legal string in RDF - it is not an escape, RDF does not 
have escapes - syntaxes do.

     Andy

> 
> Event the org.apache.jena.riot.checker.CheckerLiterals is silent:
> 
> val handler =
> org.apache.jena.riot.system.ErrorHandlerFactory.errorHandlerStrict
> val checker = new org.apache.jena.riot.checker.CheckerLiterals(handler)
> val obj = "ggg\\<br"
> import org.apache.jena.graph._
> val lit = NodeFactory.createLiteral(obj)
> checker.check(lit, 1L, 1L)
> res28: Boolean = true
> 
> So, is there a way to check a plain literal by API, other than creating a
> fake triple and parse it ?
> 
> Note: the code samples are in Scala command line (REPL), but I think it's
> easy to understand for Javaists ...
> 
> Jean-Marc Vanel
> <http://semantic-forms.cc:9112/display?displayuri=http://jmvanel.free.fr/jmv.rdf%23me>
> +33 (0)6 89 16 29 52
> Twitter: @jmvanel , @jmvanel_fr ; chat: irc://irc.freenode.net#eulergui
>   Chroniques jardin
> <http://semantic-forms.cc:1952/history?uri=http%3A%2F%2Fdbpedia.org%2Fresource%2FChronicle>
>