Skip to content

Commit 2fcaa78

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

File tree

8 files changed

+37
-10
lines changed

8 files changed

+37
-10
lines changed

core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<artifactId>jsonld-java-parent</artifactId>
66
<groupId>com.github.jsonld-java</groupId>
7-
<version>0.12.2-SNAPSHOT</version>
7+
<version>0.12.3-SNAPSHOT</version>
88
</parent>
99
<modelVersion>4.0.0</modelVersion>
1010
<artifactId>jsonld-java</artifactId>

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,13 +1044,15 @@ private String selectTerm(String iri, List<String> containers, String typeLangua
10441044
*
10451045
* @param property
10461046
* The Property to get a container mapping for.
1047-
* @return The container mapping
1047+
* @return The container mapping if any, else null
10481048
*/
10491049
public String getContainer(String property) {
1050+
if (property==null) return null;
10501051
if (JsonLdConsts.GRAPH.equals(property)) {
10511052
return JsonLdConsts.SET;
10521053
}
1053-
if (JsonLdUtils.isKeyword(property)) {
1054+
if (!property.equals(JsonLdConsts.TYPE)
1055+
&& JsonLdUtils.isKeyword(property)) {
10541056
return property;
10551057
}
10561058
final Map<String, Object> td = (Map<String, Object>) termDefinitions.get(property);

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,13 @@ public Object compact(Context activeCtx, String activeProperty, Object element,
202202
Collections.sort(keys);
203203
for (final String expandedProperty : keys) {
204204
final Object expandedValue = elem.get(expandedProperty);
205-
206205
// 7.1)
207206
if (JsonLdConsts.ID.equals(expandedProperty)
208207
|| JsonLdConsts.TYPE.equals(expandedProperty)) {
208+
// 7.1.3)
209+
final String alias = activeCtx.compactIri(expandedProperty, true);
209210
Object compactedValue;
210-
211+
211212
// 7.1.1)
212213
if (expandedValue instanceof String) {
213214
compactedValue = activeCtx.compactIri((String) expandedValue,
@@ -221,15 +222,15 @@ public Object compact(Context activeCtx, String activeProperty, Object element,
221222
types.add(activeCtx.compactIri(expandedType, true));
222223
}
223224
// 7.1.2.3)
224-
if (types.size() == 1) {
225+
if ( types.size() == 1
226+
// see w3c/json-ld-syntax#74
227+
&& ! (activeCtx.getContainer(alias) != null
228+
&& activeCtx.getContainer(alias).equals(JsonLdConsts.SET)) ) {
225229
compactedValue = types.get(0);
226230
} else {
227231
compactedValue = types;
228232
}
229233
}
230-
231-
// 7.1.3)
232-
final String alias = activeCtx.compactIri(expandedProperty, true);
233234
// 7.1.4)
234235
result.put(alias, compactedValue);
235236
continue;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"@context": {
3+
"type": {"@id": "@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": {"@id": "@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
@@ -585,6 +585,16 @@
585585
"input": "compact-0072-in.jsonld",
586586
"context": "compact-0072-context.jsonld",
587587
"expect": "compact-0072-out.jsonld"
588+
},
589+
{
590+
"@id": "#t0105",
591+
"@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"],
592+
"name": "Compact @type with @container: @set using an alias of @type",
593+
"purpose": "Ensures that a single @type value is represented as an array",
594+
"input": "compact-0105-in.jsonld",
595+
"context": "compact-0105-context.jsonld",
596+
"expect": "compact-0105-out.jsonld",
597+
"option": {"processingMode": "json-ld-1.1", "specVersion": "json-ld-1.1"}
588598
}
589599
]
590600
}

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>com.github.jsonld-java</groupId>
66
<artifactId>jsonld-java-parent</artifactId>
7-
<version>0.12.2-SNAPSHOT</version>
7+
<version>0.12.3-SNAPSHOT</version>
88
<name>JSONLD Java :: Parent</name>
99
<description>Json-LD Java Parent POM</description>
1010
<packaging>pom</packaging>

0 commit comments

Comments
 (0)