Skip to content

Commit

Permalink
Merge pull request #1410 from avataar/issues/#1409-unnecessary-iri-pa…
Browse files Browse the repository at this point in the history
…rsing

GH-1409: Unnecessary parsing of IRIs every time an RDF parser is used
  • Loading branch information
Jeen Broekstra authored May 17, 2019
2 parents 62f7889 + 97d0ea1 commit a8323bf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -440,8 +440,7 @@ public void test780IRISpace() throws Exception {
assertEquals(1, model.size());
model.filter(null, RDF.TYPE, null)
.objects()
.forEach(obj -> assertEquals("http://purl.bioontology.org/ontology/UATC/%20SERINE%20%20",
obj.stringValue()));
.forEach(obj -> assertEquals("http://purl.bioontology.org/ontology/UATC/ SERINE ", obj.stringValue()));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,38 +367,24 @@ protected void clearBNodeIDMap() {
* Resolves a URI-string against the base URI and creates a {@link IRI} object for it.
*/
protected IRI resolveURI(String uriSpec) throws RDFParseException {
// Resolve relative URIs against base URI
ParsedIRI uri;
try {
uri = new ParsedIRI(uriSpec);
} catch (URISyntaxException e) {
reportError("Invalid IRI '" + uriSpec, BasicParserSettings.VERIFY_URI_SYNTAX);
try {
uri = ParsedIRI.create(uriSpec);
} catch (IllegalArgumentException ex) {
if (getParserConfig().isNonFatalError(BasicParserSettings.VERIFY_URI_SYNTAX)) {
return null;
}
return valueFactory.createIRI(uriSpec);
}
}

if (!uri.isAbsolute()) {
if (uriSpec.indexOf(':') < 0) {
// Resolve relative URIs against base URI
if (baseURI == null) {
reportFatalError("Unable to resolve URIs, no base URI has been set");
}

if (getParserConfig().get(BasicParserSettings.VERIFY_RELATIVE_URIS)) {
if (!uri.isAbsolute() && uriSpec.length() > 0 && !uriSpec.startsWith("#") && baseURI.isOpaque()) {
if (uriSpec.length() > 0 && !uriSpec.startsWith("#") && baseURI.isOpaque()) {
reportError("Relative URI '" + uriSpec + "' cannot be resolved using the opaque base URI '"
+ baseURI + "'", BasicParserSettings.VERIFY_RELATIVE_URIS);
}
}

uri = baseURI.resolve(uri);
return createURI(baseURI.resolve(uriSpec));
} else {
// URI is not relative
return createURI(uriSpec);
}

return createURI(uri.toString());
}

/**
Expand All @@ -410,6 +396,7 @@ protected IRI createURI(String uri) throws RDFParseException {
new ParsedIRI(uri);
} catch (URISyntaxException e) {
reportError(e.getMessage(), BasicParserSettings.VERIFY_URI_SYNTAX);
return null;
}
}
try {
Expand Down

0 comments on commit a8323bf

Please sign in to comment.