Skip to content

Commit 673dac2

Browse files
committed
Implement @type to be defined with @container: @set
- add test compact-104 See w3c/json-ld-syntax#34.
1 parent 2fcaa78 commit 673dac2

File tree

5 files changed

+30
-2
lines changed

5 files changed

+30
-2
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,9 @@ private void createTermDefinition(Map<String, Object> context, String term,
310310

311311
defined.put(term, false);
312312

313-
if (JsonLdUtils.isKeyword(term)) {
313+
if ( JsonLdUtils.isKeyword(term)//
314+
&& !(JsonLdConsts.TYPE.equals(term)//
315+
&& !(context.get(term)).toString().contains(JsonLdConsts.ID)) ) {
314316
throw new JsonLdError(Error.KEYWORD_REDEFINITION, term);
315317
}
316318

@@ -439,7 +441,7 @@ else if (term.indexOf(":") >= 0) {
439441
// 15)
440442
} else if (this.containsKey(JsonLdConsts.VOCAB)) {
441443
definition.put(JsonLdConsts.ID, this.get(JsonLdConsts.VOCAB) + term);
442-
} else {
444+
} else if (!JsonLdConsts.TYPE.equals(term)) {
443445
throw new JsonLdError(Error.INVALID_IRI_MAPPING,
444446
"relative term definition without vocab mapping");
445447
}
@@ -454,6 +456,8 @@ else if (term.indexOf(":") >= 0) {
454456
"@container must be either @list, @set, @index, or @language");
455457
}
456458
definition.put(JsonLdConsts.CONTAINER, container);
459+
if (JsonLdConsts.TYPE.equals(term))
460+
definition.put(JsonLdConsts.ID,"type");
457461
}
458462

459463
// 17)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"@context": {
3+
"@type": {"@container": "@set"}
4+
}
5+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"@type": "http://example.org/type"
3+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"@context": {
3+
"@type": {"@container": "@set"}
4+
},
5+
"@type": ["http://example.org/type"]
6+
}

core/src/test/resources/json-ld.org/compact-manifest.jsonld

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,16 @@
586586
"context": "compact-0072-context.jsonld",
587587
"expect": "compact-0072-out.jsonld"
588588
},
589+
{
590+
"@id": "#t0104",
591+
"@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"],
592+
"name": "Compact @type with @container: @set",
593+
"purpose": "Ensures that a single @type value is represented as an array",
594+
"input": "compact-0104-in.jsonld",
595+
"context": "compact-0104-context.jsonld",
596+
"expect": "compact-0104-out.jsonld",
597+
"option": {"processingMode": "json-ld-1.1", "specVersion": "json-ld-1.1"}
598+
},
589599
{
590600
"@id": "#t0105",
591601
"@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"],

0 commit comments

Comments
 (0)