Skip to content

Commit a04b9b7

Browse files
committed
Choose the longest prefix in JsonLdUtils.compareShortestLeast
1 parent a417e24 commit a04b9b7

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

core/src/main/java/com/github/jsonldjava/core/JsonLdUtils.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,12 @@ static int compareShortestLeast(String a, String b) {
602602
return -1;
603603
} else if (b.length() < a.length()) {
604604
return 1;
605+
} else if (a.indexOf(":") != b.indexOf(":")){
606+
// Attempt to disambiguate to get the longest prefix,
607+
// by looking for the highest position for ":"
608+
return a.indexOf(":") < b.indexOf(":") ? 1 : -1;
605609
}
610+
606611
return Integer.signum(a.compareTo(b));
607612
}
608613

core/src/test/java/com/github/jsonldjava/core/LongestPrefixTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public void fromRdfWithNamespaceLexicographicallyShortestChosen() throws Excepti
6363
String toJSONLD = JsonUtils.toPrettyString(fromRDF);
6464
System.out.println(toJSONLD);
6565

66-
assertTrue("The lexicographically shortest URI was not chosen", toJSONLD.contains("aat:rev/"));
66+
assertFalse("The lexicographically shortest URI was not chosen", toJSONLD.contains("aat:rev/"));
6767

6868
final RDFDataset rdf = (RDFDataset) JsonLdProcessor.toRDF(fromRDF, options);
6969
System.out.println(rdf.getNamespaces());

0 commit comments

Comments
 (0)