Skip to content

Commit 949c705

Browse files
committed
- Percent encoding of local names of the property URIs
0.0.7 release
1 parent cb696e8 commit 949c705

File tree

4 files changed

+40
-13
lines changed

4 files changed

+40
-13
lines changed

pom.xml

+7-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>com.github.spice-h2020</groupId>
77
<artifactId>json2rdf</artifactId>
8-
<version>0.0.6-SNAPSHOT</version>
8+
<version>0.0.7</version>
99
<packaging>jar</packaging>
1010

1111
<name>json2rdf</name>
@@ -163,6 +163,12 @@
163163
<artifactId>slf4j-jdk14</artifactId>
164164
<version>1.7.7</version>
165165
</dependency>
166+
167+
<dependency>
168+
<groupId>com.google.guava</groupId>
169+
<artifactId>guava</artifactId>
170+
<version>30.1-jre</version>
171+
</dependency>
166172

167173
<dependency>
168174
<groupId>com.jsoniter</groupId>

src/main/java/com/github/spiceh2020/json2rdf/transformers/JSONTransformer.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ private void getModel(JSONObject object, Resource r, Model m) {
8080
// m.add(r, RDF.type, RDFS.Resource);
8181
object.keys().forEachRemaining(k -> {
8282
Object o = object.get(k);
83-
Property p = m.createProperty(propertyPrefix + k);
83+
Property p = m.createProperty(propertyPrefix + Utils.toSafeURIString(k));
8484
// m.add(p, RDFS.label, m.createTypedLiteral(k));
8585
if (o instanceof String || o instanceof Boolean || o instanceof Integer) {
8686
transformPrimites(m, r, p, o);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.github.spiceh2020.json2rdf.transformers;
2+
3+
import com.google.common.escape.UnicodeEscaper;
4+
import com.google.common.net.PercentEscaper;
5+
6+
public class Utils {
7+
static UnicodeEscaper basicEscaper = new PercentEscaper("%", false);
8+
9+
public static String toSafeURIString(String s) {
10+
return basicEscaper.escape(s);
11+
}
12+
13+
}

src/test/java/com/github/spiceh2020/json2rdf/test/JSON2RDFTransformerTest.java

+19-11
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ public void testEmptyAndNull() {
4545
}
4646
{
4747
JSONTransformer_JSONIter jt = new JSONTransformer_JSONIter(ontologyPrefix);
48-
4948

5049
assertEquals(jt.transformJSON("{}").size(), 0L);
5150
assertEquals(jt.transformJSON("[]").size(), 0L);
@@ -103,15 +102,13 @@ public void testPrimitive() {
103102
mn.add(rn, mn.createProperty(ontologyPrefix + "string"), mn.createTypedLiteral("string"));
104103
mn.add(rn, mn.createProperty(ontologyPrefix + "bool"), mn.createTypedLiteral(true));
105104
mn.add(rn, mn.createProperty(ontologyPrefix + "boolf"), mn.createTypedLiteral(false));
106-
105+
107106
// mn.add(mn.createProperty(ontologyPrefix + "a"), RDFS.label, mn.createTypedLiteral("a"));
108107
// mn.add(mn.createProperty(ontologyPrefix + "string"), RDFS.label, mn.createTypedLiteral("string"));
109108
// mn.add(mn.createProperty(ontologyPrefix + "bool"), RDFS.label, mn.createTypedLiteral("bool"));
110109
// mn.add(mn.createProperty(ontologyPrefix + "boolf"), RDFS.label, mn.createTypedLiteral("boolf"));
111110
// mn.add(mn.createProperty(ontologyPrefix + "n"), RDFS.label, mn.createTypedLiteral("n"));
112-
113-
114-
111+
115112
assertTrue(mn.isIsomorphicWith(jtN.transformJSON(primitive1)));
116113
}
117114
}
@@ -127,15 +124,14 @@ public void testPrimitive() {
127124
m.add(r, m.createProperty(ontologyPrefix + "string"), m.createTypedLiteral("string"));
128125
m.add(r, m.createProperty(ontologyPrefix + "bool"), m.createTypedLiteral(true));
129126
m.add(r, m.createProperty(ontologyPrefix + "boolf"), m.createTypedLiteral(false));
130-
127+
131128
// m.add(r, RDF.type, RDFS.Resource);
132129
// m.add(m.createProperty(ontologyPrefix + "a"), RDFS.label, m.createTypedLiteral("a"));
133130
// m.add(m.createProperty(ontologyPrefix + "string"), RDFS.label, m.createTypedLiteral("string"));
134131
// m.add(m.createProperty(ontologyPrefix + "bool"), RDFS.label, m.createTypedLiteral("bool"));
135132
// m.add(m.createProperty(ontologyPrefix + "boolf"), RDFS.label, m.createTypedLiteral("boolf"));
136133
// m.add(m.createProperty(ontologyPrefix + "n"), RDFS.label, m.createTypedLiteral("n"));
137-
138-
134+
139135
assertTrue(m.isIsomorphicWith(jt.transformJSON(primitive1)));
140136
}
141137

@@ -151,14 +147,13 @@ public void testPrimitive() {
151147
mn.add(rn, mn.createProperty(ontologyPrefix + "string"), mn.createTypedLiteral("string"));
152148
mn.add(rn, mn.createProperty(ontologyPrefix + "bool"), mn.createTypedLiteral(true));
153149
mn.add(rn, mn.createProperty(ontologyPrefix + "boolf"), mn.createTypedLiteral(false));
154-
150+
155151
// mn.add(mn.createProperty(ontologyPrefix + "a"), RDFS.label, mn.createTypedLiteral("a"));
156152
// mn.add(mn.createProperty(ontologyPrefix + "string"), RDFS.label, mn.createTypedLiteral("string"));
157153
// mn.add(mn.createProperty(ontologyPrefix + "bool"), RDFS.label, mn.createTypedLiteral("bool"));
158154
// mn.add(mn.createProperty(ontologyPrefix + "boolf"), RDFS.label, mn.createTypedLiteral("boolf"));
159155
// mn.add(mn.createProperty(ontologyPrefix + "n"), RDFS.label, mn.createTypedLiteral("n"));
160-
161-
156+
162157
assertTrue(mn.isIsomorphicWith(jtN.transformJSON(primitive1)));
163158
}
164159
}
@@ -282,4 +277,17 @@ public void testDuplicateKeyJSON() {
282277
}
283278
}
284279

280+
@Test
281+
public void testWhiteSpace() {
282+
String test = "{\"a b\":{\"a c\":\"c\"}}";
283+
JSONTransformer jt = new JSONTransformer(ontologyPrefix);
284+
285+
Model m = ModelFactory.createDefaultModel();
286+
Resource r = m.createResource(), r1 = m.createResource();
287+
m.add(r, m.createProperty(ontologyPrefix + "a%20b"), r1);
288+
m.add(r1, m.createProperty(ontologyPrefix + "a%20c"), m.createTypedLiteral("c"));
289+
290+
assertTrue(m.isIsomorphicWith(jt.transformJSON(test)));
291+
}
292+
285293
}

0 commit comments

Comments
 (0)