Skip to content

Commit 33a9223

Browse files
adds implicit "flag only" subframe to fix incomplete list recursion
1 parent c79608d commit 33a9223

File tree

5 files changed

+614
-15
lines changed

5 files changed

+614
-15
lines changed

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

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,8 +1320,6 @@ public List<Object> frame(Object input, List<Object> frame) throws JsonLdError {
13201320
*
13211321
* @param state
13221322
* the current framing state.
1323-
* @param subjects
1324-
* the subjects to filter.
13251323
* @param frame
13261324
* the frame.
13271325
* @param parent
@@ -1339,7 +1337,10 @@ private void frame(FramingContext state, Map<String, Object> nodes, Map<String,
13391337

13401338
// get flags for current frame
13411339
Boolean embedOn = getFrameFlag(frame, JsonLdConsts.EMBED, state.embed);
1342-
final Boolean explicicOn = getFrameFlag(frame, JsonLdConsts.EXPLICIT, state.explicit);
1340+
final Boolean explicitOn = getFrameFlag(frame, JsonLdConsts.EXPLICIT, state.explicit);
1341+
final Map<String, Object> flags = newMap();
1342+
flags.put(JsonLdConsts.EXPLICIT, explicitOn);
1343+
flags.put(JsonLdConsts.EMBED, embedOn);
13431344

13441345
// add matches to output
13451346
final List<String> ids = new ArrayList<String>(matches.keySet());
@@ -1411,11 +1412,7 @@ private void frame(FramingContext state, Map<String, Object> nodes, Map<String,
14111412
}
14121413

14131414
// if property isn't in the frame
1414-
if (!frame.containsKey(prop)) {
1415-
// if explicit is off, embed values
1416-
if (!explicicOn) {
1417-
embedValues(state, element, prop, output);
1418-
}
1415+
if (explicitOn && !frame.containsKey(prop)) {
14191416
continue;
14201417
}
14211418

@@ -1443,10 +1440,13 @@ private void frame(FramingContext state, Map<String, Object> nodes, Map<String,
14431440
// TODO: nodes may need to be node_map,
14441441
// which is global
14451442
tmp.put(itemid, this.nodeMap.get(itemid));
1446-
frame(state, tmp,
1447-
(Map<String, Object>) ((List<Object>) frame.get(prop))
1448-
.get(0),
1449-
list, JsonLdConsts.LIST);
1443+
Map<String, Object> subframe;
1444+
if (frame.containsKey(prop)) {
1445+
subframe = (Map<String, Object>) ((List<Object>) frame.get(prop)).get(0);
1446+
} else {
1447+
subframe = flags;
1448+
}
1449+
frame(state, tmp, subframe, list, JsonLdConsts.LIST);
14501450
} else {
14511451
// include other values automatcially (TODO:
14521452
// may need JsonLdUtils.clone(n))
@@ -1463,9 +1463,13 @@ else if (JsonLdUtils.isNodeReference(item)) {
14631463
// TODO: nodes may need to be node_map, which is
14641464
// global
14651465
tmp.put(itemid, this.nodeMap.get(itemid));
1466-
frame(state, tmp,
1467-
(Map<String, Object>) ((List<Object>) frame.get(prop)).get(0),
1468-
output, prop);
1466+
Map<String, Object> subframe;
1467+
if (frame.containsKey(prop)) {
1468+
subframe = (Map<String, Object>) ((List<Object>) frame.get(prop)).get(0);
1469+
} else {
1470+
subframe = flags;
1471+
}
1472+
frame(state, tmp, subframe, output, prop);
14691473
} else {
14701474
// include other values automatically (TODO: may
14711475
// need JsonLdUtils.clone(o))

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,22 @@ public void testFrame0002() throws IOException, JsonLdError {
4141
assertEquals(out, frame2);
4242
}
4343

44+
@Test
45+
public void testFrame0004() throws IOException, JsonLdError {
46+
final Object frame = JsonUtils
47+
.fromInputStream(getClass().getResourceAsStream("/custom/frame-0004-frame.jsonld"));
48+
final Object in = JsonUtils
49+
.fromInputStream(getClass().getResourceAsStream("/custom/frame-0004-in.jsonld"));
50+
51+
JsonLdOptions opts = new JsonLdOptions();
52+
opts.setCompactArrays(true);
53+
final Map<String, Object> frame2 = JsonLdProcessor.frame(in, frame, opts);
54+
55+
final Object out = JsonUtils
56+
.fromInputStream(getClass().getResourceAsStream("/custom/frame-0004-out.jsonld"));
57+
//System.out.println(JsonUtils.toPrettyString(out));
58+
//System.out.println(JsonUtils.toPrettyString(frame2));
59+
assertEquals(out, frame2);
60+
}
61+
4462
}
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
{ "@context" : {
2+
"sc" : "http://iiif.io/api/presentation/2#",
3+
"iiif" : "http://iiif.io/api/image/2#",
4+
"exif" : "http://www.w3.org/2003/12/exif/ns#",
5+
"oa" : "http://www.w3.org/ns/oa#",
6+
"cnt" : "http://www.w3.org/2011/content#",
7+
"dc" : "http://purl.org/dc/elements/1.1/",
8+
"dcterms" : "http://purl.org/dc/terms/",
9+
"dctypes" : "http://purl.org/dc/dcmitype/",
10+
"doap" : "http://usefulinc.com/ns/doap#",
11+
"foaf" : "http://xmlns.com/foaf/0.1/",
12+
"rdf" : "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
13+
"rdfs" : "http://www.w3.org/2000/01/rdf-schema#",
14+
"xsd" : "http://www.w3.org/2001/XMLSchema#",
15+
"svcs" : "http://rdfs.org/sioc/services#",
16+
"as" : "http://www.w3.org/ns/activitystreams#",
17+
"service" : {
18+
"@type" : "@id",
19+
"@id" : "svcs:has_service"
20+
},
21+
"profile" : {
22+
"@type" : "@id",
23+
"@id" : "doap:implements"
24+
},
25+
"manifests" : {
26+
"@type" : "@id",
27+
"@id" : "sc:hasManifests",
28+
"@container" : "@list"
29+
},
30+
"sequences" : {
31+
"@type" : "@id",
32+
"@id" : "sc:hasSequences",
33+
"@container" : "@list"
34+
},
35+
"canvases" : {
36+
"@type" : "@id",
37+
"@id" : "sc:hasCanvases",
38+
"@container" : "@list"
39+
},
40+
"resources" : {
41+
"@type" : "@id",
42+
"@id" : "sc:hasAnnotations",
43+
"@container" : "@set"
44+
},
45+
"images" : {
46+
"@type" : "@id",
47+
"@id" : "sc:hasImageAnnotations",
48+
"@container" : "@list"
49+
},
50+
"otherContent" : {
51+
"@type" : "@id",
52+
"@id" : "sc:hasLists",
53+
"@container" : "@list"
54+
},
55+
"height" : {
56+
"@type" : "xsd:integer",
57+
"@id" : "exif:height"
58+
},
59+
"width" : {
60+
"@type" : "xsd:integer",
61+
"@id" : "exif:width"
62+
},
63+
"viewingDirection" : {
64+
"@id" : "sc:viewingDirection",
65+
"@type" : "@vocab"
66+
},
67+
"viewingHint" : {
68+
"@id" : "sc:viewingHint",
69+
"@type" : "@vocab"
70+
},
71+
"paged" : {
72+
"@id" : "sc:pagedHint"
73+
},
74+
"motivation" : {
75+
"@type" : "@id",
76+
"@id" : "oa:motivatedBy"
77+
},
78+
"resource" : {
79+
"@type" : "@id",
80+
"@id" : "oa:hasBody"
81+
},
82+
"on" : {
83+
"@type" : "@id",
84+
"@id" : "oa:hasTarget"
85+
},
86+
"chars" : {
87+
"@id" : "cnt:chars"
88+
},
89+
"format" : {
90+
"@id" : "dc:format"
91+
},
92+
"value" : {
93+
"@id" : "rdf:value"
94+
},
95+
"label" : {
96+
"@id" : "rdfs:label"
97+
}
98+
},
99+
"@type": "sc:Manifest",
100+
"sequences": [
101+
{
102+
"@type": "sc:Sequence",
103+
"startCanvas": {
104+
"@type": "sc:Canvas",
105+
"@omitDefault": true,
106+
"@embed": false
107+
},
108+
"canvases": [
109+
{
110+
"@type": "sc:Canvas",
111+
"images": [
112+
{
113+
"@type": "oa:Annotation",
114+
"@embed": true
115+
}
116+
],
117+
"otherContent": [
118+
{
119+
"@type": "sc:AnnotationList",
120+
"@embed": true
121+
}
122+
]
123+
}
124+
]
125+
}
126+
],
127+
"structures": [
128+
{
129+
"@type": "sc:Range",
130+
"@embed": true,
131+
"@omitDefault": true,
132+
"canvases": [
133+
{
134+
"@embed": false
135+
}
136+
],
137+
"ranges": [
138+
{
139+
"@embed": false
140+
}
141+
]
142+
}
143+
]
144+
}

0 commit comments

Comments
 (0)