Skip to content

Commit b2dcff1

Browse files
committed
Add test to verify that the RDFDataset API is not the key to the IRI
appearing in the context in expanded form for issue jsonld-java#140 Seems to be setup manually in the Jena code: https://github.com/apache/jena/blob/d480bd1fc36d4f7a9b286a607dbc66ea4988b64d/jena-arq/src/main/java/org/apache/jena/riot/out/JsonLDWriter.java#L147
1 parent e27acd7 commit b2dcff1

File tree

1 file changed

+47
-20
lines changed

1 file changed

+47
-20
lines changed

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

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,51 +30,78 @@ public void toRdfWithNamespace() throws Exception {
3030

3131
@Test
3232
public void fromRdfWithNamespaceLexicographicallyShortestChosen() throws Exception {
33-
33+
3434
RDFDataset inputRdf = new RDFDataset();
3535
inputRdf.setNamespace("aat", "http://vocab.getty.edu/aat/");
3636
inputRdf.setNamespace("aat_rev", "http://vocab.getty.edu/aat/rev/");
37-
38-
inputRdf.addTriple("http://vocab.getty.edu/aat/rev/5001065997", JsonLdConsts.RDF_TYPE, "http://vocab.getty.edu/aat/datatype");
39-
37+
38+
inputRdf.addTriple("http://vocab.getty.edu/aat/rev/5001065997", JsonLdConsts.RDF_TYPE,
39+
"http://vocab.getty.edu/aat/datatype");
40+
4041
final JsonLdOptions options = new JsonLdOptions();
4142
options.useNamespaces = true;
42-
43-
Object fromRDF = JsonLdProcessor.compact(new JsonLdApi(options).fromRDF(inputRdf),inputRdf.getContext(), options);
44-
43+
44+
Object fromRDF = JsonLdProcessor.compact(new JsonLdApi(options).fromRDF(inputRdf),
45+
inputRdf.getContext(), options);
46+
4547
final RDFDataset rdf = (RDFDataset) JsonLdProcessor.toRDF(fromRDF, options);
4648
System.out.println(rdf.getNamespaces());
4749
assertEquals("http://vocab.getty.edu/aat/", rdf.getNamespace("aat"));
4850
assertEquals("http://vocab.getty.edu/aat/rev/", rdf.getNamespace("aat_rev"));
49-
51+
5052
String toJSONLD = JsonUtils.toPrettyString(fromRDF);
5153
System.out.println(toJSONLD);
52-
53-
assertTrue("The lexicographically shortest URI was not chosen", toJSONLD.contains("aat:rev/"));
54+
55+
assertTrue("The lexicographically shortest URI was not chosen",
56+
toJSONLD.contains("aat:rev/"));
5457
}
5558

5659
@Test
5760
public void fromRdfWithNamespaceLexicographicallyShortestChosen2() throws Exception {
58-
61+
5962
RDFDataset inputRdf = new RDFDataset();
6063
inputRdf.setNamespace("aat", "http://vocab.getty.edu/aat/");
6164
inputRdf.setNamespace("aatrev", "http://vocab.getty.edu/aat/rev/");
62-
63-
inputRdf.addTriple("http://vocab.getty.edu/aat/rev/5001065997", JsonLdConsts.RDF_TYPE, "http://vocab.getty.edu/aat/datatype");
64-
65+
66+
inputRdf.addTriple("http://vocab.getty.edu/aat/rev/5001065997", JsonLdConsts.RDF_TYPE,
67+
"http://vocab.getty.edu/aat/datatype");
68+
6569
final JsonLdOptions options = new JsonLdOptions();
6670
options.useNamespaces = true;
67-
68-
Object fromRDF = JsonLdProcessor.compact(new JsonLdApi(options).fromRDF(inputRdf),inputRdf.getContext(), options);
69-
71+
72+
Object fromRDF = JsonLdProcessor.compact(new JsonLdApi(options).fromRDF(inputRdf),
73+
inputRdf.getContext(), options);
74+
7075
final RDFDataset rdf = (RDFDataset) JsonLdProcessor.toRDF(fromRDF, options);
7176
System.out.println(rdf.getNamespaces());
7277
assertEquals("http://vocab.getty.edu/aat/", rdf.getNamespace("aat"));
7378
assertEquals("http://vocab.getty.edu/aat/rev/", rdf.getNamespace("aatrev"));
74-
79+
7580
String toJSONLD = JsonUtils.toPrettyString(fromRDF);
7681
System.out.println(toJSONLD);
77-
78-
assertFalse("The lexicographically shortest URI was not chosen", toJSONLD.contains("aat:rev/"));
82+
83+
assertFalse("The lexicographically shortest URI was not chosen",
84+
toJSONLD.contains("aat:rev/"));
85+
}
86+
87+
@Test
88+
public void prefixUsedToShortenPredicate() throws Exception {
89+
final RDFDataset inputRdf = new RDFDataset();
90+
inputRdf.setNamespace("ex", "http://www.a.com/foo/");
91+
inputRdf.addTriple("http://www.a.com/foo/s", "http://www.a.com/foo/p",
92+
"http://www.a.com/foo/o");
93+
assertEquals("http://www.a.com/foo/", inputRdf.getNamespace("ex"));
94+
95+
final JsonLdOptions options = new JsonLdOptions();
96+
options.useNamespaces = true;
97+
98+
Object fromRDF = JsonLdProcessor.compact(new JsonLdApi(options).fromRDF(inputRdf),
99+
inputRdf.getContext(), options);
100+
String toJSONLD = JsonUtils.toPrettyString(fromRDF);
101+
System.out.println(toJSONLD);
102+
103+
assertFalse("The lexicographically shortest URI was not chosen",
104+
toJSONLD.contains("http://www.a.com/foo/p"));
79105
}
106+
80107
}

0 commit comments

Comments
 (0)