Skip to content

Commit

Permalink
Use '.' as character after artifact code if base URI already has '#'
Browse files Browse the repository at this point in the history
  • Loading branch information
tkuhn committed Mar 9, 2015
1 parent 453ba23 commit 128ccdc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 63 deletions.
29 changes: 18 additions & 11 deletions src/main/java/net/trustyuri/rdf/RdfUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,21 @@

public class RdfUtils {

public static final char bnodeChar = '_';
public static final char preAcChar = '.';
public static final char postAcChar = '#';
public static final char postAcFallbackChar = '.';

private RdfUtils() {} // no instances allowed

public static String getTrustyUriString(URI baseUri, String artifactCode, String suffix) {
UriTransformConfig c = UriTransformConfig.getDefault();
String s = expandBaseUri(baseUri) + artifactCode;
if (suffix != null) {
if (suffix.startsWith(c.getBnodeChar() + "")) {
if (suffix.startsWith(bnodeChar + "")) {
// Duplicate bnode character for escaping:
s += c.getPostHashChar() + c.getBnodeChar() + suffix;
} else if (!c.isPostHashCharForced() && suffix.matches("[^A-Za-z0-9\\-_].*")) {
s += suffix;
s += getPostAcChar(baseUri) + bnodeChar + suffix;
} else {
s += c.getPostHashChar() + suffix;
s += getPostAcChar(baseUri) + suffix;
}
}
return s;
Expand Down Expand Up @@ -96,10 +98,16 @@ public static void checkUri(URI uri) {
}
}

public static char getPostAcChar(URI baseUri) {
if (baseUri.stringValue().contains("#")) {
return postAcFallbackChar;
}
return postAcChar;
}

private static URI getSkolemizedUri(BNode bnode, URI baseUri, Map<String,Integer> bnodeMap) {
int n = getBlankNodeNumber(bnode, bnodeMap);
UriTransformConfig c = UriTransformConfig.getDefault();
return new URIImpl(expandBaseUri(baseUri) + " " + c.getPostHashChar() + c.getBnodeChar() + n);
return new URIImpl(expandBaseUri(baseUri) + " " + getPostAcChar(baseUri) + bnodeChar + n);
}

private static String getSuffix(URI plainUri, URI baseUri) {
Expand Down Expand Up @@ -135,10 +143,9 @@ private static int getBlankNodeNumber(BNode blankNode, Map<String,Integer> bnode
}

private static String expandBaseUri(URI baseUri) {
UriTransformConfig c = UriTransformConfig.getDefault();
String s = baseUri.toString();
if (s.matches(".*[A-Za-z0-9\\-_]") || c.isPreHashCharForced()) {
s += c.getPreHashChar();
if (s.matches(".*[A-Za-z0-9\\-_]")) {
s += preAcChar;
}
return s;
}
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/net/trustyuri/rdf/TransformRdf.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,9 @@ static void addToNamespaceMap(Value v, URI baseURI, String artifactCode, Map<Str
String uri = RdfUtils.getTrustyUriString(baseURI, artifactCode);
String s = v.toString().replace(" ", artifactCode);
if (!s.startsWith(uri)) return;
UriTransformConfig c = UriTransformConfig.getDefault();
String suffix = s.substring(uri.length());
if (suffix.length() > 2 && suffix.charAt(0) == c.getPostHashChar() && suffix.charAt(1) == c.getBnodeChar() &&
!(c.getBnodeChar() + "").matches("[A-Za-z0-9\\-_]")) {
if (suffix.length() > 2 && suffix.charAt(0) == RdfUtils.getPostAcChar(baseURI) && suffix.charAt(1) == RdfUtils.bnodeChar &&
!(RdfUtils.bnodeChar + "").matches("[A-Za-z0-9\\-_]")) {
ns.put("node", uri + "..");
} else if (suffix.matches("[^A-Za-z0-9\\-_].*")) {
ns.put("sub", uri + suffix.charAt(0));
Expand Down
49 changes: 0 additions & 49 deletions src/main/java/net/trustyuri/rdf/UriTransformConfig.java

This file was deleted.

0 comments on commit 128ccdc

Please sign in to comment.