Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class IRIUtils {

private static final Logger logger = LoggerFactory.getLogger(IRIUtils.class);

private static final Pattern IRI_PATTERN = Pattern.compile("^(([\\w\\-]+:\\/\\/([\\w\\-_:]+\\.)*[\\w\\-_:]*)(\\/([\\w\\-\\._\\:]+\\/)*))([\\w\\-\\._\\:]+)(\\?[\\w\\-_\\:\\?\\=]+)?((\\#)?([\\w\\-_]+))?$");
private static final Pattern IRI_PATTERN = Pattern.compile("^(([\\w\\-]+:\\/\\/([\\w\\-_:]+\\.)*[\\w\\-_:]*)(\\/([\\w\\-\\._\\:]+\\/)*))([\\w\\-\\._\\:]+)?(\\?[\\w\\-_\\:\\?\\=]+)?((\\#)?([\\w\\-_]+))?$");
private static final Pattern STANDARD_IRI_PATTERN = Pattern.compile("^(([^:/?#\\s]+):)(\\/\\/([^/?#\\s]*))?([^?#\\s]*)(\\?([^#\\s]*))?(#(.*))?");

/**
Expand All @@ -34,9 +34,11 @@ public static String guessNamespace(String iri) {
Matcher matcher = IRI_PATTERN.matcher(iri);

if(matcher.matches()) {
if(matcher.group(8) == null ) { // If the IRI has no fragment)
if((matcher.group(8) == null) || (matcher.group(6) == null && matcher.group(9) == null) ) { // If the IRI has no fragment or ends with a slash

return matcher.group(1);
} else {
// 1: Domain and path ending with a slash, 6: final path element without slash, 9: final # if there is a fragment
return matcher.group(1) + matcher.group(6) + matcher.group(9);
}
} else {
Expand All @@ -57,10 +59,12 @@ public static String guessLocalName(String iri) {
Matcher matcher = IRI_PATTERN.matcher(iri);

if(matcher.matches()) {
if(matcher.group(8) == null ) { // If the IRI has no fragment)
return matcher.group(6);
} else {
if(matcher.group(10) != null){ // If the IRI has a fragment
return matcher.group(10);
} else if(matcher.group(6) != null ) { // If the IRI has no fragment but do not ends with a slash
return matcher.group(6);
} else { // If the URI ends with a slash
return "";
}
} else {
return "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,11 @@ public void testCreateStatementWithContext() {
assertEquals(literal, statement.getObject());
assertEquals(context, statement.getContext());
}

@Test
public void testCreateFOAFURI() {
IRI foaf = valueFactory.createIRI("http://xmlns.com/foaf/0.1/");
assertNotNull(foaf);
assertEquals("http://xmlns.com/foaf/0.1/", foaf.stringValue());
}
}