-
Notifications
You must be signed in to change notification settings - Fork 659
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
Valid IRI while missing scheme? #2975
Comments
Online validator for IRIs https://www.sparql.org/iri-validator.html (running Jena 5.3.0 / jena-iri3986) The Two providers old/legacy jena-iri (your code uses that) and jena-irir3986 (will replace jena-iri soon). Even when using jena-iri, the correct route is via IRIx because the violation checking is different and reflects RDF better. jena-iri3986 is up-to-date with all the RFCs that define the various URIs scheme of interest, as well as RFC 3986/7, the syntax of IRIs.
They are valid as IRIs but they are both not suitable for RDF which requires resolved IRIs which are not relative references. (Oddly, I was updating the "RDF Concepts" in the RDF Working Group in this area last week.) Jena calls them " RDF references" - there isn't an exact term for this in the RFC3986 spec. ("Absolute" does not mean what people intuitively think it means!) This is an area that has tightened up over the years, both spec-wise and in Jena. Jena2 is RDF 1.0. RDF 1.0 that spec has "RDF URI references" - this all predates IRI3986/7. public static boolean checkIriBad(final String iriStr) {
final IRIx iri = IRIx.create(iriStr);
System.out.println(iri);
System.out.println("hasViolations: "+iri.hasViolations());
System.out.println("Reference: "+iri.isReference());
return iri.hasViolations();
}
Weclome to the black hole of IRI details! |
wooaahhhhhh.... thanks a lot! So instead of Using the code you supplied, both test strings still pas as valid (and thus the tests fail):
(Using latest jena main branch as of now: |
A parser will always resolve a IRI against the base (there is always a base): public static void iriProcess(final String iriStr) {
IRIx iri = IRIx.create(iriStr);
System.out.println("Argument: "+iri);
IRIx base = IRIs.getSystemBase();
IRIx iriResolved = base.resolve(iri);
System.out.println("iriResolved ="+iriResolved);
System.out.println("Reference: "+iriResolved.isReference());
} |
aHA! So I'll use: public static boolean checkValidIriForRDF(final String iriStr) {
final IRIx iri = IRIx.create(iriStr);
return !iri.hasViolations() && iri.isReference();
}
public void testBadIri1() {
assertFalse(checkValidIriForRDF("#:bar"));
}
public void testBadIri2() {
assertFalse(checkValidIriForRDF("domain.com/directory"));
}
public void testGoodIri1() {
assertTrue(checkValidIriForRDF("xsd:string"));
}
public void testGoodIri2() {
assertTrue(checkValidIriForRDF("http://domain.com/directory#good"));
} These all pass! |
Caveat the |
ouhhhh... |
Version
5.4.0-SNAPSHOT
Question
I would expect these two tests to pass, but they both fail:
They fail with:
Are these really valid IRIs?
(In Jena 2 the tests passed)
The text was updated successfully, but these errors were encountered: