You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by fc...@apache.org on 2011/09/30 11:38:02 UTC
svn commit: r1177566 [2/3] - in /incubator/stanbol/trunk:
commons/jsonld/src/main/java/org/apache/stanbol/commons/jsonld/
commons/jsonld/src/test/java/org/apache/stanbol/commons/jsonld/
commons/web/base/src/main/java/org/apache/stanbol/commons/web/base...
Modified: incubator/stanbol/trunk/commons/jsonld/src/test/java/org/apache/stanbol/commons/jsonld/JsonLdTest.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/jsonld/src/test/java/org/apache/stanbol/commons/jsonld/JsonLdTest.java?rev=1177566&r1=1177565&r2=1177566&view=diff
==============================================================================
--- incubator/stanbol/trunk/commons/jsonld/src/test/java/org/apache/stanbol/commons/jsonld/JsonLdTest.java (original)
+++ incubator/stanbol/trunk/commons/jsonld/src/test/java/org/apache/stanbol/commons/jsonld/JsonLdTest.java Fri Sep 30 09:38:01 2011
@@ -16,10 +16,7 @@
*/
package org.apache.stanbol.commons.jsonld;
-import static org.junit.Assert.*;
-
-import java.util.HashMap;
-import java.util.Map;
+import static org.junit.Assert.assertEquals;
import org.junit.After;
import org.junit.Before;
@@ -44,6 +41,8 @@ public class JsonLdTest {
JsonLd jsonLd = new JsonLd();
jsonLd.setUseTypeCoercion(false);
jsonLd.addNamespacePrefix("http://example.org/myvocab#", "myvocab");
+ jsonLd.addNamespacePrefix("http://xmlns.com/foaf/0.1/", "foaf");
+ jsonLd.addNamespacePrefix("http://sioc.org/vocab/1/", "sioc");
JsonLdResource jsonLdResource = new JsonLdResource();
jsonLdResource.addType("foaf:Person");
@@ -51,14 +50,14 @@ public class JsonLdTest {
jsonLdResource.putProperty("foaf:homepage", "<http://manu.sporny.org/>");
jsonLdResource.putProperty("sioc:avatar", "<http://twitter.com/account/profile_image/manusporny>");
jsonLdResource.putProperty("myvocab:credits", 500);
- jsonLd.put("dummy", jsonLdResource);
+ jsonLd.put(jsonLdResource);
String actual = jsonLd.toString();
- String expected = "{\"#\":{\"myvocab\":\"http:\\/\\/example.org\\/myvocab#\"},\"a\":\"foaf:Person\",\"foaf:homepage\":\"<http:\\/\\/manu.sporny.org\\/>\",\"foaf:name\":\"Manu Sporny\",\"myvocab:credits\":500,\"sioc:avatar\":\"<http:\\/\\/twitter.com\\/account\\/profile_image\\/manusporny>\"}";
+ String expected = "{\"@context\":{\"foaf\":\"http://xmlns.com/foaf/0.1/\",\"myvocab\":\"http://example.org/myvocab#\",\"sioc\":\"http://sioc.org/vocab/1/\"},\"@type\":\"foaf:Person\",\"foaf:homepage\":\"<http://manu.sporny.org/>\",\"foaf:name\":\"Manu Sporny\",\"myvocab:credits\":500,\"sioc:avatar\":\"<http://twitter.com/account/profile_image/manusporny>\"}";
assertEquals(expected, actual);
String actualIndent = jsonLd.toString(4);
- String expectedIndent = "{\n \"#\": {\n \"myvocab\": \"http:\\/\\/example.org\\/myvocab#\"\n },\n \"a\": \"foaf:Person\",\n \"foaf:homepage\": \"<http:\\/\\/manu.sporny.org\\/>\",\n \"foaf:name\": \"Manu Sporny\",\n \"myvocab:credits\": 500,\n \"sioc:avatar\": \"<http:\\/\\/twitter.com\\/account\\/profile_image\\/manusporny>\"\n}";
+ String expectedIndent = "{\n \"@context\": {\n \"foaf\": \"http://xmlns.com/foaf/0.1/\",\n \"myvocab\": \"http://example.org/myvocab#\",\n \"sioc\": \"http://sioc.org/vocab/1/\"\n },\n \"@type\": \"foaf:Person\",\n \"foaf:homepage\": \"<http://manu.sporny.org/>\",\n \"foaf:name\": \"Manu Sporny\",\n \"myvocab:credits\": 500,\n \"sioc:avatar\": \"<http://twitter.com/account/profile_image/manusporny>\"\n}";
assertEquals(expectedIndent, actualIndent);
}
@@ -91,11 +90,11 @@ public class JsonLdTest {
jsonLd.put(r3.getSubject(), r3);
String actual = jsonLd.toString();
- String expected = "{\"#\":{\"foaf\":\"http:\\/\\/xmlns.com\\/foaf\\/0.1\\/\"},\"@\":[{\"@\":\"_:bnode1\",\"a\":\"foaf:Person\",\"foaf:homepage\":\"<http:\\/\\/example.com\\/bob>\",\"foaf:name\":\"Bob\"},{\"@\":\"_:bnode2\",\"a\":\"foaf:Person\",\"foaf:homepage\":\"<http:\\/\\/example.com\\/eve>\",\"foaf:name\":\"Eve\"},{\"@\":\"_:bnode3\",\"a\":\"foaf:Person\",\"foaf:homepage\":\"<http:\\/\\/example.com\\/bert>\",\"foaf:name\":\"Bert\"}]}";
+ String expected = "{\"@context\":{\"foaf\":\"http://xmlns.com/foaf/0.1/\"},\"@subject\":[{\"@subject\":\"_:bnode1\",\"@type\":\"foaf:Person\",\"foaf:homepage\":\"<http://example.com/bob>\",\"foaf:name\":\"Bob\"},{\"@subject\":\"_:bnode2\",\"@type\":\"foaf:Person\",\"foaf:homepage\":\"<http://example.com/eve>\",\"foaf:name\":\"Eve\"},{\"@subject\":\"_:bnode3\",\"@type\":\"foaf:Person\",\"foaf:homepage\":\"<http://example.com/bert>\",\"foaf:name\":\"Bert\"}]}";
assertEquals(expected, actual);
String actualIndent = jsonLd.toString(4);
- String expectedIndent = "{\n \"#\": {\n \"foaf\": \"http:\\/\\/xmlns.com\\/foaf\\/0.1\\/\"\n },\n \"@\": [\n {\n \"@\": \"_:bnode1\",\n \"a\": \"foaf:Person\",\n \"foaf:homepage\": \"<http:\\/\\/example.com\\/bob>\",\n \"foaf:name\": \"Bob\"\n },\n {\n \"@\": \"_:bnode2\",\n \"a\": \"foaf:Person\",\n \"foaf:homepage\": \"<http:\\/\\/example.com\\/eve>\",\n \"foaf:name\": \"Eve\"\n },\n {\n \"@\": \"_:bnode3\",\n \"a\": \"foaf:Person\",\n \"foaf:homepage\": \"<http:\\/\\/example.com\\/bert>\",\n \"foaf:name\": \"Bert\"\n }\n ]\n}";
+ String expectedIndent = "{\n \"@context\": {\n \"foaf\": \"http://xmlns.com/foaf/0.1/\"\n },\n \"@subject\": [\n {\n \"@subject\": \"_:bnode1\",\n \"@type\": \"foaf:Person\",\n \"foaf:homepage\": \"<http://example.com/bob>\",\n \"foaf:name\": \"Bob\"\n },\n {\n \"@subject\": \"_:bnode2\",\n \"@type\": \"foaf:Person\",\n \"foaf:homepage\": \"<http://example.com/eve>\",\n \"foaf:name\": \"Eve\"\n },\n {\n \"@subject\": \"_:bnode3\",\n \"@type\": \"foaf:Person\",\n \"foaf:homepage\": \"<http://example.com/bert>\",\n \"foaf:name\": \"Bert\"\n }\n ]\n}";
assertEquals(expectedIndent, actualIndent);
}
@@ -128,11 +127,11 @@ public class JsonLdTest {
jsonLd.put(r3.getSubject(), r3);
String actual = jsonLd.toString();
- String expected = "[{\"#\":{\"foaf\":\"http:\\/\\/xmlns.com\\/foaf\\/0.1\\/\"},\"@\":\"_:bnode1\",\"a\":\"foaf:Person\",\"foaf:homepage\":\"<http:\\/\\/example.com\\/bob>\",\"foaf:name\":\"Bob\"},{\"#\":{\"foaf\":\"http:\\/\\/xmlns.com\\/foaf\\/0.1\\/\"},\"@\":\"_:bnode2\",\"a\":\"foaf:Person\",\"foaf:homepage\":\"<http:\\/\\/example.com\\/eve>\",\"foaf:name\":\"Eve\"},{\"#\":{\"foaf\":\"http:\\/\\/xmlns.com\\/foaf\\/0.1\\/\"},\"@\":\"_:bnode3\",\"a\":\"foaf:Person\",\"foaf:homepage\":\"<http:\\/\\/example.com\\/eve>\",\"foaf:name\":\"Eve\"}]";
+ String expected = "[{\"@context\":{\"foaf\":\"http://xmlns.com/foaf/0.1/\"},\"@subject\":\"_:bnode1\",\"@type\":\"foaf:Person\",\"foaf:homepage\":\"<http://example.com/bob>\",\"foaf:name\":\"Bob\"},{\"@context\":{\"foaf\":\"http://xmlns.com/foaf/0.1/\"},\"@subject\":\"_:bnode2\",\"@type\":\"foaf:Person\",\"foaf:homepage\":\"<http://example.com/eve>\",\"foaf:name\":\"Eve\"},{\"@context\":{\"foaf\":\"http://xmlns.com/foaf/0.1/\"},\"@subject\":\"_:bnode3\",\"@type\":\"foaf:Person\",\"foaf:homepage\":\"<http://example.com/eve>\",\"foaf:name\":\"Eve\"}]";
assertEquals(expected, actual);
String actualIndent = jsonLd.toString(4);
- String expectedIndent = "[\n {\n \"#\": {\n \"foaf\": \"http:\\/\\/xmlns.com\\/foaf\\/0.1\\/\"\n },\n \"@\": \"_:bnode1\",\n \"a\": \"foaf:Person\",\n \"foaf:homepage\": \"<http:\\/\\/example.com\\/bob>\",\n \"foaf:name\": \"Bob\"\n },\n {\n \"#\": {\n \"foaf\": \"http:\\/\\/xmlns.com\\/foaf\\/0.1\\/\"\n },\n \"@\": \"_:bnode2\",\n \"a\": \"foaf:Person\",\n \"foaf:homepage\": \"<http:\\/\\/example.com\\/eve>\",\n \"foaf:name\": \"Eve\"\n },\n {\n \"#\": {\n \"foaf\": \"http:\\/\\/xmlns.com\\/foaf\\/0.1\\/\"\n },\n \"@\": \"_:bnode3\",\n \"a\": \"foaf:Person\",\n \"foaf:homepage\": \"<http:\\/\\/example.com\\/eve>\",\n \"foaf:name\": \"Eve\"\n }\n]";
+ String expectedIndent = "[\n {\n \"@context\": {\n \"foaf\": \"http://xmlns.com/foaf/0.1/\"\n },\n \"@subject\": \"_:bnode1\",\n \"@type\": \"foaf:Person\",\n \"foaf:homepage\": \"<http://example.com/bob>\",\n \"foaf:name\": \"Bob\"\n },\n {\n \"@context\": {\n \"foaf\": \"http://xmlns.com/foaf/0.1/\"\n },\n \"@subject\": \"_:bnode2\",\n \"@type\": \"foaf:Person\",\n \"foaf:homepage\": \"<http://example.com/eve>\",\n \"foaf:name\": \"Eve\"\n },\n {\n \"@context\": {\n \"foaf\": \"http://xmlns.com/foaf/0.1/\"\n },\n \"@subject\": \"_:bnode3\",\n \"@type\": \"foaf:Person\",\n \"foaf:homepage\": \"<http://example.com/eve>\",\n \"foaf:name\": \"Eve\"\n }\n]";
assertEquals(expectedIndent, actualIndent);
}
@@ -152,11 +151,11 @@ public class JsonLdTest {
jsonLd.put(r1.getSubject(), r1);
String actual = jsonLd.toString();
- String expected = "{\"#\":{\"fn\":\"http:\\/\\/microformats.org\\/profile\\/hcard#fn\",\"url\":\"http:\\/\\/microformats.org\\/profile\\/hcard#url\",\"vcard\":\"http:\\/\\/microformats.org\\/profile\\/hcard#vcard\"},\"@\":\"_:bnode1\",\"a\":\"vcard\",\"fn\":\"Tantek Celik\",\"url\":\"<http:\\/\\/tantek.com\\/>\"}";
+ String expected = "{\"@context\":{\"fn\":\"http://microformats.org/profile/hcard#fn\",\"url\":\"http://microformats.org/profile/hcard#url\",\"vcard\":\"http://microformats.org/profile/hcard#vcard\"},\"@subject\":\"_:bnode1\",\"@type\":\"vcard\",\"fn\":\"Tantek Celik\",\"url\":\"<http://tantek.com/>\"}";
assertEquals(expected, actual);
String actualIndent = jsonLd.toString(4);
- String expectedIndent = "{\n \"#\": {\n \"fn\": \"http:\\/\\/microformats.org\\/profile\\/hcard#fn\",\n \"url\": \"http:\\/\\/microformats.org\\/profile\\/hcard#url\",\n \"vcard\": \"http:\\/\\/microformats.org\\/profile\\/hcard#vcard\"\n },\n \"@\": \"_:bnode1\",\n \"a\": \"vcard\",\n \"fn\": \"Tantek Celik\",\n \"url\": \"<http:\\/\\/tantek.com\\/>\"\n}";
+ String expectedIndent = "{\n \"@context\": {\n \"fn\": \"http://microformats.org/profile/hcard#fn\",\n \"url\": \"http://microformats.org/profile/hcard#url\",\n \"vcard\": \"http://microformats.org/profile/hcard#vcard\"\n },\n \"@subject\": \"_:bnode1\",\n \"@type\": \"vcard\",\n \"fn\": \"Tantek Celik\",\n \"url\": \"<http://tantek.com/>\"\n}";
assertEquals(expectedIndent, actualIndent);
}
@@ -164,8 +163,6 @@ public class JsonLdTest {
public void testSpecExample3DefaultContext() {
JsonLd jsonLd = new JsonLd();
jsonLd.setUseTypeCoercion(false);
- jsonLd.addNamespacePrefix("http://example.org/default-vocab#","#vocab");
- jsonLd.addNamespacePrefix("http://example.org/baseurl/","#base");
jsonLd.addNamespacePrefix("http://www.w3.org/2001/XMLSchema#", "xsd");
jsonLd.addNamespacePrefix("http://purl.org/dc/terms/", "dc");
jsonLd.addNamespacePrefix("http://xmlns.com/foaf/0.1/", "foaf");
@@ -180,12 +177,8 @@ public class JsonLdTest {
jsonLd.addNamespacePrefix("http://xmlns.com/foaf/0.1/homepage", "homepage");
String actual = jsonLd.toString();
- String expected = "{\"#\":{\"#base\":\"http:\\/\\/example.org\\/baseurl\\/\",\"#vocab\":\"http:\\/\\/example.org\\/default-vocab#\",\"cal\":\"http:\\/\\/www.w3.org\\/2002\\/12\\/cal\\/ical#\",\"cc\":\"http:\\/\\/creativecommons.org\\/ns#\",\"dc\":\"http:\\/\\/purl.org\\/dc\\/terms\\/\",\"doap\":\"http:\\/\\/usefulinc.com\\/ns\\/doap#\",\"foaf\":\"http:\\/\\/xmlns.com\\/foaf\\/0.1\\/\",\"geo\":\"http:\\/\\/www.w3.org\\/2003\\/01\\/geo\\/wgs84_pos#\",\"homepage\":\"http:\\/\\/xmlns.com\\/foaf\\/0.1\\/homepage\",\"name\":\"http:\\/\\/xmlns.com\\/foaf\\/0.1\\/name\",\"Person\":\"http:\\/\\/xmlns.com\\/foaf\\/0.1\\/Person\",\"sioc\":\"http:\\/\\/rdfs.org\\/sioc\\/ns#\",\"vcard\":\"http:\\/\\/www.w3.org\\/2006\\/vcard\\/ns#\",\"xsd\":\"http:\\/\\/www.w3.org\\/2001\\/XMLSchema#\"}}";
+ String expected = "{}";
assertEquals(expected, actual);
-
- String actualIndent = jsonLd.toString(4);
- String expectedIndent = "{\n \"#\": {\n \"#base\": \"http:\\/\\/example.org\\/baseurl\\/\",\n \"#vocab\": \"http:\\/\\/example.org\\/default-vocab#\",\n \"cal\": \"http:\\/\\/www.w3.org\\/2002\\/12\\/cal\\/ical#\",\n \"cc\": \"http:\\/\\/creativecommons.org\\/ns#\",\n \"dc\": \"http:\\/\\/purl.org\\/dc\\/terms\\/\",\n \"doap\": \"http:\\/\\/usefulinc.com\\/ns\\/doap#\",\n \"foaf\": \"http:\\/\\/xmlns.com\\/foaf\\/0.1\\/\",\n \"geo\": \"http:\\/\\/www.w3.org\\/2003\\/01\\/geo\\/wgs84_pos#\",\n \"homepage\": \"http:\\/\\/xmlns.com\\/foaf\\/0.1\\/homepage\",\n \"name\": \"http:\\/\\/xmlns.com\\/foaf\\/0.1\\/name\",\n \"Person\": \"http:\\/\\/xmlns.com\\/foaf\\/0.1\\/Person\",\n \"sioc\": \"http:\\/\\/rdfs.org\\/sioc\\/ns#\",\n \"vcard\": \"http:\\/\\/www.w3.org\\/2006\\/vcard\\/ns#\",\n \"xsd\": \"http:\\/\\/www.w3.org\\/2001\\/XMLSchema#\"\n }\n}";
- assertEquals(expectedIndent, actualIndent);
}
@Test
@@ -216,11 +209,11 @@ public class JsonLdTest {
jsonLd.put(r3.getSubject(), r3);
String actual = jsonLd.toString();
- String expected = "[{\"@\":\"<http:\\/\\/purl.oreilly.com\\/products\\/9780596007683.BOOK>\",\"a\":\"<http:\\/\\/purl.org\\/vocab\\/frbr\\/core#Expression>\",\"http:\\/\\/purl.org\\/dc\\/terms\\/type\":\"<http:\\/\\/purl.oreilly.com\\/product-types\\/BOOK>\"},{\"@\":\"<http:\\/\\/purl.oreilly.com\\/products\\/9780596802189.EBOOK>\",\"a\":\"http:\\/\\/purl.org\\/vocab\\/frbr\\/core#Expression\",\"http:\\/\\/purl.org\\/dc\\/terms\\/type\":\"<http:\\/\\/purl.oreilly.com\\/product-types\\/BOOK>\"},{\"@\":\"<http:\\/\\/purl.oreilly.com\\/works\\/45U8QJGZSQKDH8N>\",\"a\":\"http:\\/\\/purl.org\\/vocab\\/frbr\\/core#Work\",\"http:\\/\\/purl.org\\/dc\\/terms\\/creator\":\"Whil Wheaton\",\"http:\\/\\/purl.org\\/dc\\/terms\\/title\":\"Just a Geek\",\"http:\\/\\/purl.org\\/vocab\\/frbr\\/core#realization\":[\"<http:\\/\\/purl.oreilly.com\\/products\\/9780596007683.BOOK>\",\"<http:\\/\\/purl.oreilly.com\\/products\\/9780596802189.EBOOK>\"]}]";
+ String expected = "[{\"@subject\":\"<http://purl.oreilly.com/products/9780596007683.BOOK>\",\"@type\":\"<http://purl.org/vocab/frbr/core#Expression>\",\"http://purl.org/dc/terms/type\":\"<http://purl.oreilly.com/product-types/BOOK>\"},{\"@subject\":\"<http://purl.oreilly.com/products/9780596802189.EBOOK>\",\"@type\":\"http://purl.org/vocab/frbr/core#Expression\",\"http://purl.org/dc/terms/type\":\"<http://purl.oreilly.com/product-types/BOOK>\"},{\"@subject\":\"<http://purl.oreilly.com/works/45U8QJGZSQKDH8N>\",\"@type\":\"http://purl.org/vocab/frbr/core#Work\",\"http://purl.org/dc/terms/creator\":\"Whil Wheaton\",\"http://purl.org/dc/terms/title\":\"Just a Geek\",\"http://purl.org/vocab/frbr/core#realization\":[\"<http://purl.oreilly.com/products/9780596007683.BOOK>\",\"<http://purl.oreilly.com/products/9780596802189.EBOOK>\"]}]";
assertEquals(expected, actual);
String actualIndent = jsonLd.toString(4);
- String expectedIndent = "[\n {\n \"@\": \"<http:\\/\\/purl.oreilly.com\\/products\\/9780596007683.BOOK>\",\n \"a\": \"<http:\\/\\/purl.org\\/vocab\\/frbr\\/core#Expression>\",\n \"http:\\/\\/purl.org\\/dc\\/terms\\/type\": \"<http:\\/\\/purl.oreilly.com\\/product-types\\/BOOK>\"\n },\n {\n \"@\": \"<http:\\/\\/purl.oreilly.com\\/products\\/9780596802189.EBOOK>\",\n \"a\": \"http:\\/\\/purl.org\\/vocab\\/frbr\\/core#Expression\",\n \"http:\\/\\/purl.org\\/dc\\/terms\\/type\": \"<http:\\/\\/purl.oreilly.com\\/product-types\\/BOOK>\"\n },\n {\n \"@\": \"<http:\\/\\/purl.oreilly.com\\/works\\/45U8QJGZSQKDH8N>\",\n \"a\": \"http:\\/\\/purl.org\\/vocab\\/frbr\\/core#Work\",\n \"http:\\/\\/purl.org\\/dc\\/terms\\/creator\": \"Whil Wheaton\",\n \"http:\\/\\/purl.org\\/dc\\/terms\\/title\": \"Just a Geek\",\n \"http:\\/\\/purl.org\\/vocab\\/frbr\\/core#realization\": [\n \"<
http:\\/\\/purl.oreilly.com\\/products\\/9780596007683.BOOK>\",\n \"<http:\\/\\/purl.oreilly.com\\/products\\/9780596802189.EBOOK>\"\n ]\n }\n]";
+ String expectedIndent = "[\n {\n \"@subject\": \"<http://purl.oreilly.com/products/9780596007683.BOOK>\",\n \"@type\": \"<http://purl.org/vocab/frbr/core#Expression>\",\n \"http://purl.org/dc/terms/type\": \"<http://purl.oreilly.com/product-types/BOOK>\"\n },\n {\n \"@subject\": \"<http://purl.oreilly.com/products/9780596802189.EBOOK>\",\n \"@type\": \"http://purl.org/vocab/frbr/core#Expression\",\n \"http://purl.org/dc/terms/type\": \"<http://purl.oreilly.com/product-types/BOOK>\"\n },\n {\n \"@subject\": \"<http://purl.oreilly.com/works/45U8QJGZSQKDH8N>\",\n \"@type\": \"http://purl.org/vocab/frbr/core#Work\",\n \"http://purl.org/dc/terms/creator\": \"Whil Wheaton\",\n \"http://purl.org/dc/terms/title\": \"Just a Geek\",\n \"http://purl.org/vocab/frbr/core#realization\": [\n \"<http://purl.oreilly.com/products/9780596007683.BOOK>\",\n \"<http://purl.ore
illy.com/products/9780596802189.EBOOK>\"\n ]\n }\n]";
assertEquals(expectedIndent, actualIndent);
}
@@ -236,12 +229,8 @@ public class JsonLdTest {
jsonLd.put("r1", r1);
String actual = jsonLd.toString();
- String expected = "{\"#\":{\"dc\":\"http:\\/\\/purl.org\\/dc\\/terms\\/\",\"xsd\":\"http:\\/\\/www.w3.org\\/2001\\/XMLSchema#\"},\"dc:modified\":\"2010-05-29T14:17:39+02:00^^xsd:dateTime\"}";
+ String expected = "{\"@context\":{\"dc\":\"http://purl.org/dc/terms/\",\"xsd\":\"http://www.w3.org/2001/XMLSchema#\"},\"dc:modified\":\"2010-05-29T14:17:39+02:00^^xsd:dateTime\"}";
assertEquals(expected, actual);
-
- String actualIndent = jsonLd.toString(4);
- String expectedIndent = "{\n \"#\": {\n \"dc\": \"http:\\/\\/purl.org\\/dc\\/terms\\/\",\n \"xsd\": \"http:\\/\\/www.w3.org\\/2001\\/XMLSchema#\"\n },\n \"dc:modified\": \"2010-05-29T14:17:39+02:00^^xsd:dateTime\"\n}";
- assertEquals(expectedIndent, actualIndent);
}
@Test
@@ -257,11 +246,11 @@ public class JsonLdTest {
r1.setSubject("<http://example.org/people#joebob>");
String nick = "\"stu\"^^http://www.w3.org/2001/XMLSchema#string";
r1.putProperty("http://xmlns.com/foaf/0.1/nick", nick);
- r1.putCoercionType("http://xmlns.com/foaf/0.1/nick", "xsd:string");
+ r1.putPropertyType("http://xmlns.com/foaf/0.1/nick", "xsd:string");
jsonLd.put("r1", r1);
String actual = jsonLd.toString();
- String expected = "{\"#\":{\"foaf\":\"http:\\/\\/xmlns.com\\/foaf\\/0.1\\/\",\"xsd\":\"http:\\/\\/www.w3.org\\/2001\\/XMLSchema#\",\"#types\":{\"http:\\/\\/xmlns.com\\/foaf\\/0.1\\/nick\":\"http:\\/\\/www.w3.org\\/2001\\/XMLSchema#string\"}},\"@\":\"<http:\\/\\/example.org\\/people#joebob>\",\"http:\\/\\/xmlns.com\\/foaf\\/0.1\\/nick\":\"stu\"}";
+ String expected = "{\"@context\":{\"@coerce\":{\"http://www.w3.org/2001/XMLSchema#string\":\"http://xmlns.com/foaf/0.1/nick\"}},\"@subject\":\"<http://example.org/people#joebob>\",\"http://xmlns.com/foaf/0.1/nick\":\"stu\"}";
assertEquals(expected, actual);
}
@@ -278,11 +267,11 @@ public class JsonLdTest {
r1.setSubject("<http://example.org/people#joebob>");
String nick = "\"stu\"^^http://www.w3.org/2001/XMLSchema#string";
r1.putProperty("http://xmlns.com/foaf/0.1/nick", nick);
- r1.putCoercionType("http://xmlns.com/foaf/0.1/nick", "xsd:string");
- jsonLd.put("r1", r1);
+ r1.putPropertyType("http://xmlns.com/foaf/0.1/nick", "xsd:string");
+ jsonLd.put(r1);
String actual = jsonLd.toString();
- String expected = "{\"#\":{\"foaf\":\"http:\\/\\/xmlns.com\\/foaf\\/0.1\\/\",\"xsd\":\"http:\\/\\/www.w3.org\\/2001\\/XMLSchema#\",\"#types\":{\"foaf:nick\":\"xsd:string\"}},\"@\":\"<http:\\/\\/example.org\\/people#joebob>\",\"foaf:nick\":\"stu\"}";
+ String expected = "{\"@context\":{\"foaf\":\"http://xmlns.com/foaf/0.1/\",\"xsd\":\"http://www.w3.org/2001/XMLSchema#\",\"@coerce\":{\"xsd:string\":\"foaf:nick\"}},\"@subject\":\"<http://example.org/people#joebob>\",\"foaf:nick\":\"stu\"}";
assertEquals(expected, actual);
}
@@ -297,13 +286,12 @@ public class JsonLdTest {
JsonLdResource r1 = new JsonLdResource();
r1.setSubject("<http://example.org/people#joebob>");
- String nick = "\"stu\"^^http://www.w3.org/2001/XMLSchema#string";
- r1.putProperty("http://xmlns.com/foaf/0.1/nick", nick);
- r1.putCoercionType("http://xmlns.com/foaf/0.1/nick", "xsd:string");
- jsonLd.put("r1", r1);
+ r1.putProperty("http://xmlns.com/foaf/0.1/nick", "stu");
+ r1.putPropertyType("http://xmlns.com/foaf/0.1/nick", "xsd:string");
+ jsonLd.put(r1);
String actual = jsonLd.toString();
- String expected = "{\"#\":{\"foaf\":\"http:\\/\\/xmlns.com\\/foaf\\/0.1\\/\",\"xsd\":\"http:\\/\\/www.w3.org\\/2001\\/XMLSchema#\"},\"@\":\"<http:\\/\\/example.org\\/people#joebob>\",\"http:\\/\\/xmlns.com\\/foaf\\/0.1\\/nick\":\"\\\"stu\\\"^^http:\\/\\/www.w3.org\\/2001\\/XMLSchema#string\"}";
+ String expected = "{\"@subject\":\"<http://example.org/people#joebob>\",\"http://xmlns.com/foaf/0.1/nick\":{\"@literal\":\"stu\",\"@datatype\":\"http://www.w3.org/2001/XMLSchema#string\"}}";
assertEquals(expected, actual);
}
@@ -318,13 +306,12 @@ public class JsonLdTest {
JsonLdResource r1 = new JsonLdResource();
r1.setSubject("<http://example.org/people#joebob>");
- String nick = "\"stu\"^^http://www.w3.org/2001/XMLSchema#string";
- r1.putProperty("http://xmlns.com/foaf/0.1/nick", nick);
- r1.putCoercionType("http://xmlns.com/foaf/0.1/nick", "xsd:string");
- jsonLd.put("r1", r1);
+ r1.putProperty("http://xmlns.com/foaf/0.1/nick", "stu");
+ r1.putPropertyType("http://xmlns.com/foaf/0.1/nick", "xsd:string");
+ jsonLd.put(r1);
String actual = jsonLd.toString();
- String expected = "{\"#\":{\"foaf\":\"http:\\/\\/xmlns.com\\/foaf\\/0.1\\/\",\"xsd\":\"http:\\/\\/www.w3.org\\/2001\\/XMLSchema#\"},\"@\":\"<http:\\/\\/example.org\\/people#joebob>\",\"foaf:nick\":\"\\\"stu\\\"^^xsd:string\"}";
+ String expected = "{\"@context\":{\"foaf\":\"http://xmlns.com/foaf/0.1/\",\"xsd\":\"http://www.w3.org/2001/XMLSchema#\"},\"@subject\":\"<http://example.org/people#joebob>\",\"foaf:nick\":{\"@literal\":\"stu\",\"@datatype\":\"xsd:string\"}}";
assertEquals(expected, actual);
}
@@ -337,68 +324,79 @@ public class JsonLdTest {
JsonLdResource r1 = new JsonLdResource();
r1.setSubject("<http://example.org/people#joebob>");
- String [] nicks = new String [] {"\"stu\"^^http://www.w3.org/2001/XMLSchema#string", "\"groknar\"^^http://www.w3.org/2001/XMLSchema#string", "\"radface\"^^http://www.w3.org/2001/XMLSchema#string"};
- r1.putProperty("http://xmlns.com/foaf/0.1/nick", nicks);
- jsonLd.put("r1", r1);
+ String [] nicks = new String [] {"stu", "groknar", "radface"};
+ r1.putProperty("foaf:nick", nicks);
+ jsonLd.put(r1);
String actual = jsonLd.toString();
- String expected = "{\"#\":{\"foaf\":\"http:\\/\\/xmlns.com\\/foaf\\/0.1\\/\",\"xsd\":\"http:\\/\\/www.w3.org\\/2001\\/XMLSchema#\"},\"@\":\"<http:\\/\\/example.org\\/people#joebob>\",\"foaf:nick\":[\"\\\"stu\\\"^^xsd:string\",\"\\\"groknar\\\"^^xsd:string\",\"\\\"radface\\\"^^xsd:string\"]}";
+ String expected = "{\"@context\":{\"foaf\":\"http://xmlns.com/foaf/0.1/\"},\"@subject\":\"<http://example.org/people#joebob>\",\"foaf:nick\":[\"stu\",\"groknar\",\"radface\"]}";
assertEquals(expected, actual);
-
- String actualIndent = jsonLd.toString(4);
- String expectedIndent = "{\n \"#\": {\n \"foaf\": \"http:\\/\\/xmlns.com\\/foaf\\/0.1\\/\",\n \"xsd\": \"http:\\/\\/www.w3.org\\/2001\\/XMLSchema#\"\n },\n \"@\": \"<http:\\/\\/example.org\\/people#joebob>\",\n \"foaf:nick\": [\n \"\\\"stu\\\"^^xsd:string\",\n \"\\\"groknar\\\"^^xsd:string\",\n \"\\\"radface\\\"^^xsd:string\"\n ]\n}";
- assertEquals(expectedIndent, actualIndent);
}
@Test
- public void testSpecExample7NoNSApply() {
+ public void testSpecExample6MultipleTypedObjects() {
JsonLd jsonLd = new JsonLd();
jsonLd.setUseTypeCoercion(false);
- jsonLd.setApplyNamespaces(false);
jsonLd.addNamespacePrefix("http://www.w3.org/2001/XMLSchema#", "xsd");
jsonLd.addNamespacePrefix("http://xmlns.com/foaf/0.1/", "foaf");
JsonLdResource r1 = new JsonLdResource();
r1.setSubject("<http://example.org/people#joebob>");
- String [] nicks = new String [] {"\"stu\"^^http://www.w3.org/2001/XMLSchema#string", "\"groknar\"^^http://www.w3.org/2001/XMLSchema#string", "\"radface\"^^http://www.w3.org/2001/XMLSchema#string"};
- r1.putProperty("http://xmlns.com/foaf/0.1/nick", nicks);
- jsonLd.put("r1", r1);
+ String [] nicks = new String [] {"stu", "groknar", "radface"};
+ r1.putProperty("foaf:nick", nicks);
+ r1.putPropertyType("foaf:nick", "xsd:string");
+ jsonLd.put(r1);
String actual = jsonLd.toString();
- String expected = "{\"#\":{\"foaf\":\"http:\\/\\/xmlns.com\\/foaf\\/0.1\\/\",\"xsd\":\"http:\\/\\/www.w3.org\\/2001\\/XMLSchema#\"},\"@\":\"<http:\\/\\/example.org\\/people#joebob>\",\"http:\\/\\/xmlns.com\\/foaf\\/0.1\\/nick\":[\"\\\"stu\\\"^^http:\\/\\/www.w3.org\\/2001\\/XMLSchema#string\",\"\\\"groknar\\\"^^http:\\/\\/www.w3.org\\/2001\\/XMLSchema#string\",\"\\\"radface\\\"^^http:\\/\\/www.w3.org\\/2001\\/XMLSchema#string\"]}";
+ String expected = "{\"@context\":{\"foaf\":\"http://xmlns.com/foaf/0.1/\",\"xsd\":\"http://www.w3.org/2001/XMLSchema#\"},\"@subject\":\"<http://example.org/people#joebob>\",\"foaf:nick\":[{\"@literal\":\"stu\",\"@datatype\":\"xsd:string\"},{\"@literal\":\"groknar\",\"@datatype\":\"xsd:string\"},{\"@literal\":\"radface\",\"@datatype\":\"xsd:string\"}]}";
assertEquals(expected, actual);
String actualIndent = jsonLd.toString(4);
- String expectedIndent = "{\n \"#\": {\n \"foaf\": \"http:\\/\\/xmlns.com\\/foaf\\/0.1\\/\",\n \"xsd\": \"http:\\/\\/www.w3.org\\/2001\\/XMLSchema#\"\n },\n \"@\": \"<http:\\/\\/example.org\\/people#joebob>\",\n \"http:\\/\\/xmlns.com\\/foaf\\/0.1\\/nick\": [\n \"\\\"stu\\\"^^http:\\/\\/www.w3.org\\/2001\\/XMLSchema#string\",\n \"\\\"groknar\\\"^^http:\\/\\/www.w3.org\\/2001\\/XMLSchema#string\",\n \"\\\"radface\\\"^^http:\\/\\/www.w3.org\\/2001\\/XMLSchema#string\"\n ]\n}";
+ String expectedIndent = "{\n \"@context\": {\n \"foaf\": \"http://xmlns.com/foaf/0.1/\",\n \"xsd\": \"http://www.w3.org/2001/XMLSchema#\"\n },\n \"@subject\": \"<http://example.org/people#joebob>\",\n \"foaf:nick\": [\n {\n \"@literal\": \"stu\",\n \"@datatype\": \"xsd:string\"\n },\n {\n \"@literal\": \"groknar\",\n \"@datatype\": \"xsd:string\"\n },\n {\n \"@literal\": \"radface\",\n \"@datatype\": \"xsd:string\"\n }\n ]\n}";
assertEquals(expectedIndent, actualIndent);
}
@Test
- public void testSpecExample8NoNSApply() {
+ public void testSpecExample6MultipleObjectsCoerce() {
JsonLd jsonLd = new JsonLd();
- jsonLd.setUseTypeCoercion(false);
jsonLd.setApplyNamespaces(false);
-
+ jsonLd.setUseTypeCoercion(true);
jsonLd.addNamespacePrefix("http://www.w3.org/2001/XMLSchema#", "xsd");
jsonLd.addNamespacePrefix("http://xmlns.com/foaf/0.1/", "foaf");
JsonLdResource r1 = new JsonLdResource();
r1.setSubject("<http://example.org/people#joebob>");
- String [] nicks = new String [] {"\"stu\"^^xsd:string", "\"groknar\"^^xsd:string", "\"radface\"^^xsd:string"};
- r1.putProperty("http://xmlns.com/foaf/0.1/nick", nicks);
- jsonLd.put("r1", r1);
+ String [] nicks = new String [] {"stu", "groknar", "radface"};
+ r1.putProperty("foaf:nick", nicks);
+ r1.putPropertyType("foaf:nick", "xsd:string");
+ jsonLd.put(r1);
String actual = jsonLd.toString();
- String expected = "{\"#\":{\"foaf\":\"http:\\/\\/xmlns.com\\/foaf\\/0.1\\/\",\"xsd\":\"http:\\/\\/www.w3.org\\/2001\\/XMLSchema#\"},\"@\":\"<http:\\/\\/example.org\\/people#joebob>\",\"http:\\/\\/xmlns.com\\/foaf\\/0.1\\/nick\":[\"\\\"stu\\\"^^xsd:string\",\"\\\"groknar\\\"^^xsd:string\",\"\\\"radface\\\"^^xsd:string\"]}";
+ String expected = "{\"@context\":{\"@coerce\":{\"http://www.w3.org/2001/XMLSchema#string\":\"http://xmlns.com/foaf/0.1/nick\"}},\"@subject\":\"<http://example.org/people#joebob>\",\"http://xmlns.com/foaf/0.1/nick\":[\"stu\",\"groknar\",\"radface\"]}";
assertEquals(expected, actual);
+ }
- String actualIndent = jsonLd.toString(4);
- String expectedIndent = "{\n \"#\": {\n \"foaf\": \"http:\\/\\/xmlns.com\\/foaf\\/0.1\\/\",\n \"xsd\": \"http:\\/\\/www.w3.org\\/2001\\/XMLSchema#\"\n },\n \"@\": \"<http:\\/\\/example.org\\/people#joebob>\",\n \"http:\\/\\/xmlns.com\\/foaf\\/0.1\\/nick\": [\n \"\\\"stu\\\"^^xsd:string\",\n \"\\\"groknar\\\"^^xsd:string\",\n \"\\\"radface\\\"^^xsd:string\"\n ]\n}";
- assertEquals(expectedIndent, actualIndent);
+ @Test
+ public void testSpecExample6MultipleObjectsNsCoerce() {
+ JsonLd jsonLd = new JsonLd();
+ jsonLd.setUseTypeCoercion(true);
+ jsonLd.addNamespacePrefix("http://www.w3.org/2001/XMLSchema#", "xsd");
+ jsonLd.addNamespacePrefix("http://xmlns.com/foaf/0.1/", "foaf");
+
+ JsonLdResource r1 = new JsonLdResource();
+ r1.setSubject("<http://example.org/people#joebob>");
+ String [] nicks = new String [] {"stu", "groknar", "radface"};
+ r1.putProperty("foaf:nick", nicks);
+ r1.putPropertyType("foaf:nick", "xsd:string");
+ jsonLd.put(r1);
+
+ String actual = jsonLd.toString();
+ String expected = "{\"@context\":{\"foaf\":\"http://xmlns.com/foaf/0.1/\",\"xsd\":\"http://www.w3.org/2001/XMLSchema#\",\"@coerce\":{\"xsd:string\":\"foaf:nick\"}},\"@subject\":\"<http://example.org/people#joebob>\",\"foaf:nick\":[\"stu\",\"groknar\",\"radface\"]}";
+ assertEquals(expected, actual);
}
@Test
- public void testComplexArrays() {
+ public void testMultipleIRIsNoNsCoerce() {
JsonLd jsonLd = new JsonLd();
jsonLd.setUseTypeCoercion(true);
jsonLd.setApplyNamespaces(false);
@@ -410,32 +408,24 @@ public class JsonLdTest {
JsonLdResource r1 = new JsonLdResource();
r1.setSubject("<http://example.org/people#joebob>");
- Map<String,Object> nick1 = new HashMap<String,Object>();
- nick1.put("@iri", "nick:stu");
-
- Map<String,Object> nick2 = new HashMap<String,Object>();
- nick2.put("@iri", "nick:pet");
-
- Map<String,Object> nick3 = new HashMap<String,Object>();
- nick3.put("@iri", "nick:flo");
-
- Object [] nicks = new Object [] {nick1, nick2, nick3};
+ Object [] nicks = new Object [] {"nick:stu", "nick:pet", "nick:flo"};
r1.putProperty("http://xmlns.com/foaf/0.1/nick", nicks);
- jsonLd.put("r1", r1);
+ r1.putPropertyType("http://xmlns.com/foaf/0.1/nick", "@iri");
+ jsonLd.put(r1);
String actual = jsonLd.toString();
- String expected = "{\"#\":{\"foaf\":\"http:\\/\\/xmlns.com\\/foaf\\/0.1\\/\",\"nick\":\"http:\\/\\/nickworld.com\\/nicks\\/\",\"xsd\":\"http:\\/\\/www.w3.org\\/2001\\/XMLSchema#\"},\"@\":\"<http:\\/\\/example.org\\/people#joebob>\",\"http:\\/\\/xmlns.com\\/foaf\\/0.1\\/nick\":[{\"@iri\":\"http:\\/\\/nickworld.com\\/nicks\\/stu\"},{\"@iri\":\"http:\\/\\/nickworld.com\\/nicks\\/pet\"},{\"@iri\":\"http:\\/\\/nickworld.com\\/nicks\\/flo\"}]}";
+ String expected = "{\"@context\":{\"@coerce\":{\"@iri\":\"http://xmlns.com/foaf/0.1/nick\"}},\"@subject\":\"<http://example.org/people#joebob>\",\"http://xmlns.com/foaf/0.1/nick\":[\"http://nickworld.com/nicks/stu\",\"http://nickworld.com/nicks/pet\",\"http://nickworld.com/nicks/flo\"]}";
assertEquals(expected, actual);
String actualIndent = jsonLd.toString(4);
- String expectedIndent = "{\n \"#\": {\n \"foaf\": \"http:\\/\\/xmlns.com\\/foaf\\/0.1\\/\",\n \"nick\": \"http:\\/\\/nickworld.com\\/nicks\\/\",\n \"xsd\": \"http:\\/\\/www.w3.org\\/2001\\/XMLSchema#\"\n },\n \"@\": \"<http:\\/\\/example.org\\/people#joebob>\",\n \"http:\\/\\/xmlns.com\\/foaf\\/0.1\\/nick\": [\n {\n \"@iri\": \"http:\\/\\/nickworld.com\\/nicks\\/stu\"\n },\n {\n \"@iri\": \"http:\\/\\/nickworld.com\\/nicks\\/pet\"\n },\n {\n \"@iri\": \"http:\\/\\/nickworld.com\\/nicks\\/flo\"\n }\n ]\n}";
+ String expectedIndent = "{\n \"@context\": {\n \"@coerce\": {\n \"@iri\": \"http://xmlns.com/foaf/0.1/nick\"\n }\n },\n \"@subject\": \"<http://example.org/people#joebob>\",\n \"http://xmlns.com/foaf/0.1/nick\": [\n \"http://nickworld.com/nicks/stu\",\n \"http://nickworld.com/nicks/pet\",\n \"http://nickworld.com/nicks/flo\"\n ]\n}";
assertEquals(expectedIndent, actualIndent);
}
@Test
- public void testComplexArraysWithIRIs() {
+ public void testMultipleIRIs() {
JsonLd jsonLd = new JsonLd();
- jsonLd.setUseTypeCoercion(true);
+ jsonLd.setUseTypeCoercion(false);
jsonLd.setApplyNamespaces(false);
jsonLd.addNamespacePrefix("http://www.w3.org/2001/XMLSchema#", "xsd");
@@ -451,19 +441,41 @@ public class JsonLdTest {
Object [] nicks = new Object [] {nick1, nick2, nick3};
r1.putProperty("http://xmlns.com/foaf/0.1/nick", nicks);
- jsonLd.put("r1", r1);
+ jsonLd.put(r1);
String actual = jsonLd.toString();
- String expected = "{\"#\":{\"foaf\":\"http:\\/\\/xmlns.com\\/foaf\\/0.1\\/\",\"nick\":\"http:\\/\\/nickworld.com\\/nicks\\/\",\"xsd\":\"http:\\/\\/www.w3.org\\/2001\\/XMLSchema#\"},\"@\":\"<http:\\/\\/example.org\\/people#joebob>\",\"http:\\/\\/xmlns.com\\/foaf\\/0.1\\/nick\":[{\"@iri\":\"http:\\/\\/nickworld.com\\/nicks\\/stu\"},{\"@iri\":\"http:\\/\\/nickworld.com\\/nicks\\/pet\"},{\"@iri\":\"http:\\/\\/nickworld.com\\/nicks\\/flo\"}]}";
+ String expected = "{\"@subject\":\"<http://example.org/people#joebob>\",\"http://xmlns.com/foaf/0.1/nick\":[{\"@iri\":\"http://nickworld.com/nicks/stu\"},{\"@iri\":\"http://nickworld.com/nicks/pet\"},{\"@iri\":\"http://nickworld.com/nicks/flo\"}]}";
assertEquals(expected, actual);
+ }
+
+ @Test
+ public void testMultipleIRIsWithNS() {
+ JsonLd jsonLd = new JsonLd();
+ jsonLd.setUseTypeCoercion(false);
+ jsonLd.setApplyNamespaces(true);
- String actualIndent = jsonLd.toString(4);
- String expectedIndent = "{\n \"#\": {\n \"foaf\": \"http:\\/\\/xmlns.com\\/foaf\\/0.1\\/\",\n \"nick\": \"http:\\/\\/nickworld.com\\/nicks\\/\",\n \"xsd\": \"http:\\/\\/www.w3.org\\/2001\\/XMLSchema#\"\n },\n \"@\": \"<http:\\/\\/example.org\\/people#joebob>\",\n \"http:\\/\\/xmlns.com\\/foaf\\/0.1\\/nick\": [\n {\n \"@iri\": \"http:\\/\\/nickworld.com\\/nicks\\/stu\"\n },\n {\n \"@iri\": \"http:\\/\\/nickworld.com\\/nicks\\/pet\"\n },\n {\n \"@iri\": \"http:\\/\\/nickworld.com\\/nicks\\/flo\"\n }\n ]\n}";
- assertEquals(expectedIndent, actualIndent);
+ jsonLd.addNamespacePrefix("http://www.w3.org/2001/XMLSchema#", "xsd");
+ jsonLd.addNamespacePrefix("http://xmlns.com/foaf/0.1/", "foaf");
+ jsonLd.addNamespacePrefix("http://nickworld.com/nicks/", "nick");
+
+ JsonLdResource r1 = new JsonLdResource();
+ r1.setSubject("<http://example.org/people#joebob>");
+
+ JsonLdIRI nick1 = new JsonLdIRI("nick:stu");
+ JsonLdIRI nick2 = new JsonLdIRI("nick:pet");
+ JsonLdIRI nick3 = new JsonLdIRI("nick:flo");
+
+ Object [] nicks = new Object [] {nick1, nick2, nick3};
+ r1.putProperty("http://xmlns.com/foaf/0.1/nick", nicks);
+ jsonLd.put(r1);
+
+ String actual = jsonLd.toString();
+ String expected = "{\"@context\":{\"foaf\":\"http://xmlns.com/foaf/0.1/\",\"nick\":\"http://nickworld.com/nicks/\"},\"@subject\":\"<http://example.org/people#joebob>\",\"foaf:nick\":[{\"@iri\":\"nick:stu\"},{\"@iri\":\"nick:pet\"},{\"@iri\":\"nick:flo\"}]}";
+ assertEquals(expected, actual);
}
@Test
- public void testComplexArraysWithIRIsWithNS() {
+ public void testMultipleIRIsWithNSCoerce() {
JsonLd jsonLd = new JsonLd();
jsonLd.setUseTypeCoercion(true);
jsonLd.setApplyNamespaces(true);
@@ -481,15 +493,12 @@ public class JsonLdTest {
Object [] nicks = new Object [] {nick1, nick2, nick3};
r1.putProperty("http://xmlns.com/foaf/0.1/nick", nicks);
- jsonLd.put("r1", r1);
+ r1.putPropertyType("http://xmlns.com/foaf/0.1/nick", "@iri");
+ jsonLd.put(r1);
String actual = jsonLd.toString();
- String expected = "{\"#\":{\"foaf\":\"http:\\/\\/xmlns.com\\/foaf\\/0.1\\/\",\"nick\":\"http:\\/\\/nickworld.com\\/nicks\\/\",\"xsd\":\"http:\\/\\/www.w3.org\\/2001\\/XMLSchema#\"},\"@\":\"<http:\\/\\/example.org\\/people#joebob>\",\"foaf:nick\":[{\"@iri\":\"nick:stu\"},{\"@iri\":\"nick:pet\"},{\"@iri\":\"nick:flo\"}]}";
+ String expected = "{\"@context\":{\"foaf\":\"http://xmlns.com/foaf/0.1/\",\"@coerce\":{\"@iri\":\"foaf:nick\"}},\"@subject\":\"<http://example.org/people#joebob>\",\"foaf:nick\":[\"nick:stu\",\"nick:pet\",\"nick:flo\"]}";
assertEquals(expected, actual);
-
- String actualIndent = jsonLd.toString(4);
- String expectedIndent = "{\n \"#\": {\n \"foaf\": \"http:\\/\\/xmlns.com\\/foaf\\/0.1\\/\",\n \"nick\": \"http:\\/\\/nickworld.com\\/nicks\\/\",\n \"xsd\": \"http:\\/\\/www.w3.org\\/2001\\/XMLSchema#\"\n },\n \"@\": \"<http:\\/\\/example.org\\/people#joebob>\",\n \"foaf:nick\": [\n {\n \"@iri\": \"nick:stu\"\n },\n {\n \"@iri\": \"nick:pet\"\n },\n {\n \"@iri\": \"nick:flo\"\n }\n ]\n}";
- assertEquals(expectedIndent, actualIndent);
}
@Test
@@ -505,7 +514,7 @@ public class JsonLdTest {
jsonLd.put(r1);
String actual = jsonLd.toString();
- String expected = "{\"#\":{\"foaf\":\"http:\\/\\/xmlns.com\\/foaf\\/0.1\\/\",\"xsd\":\"http:\\/\\/www.w3.org\\/2001\\/XMLSchema#\"},\"@\":\"_:bnode1\",\"@profile\":\"testprofile\"}";
+ String expected = "{\"@subject\":\"_:bnode1\",\"@profile\":\"testprofile\"}";
assertEquals(expected, actual);
}
@@ -519,20 +528,80 @@ public class JsonLdTest {
jsonLd.addNamespacePrefix("http://xmlns.com/foaf/0.1/", "foaf");
JsonLdResource r1 = new JsonLdResource();
- r1.putCoercionType("foaf:age", "http:\\/\\/www.w3.org\\/2001\\/XMLSchema#int");
r1.setSubject("_:bnode1");
r1.putProperty("foaf:age", 31);
+ r1.putPropertyType("foaf:age", "http://www.w3.org/2001/XMLSchema#int");
jsonLd.put(r1);
String actual = jsonLd.toString();
- String expected = "{\"#\":{\"foaf\":\"http:\\/\\/xmlns.com\\/foaf\\/0.1\\/\",\"xsd\":\"http:\\/\\/www.w3.org\\/2001\\/XMLSchema#\",\"#types\":{\"foaf:age\":\"http:\\\\\\/\\\\\\/www.w3.org\\\\\\/2001\\\\\\/XMLSchema#int\"}},\"@\":\"_:bnode1\",\"foaf:age\":31}";
+ String expected = "{\"@context\":{\"foaf\":\"http://xmlns.com/foaf/0.1/\",\"xsd\":\"http://www.w3.org/2001/XMLSchema#\",\"@coerce\":{\"xsd:int\":\"foaf:age\"}},\"@subject\":\"_:bnode1\",\"foaf:age\":31}";
assertEquals(expected, actual);
String actualIndented = jsonLd.toString(2);
- String expectedIndented = "{\n \"#\": {\n \"foaf\": \"http:\\/\\/xmlns.com\\/foaf\\/0.1\\/\",\n \"xsd\": \"http:\\/\\/www.w3.org\\/2001\\/XMLSchema#\",\n \"#types\": {\n \"foaf:age\": \"http:\\\\\\/\\\\\\/www.w3.org\\\\\\/2001\\\\\\/XMLSchema#int\"\n }\n },\n \"@\": \"_:bnode1\",\n \"foaf:age\": 31\n}";
+ String expectedIndented = "{\n \"@context\": {\n \"foaf\": \"http://xmlns.com/foaf/0.1/\",\n \"xsd\": \"http://www.w3.org/2001/XMLSchema#\",\n \"@coerce\": {\n \"xsd:int\": \"foaf:age\"\n }\n },\n \"@subject\": \"_:bnode1\",\n \"foaf:age\": 31\n}";
assertEquals(expectedIndented, actualIndented);
}
+ @Test
+ public void testIntegerValueNoCoerce() {
+ JsonLd jsonLd = new JsonLd();
+ jsonLd.setApplyNamespaces(true);
+ jsonLd.setUseTypeCoercion(false);
+
+ jsonLd.addNamespacePrefix("http://www.w3.org/2001/XMLSchema#", "xsd");
+ jsonLd.addNamespacePrefix("http://xmlns.com/foaf/0.1/", "foaf");
+
+ JsonLdResource r1 = new JsonLdResource();
+ r1.setSubject("_:bnode1");
+ r1.putProperty("foaf:age", 31);
+ r1.putPropertyType("foaf:age", "http://www.w3.org/2001/XMLSchema#int");
+ jsonLd.put(r1);
+
+ String actual = jsonLd.toString();
+ String expected = "{\"@context\":{\"foaf\":\"http://xmlns.com/foaf/0.1/\",\"xsd\":\"http://www.w3.org/2001/XMLSchema#\"},\"@subject\":\"_:bnode1\",\"foaf:age\":{\"@literal\":\"31\",\"@datatype\":\"xsd:int\"}}";
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void testFloatValue() {
+ JsonLd jsonLd = new JsonLd();
+ jsonLd.setApplyNamespaces(true);
+ jsonLd.setUseTypeCoercion(true);
+
+ jsonLd.addNamespacePrefix("http://www.w3.org/2001/XMLSchema#", "xsd");
+ jsonLd.addNamespacePrefix("http://xmlns.com/foaf/0.1/", "foaf");
+
+ JsonLdResource r1 = new JsonLdResource();
+ r1.setSubject("_:bnode1");
+ r1.putProperty("foaf:age", 31.533567);
+ r1.putPropertyType("foaf:age", "http://www.w3.org/2001/XMLSchema#int");
+ jsonLd.put(r1);
+
+ String actual = jsonLd.toString();
+ String expected = "{\"@context\":{\"foaf\":\"http://xmlns.com/foaf/0.1/\",\"xsd\":\"http://www.w3.org/2001/XMLSchema#\",\"@coerce\":{\"xsd:int\":\"foaf:age\"}},\"@subject\":\"_:bnode1\",\"foaf:age\":31.533567}";
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void testFloatValueNoCoerce() {
+ JsonLd jsonLd = new JsonLd();
+ jsonLd.setApplyNamespaces(true);
+ jsonLd.setUseTypeCoercion(false);
+
+ jsonLd.addNamespacePrefix("http://www.w3.org/2001/XMLSchema#", "xsd");
+ jsonLd.addNamespacePrefix("http://xmlns.com/foaf/0.1/", "foaf");
+
+ JsonLdResource r1 = new JsonLdResource();
+ r1.setSubject("_:bnode1");
+ r1.putProperty("foaf:age", 31.533567);
+ r1.putPropertyType("foaf:age", "http://www.w3.org/2001/XMLSchema#int");
+ jsonLd.put(r1);
+
+ String actual = jsonLd.toString();
+ String expected = "{\"@context\":{\"foaf\":\"http://xmlns.com/foaf/0.1/\",\"xsd\":\"http://www.w3.org/2001/XMLSchema#\"},\"@subject\":\"_:bnode1\",\"foaf:age\":{\"@literal\":\"31.533567\",\"@datatype\":\"xsd:int\"}}";
+ assertEquals(expected, actual);
+ }
+
@SuppressWarnings("unused")
private void toConsole(String actual) {
System.out.println(actual);
Added: incubator/stanbol/trunk/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/format/NamespaceEnum.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/format/NamespaceEnum.java?rev=1177566&view=auto
==============================================================================
--- incubator/stanbol/trunk/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/format/NamespaceEnum.java (added)
+++ incubator/stanbol/trunk/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/format/NamespaceEnum.java Fri Sep 30 09:38:01 2011
@@ -0,0 +1,88 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.stanbol.commons.web.base.format;
+
+public enum NamespaceEnum {
+
+ // TODO: change the namespace as soon as STANBOL-3 defines a namespace to be used for stanbol
+ enhancer("http://fise.iks-project.eu/ontology/"),
+
+ atom("http://www.w3.org/2005/Atom"),
+ bio("dc-bio","http://purl.org/vocab/bio/0.1/"),
+ cc("http://creativecommons.org/ns#"),
+ dcElements("dc-elements","http://purl.org/dc/elements/1.1/"),
+ dcTerms("dc","http://purl.org/dc/terms/"),
+ dbpediaOnt("dbp-ont","http://dbpedia.org/ontology/"),
+ dbpediaProp("dbp-prop","http://dbpedia.org/property/"),
+ cmisRa("cmis-ra","http://docs.oasis-open.org/ns/cmis/restatom/200908/"),
+ cmis("http://docs.oasis-open.org/ns/cmis/core/200908/"),
+ foaf("http://xmlns.com/foaf/0.1/"),
+ goodRelations("gr","http://purl.org/goodrelations/v1#"),
+ geo("http://www.w3.org/2003/01/geo/wgs84_pos#"),
+ geonames("http://www.geonames.org/ontology#"),
+ georss("http://www.georss.org/georss/"),
+ jcr("jcr","http://www.jcp.org/jcr/1.0/"),
+ jcrSv("jcr-sv","http://www.jcp.org/jcr/sv/1.0/"),
+ jcrNt("jcr-nt","http://www.jcp.org/jcr/nt/1.0/"),
+ jcrMix("jcr-mix","http://www.jcp.org/jcr/mix/1.0/"),
+ nie("http://www.semanticdesktop.org/ontologies/2007/01/19/nie#"),
+ nfo("http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#"),
+ rdf("http://www.w3.org/1999/02/22-rdf-syntax-ns#"),
+ rdfs("http://www.w3.org/2000/01/rdf-schema#"),
+ owl("http://www.w3.org/2002/07/owl#"),
+ rss("http://purl.org/rss/1.0/"),
+ schema("http://schema.org/"),
+ sioc("http://rdfs.org/sioc/ns#"),
+ siocTypes("sioc-types","http://rdfs.org/sioc/types#"),
+ skos("http://www.w3.org/2004/02/skos/core#"),
+ swrc("http://swrc.ontoware.org/ontology#"),
+ vCal("http://www.w3.org/2002/12/cal#"),
+ vCard("http://www.w3.org/2001/vcard-rdf/3.0#"),
+ xml("http://www.w3.org/XML/1998/namespace#"),
+ xsi("http://www.w3.org/2001/XMLSchema-instance#"),
+ xsd("http://www.w3.org/2001/XMLSchema#"),
+ ;
+
+ String ns;
+ String prefix;
+
+ NamespaceEnum(String ns) {
+ if (ns == null) {
+ throw new IllegalArgumentException("The namespace MUST NOT be NULL");
+ }
+ this.ns = ns;
+ }
+
+ NamespaceEnum(String prefix, String ns) {
+ this(ns);
+ this.prefix = prefix;
+ }
+
+ public String getNamespace() {
+ return ns;
+ }
+
+ public String getPrefix() {
+ return prefix == null ? name() : prefix;
+ }
+
+ @Override
+ public String toString() {
+ return ns;
+ }
+
+}
Modified: incubator/stanbol/trunk/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/writers/JsonLdSerializerProvider.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/writers/JsonLdSerializerProvider.java?rev=1177566&r1=1177565&r2=1177566&view=diff
==============================================================================
--- incubator/stanbol/trunk/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/writers/JsonLdSerializerProvider.java (original)
+++ incubator/stanbol/trunk/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/writers/JsonLdSerializerProvider.java Fri Sep 30 09:38:01 2011
@@ -36,6 +36,7 @@ import org.apache.clerezza.rdf.core.seri
import org.apache.clerezza.rdf.core.serializedform.SupportedFormat;
import org.apache.stanbol.commons.jsonld.JsonLd;
import org.apache.stanbol.commons.jsonld.JsonLdResource;
+import org.apache.stanbol.commons.web.base.format.NamespaceEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -43,11 +44,6 @@ import org.slf4j.LoggerFactory;
/**
* Implements a <a href="http://json-ld.org/">JSON-LD</a> serialization of a Clerezza
* {@link TripleCollection}.<br>
- * <br>
- * Note: This implementation is based on <a href="http://json-ld.org/spec/">JSON-LD
- * specification</a> draft from 25 October 2010.
- *
- * @author Fabian Christ
*
* @scr.component immediate="true"
* @scr.service
@@ -66,7 +62,7 @@ public class JsonLdSerializerProvider im
private Map<String, String> namespacePrefixMap = new HashMap<String, String>();
private int indentation = 2;
- private boolean useTypeCoercion = false;
+ private boolean useTypeCoercion = true;
@Override
public void serialize(OutputStream serializedGraph, TripleCollection tc, String formatIdentifier) {
@@ -76,7 +72,16 @@ public class JsonLdSerializerProvider im
}
JsonLd jsonLd = new JsonLd();
+ // If there is no namespace prefix map set, we use the namespaces
+ // known from the NamespaceEnum
+ if (this.namespacePrefixMap.isEmpty()) {
+ for (NamespaceEnum ns : NamespaceEnum.values()) {
+ logger.debug("Adding JSON-LD namespace " + ns.getPrefix() + ":" + ns.getNamespace());
+ this.namespacePrefixMap.put(ns.getNamespace(), ns.getPrefix());
+ }
+ }
jsonLd.setNamespacePrefixMap(this.namespacePrefixMap);
+ jsonLd.setUseTypeCoercion(this.useTypeCoercion);
Map<NonLiteral, String> subjects = createSubjectsMap(tc);
for (NonLiteral subject : subjects.keySet()) {
@@ -102,7 +107,7 @@ public class JsonLdSerializerProvider im
TypedLiteral typedObject = (TypedLiteral) currentTriple.getObject();
String type = typedObject.getDataType().getUnicodeString();
strValue = typedObject.getLexicalForm();
- resource.putCoercionType(property, type);
+ resource.putPropertyType(property, type);
}
resource.putProperty(property, convertValueType(strValue));
@@ -114,7 +119,6 @@ public class JsonLdSerializerProvider im
try {
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(serializedGraph,"utf-8"));
- jsonLd.setUseTypeCoercion(this.useTypeCoercion);
writer.write(jsonLd.toString(this.indentation));
writer.flush();
} catch (IOException ioe) {
Modified: incubator/stanbol/trunk/commons/web/base/src/test/java/org/apache/stanbol/commons/web/base/writers/JsonLdSerializerProviderTest.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/web/base/src/test/java/org/apache/stanbol/commons/web/base/writers/JsonLdSerializerProviderTest.java?rev=1177566&r1=1177565&r2=1177566&view=diff
==============================================================================
--- incubator/stanbol/trunk/commons/web/base/src/test/java/org/apache/stanbol/commons/web/base/writers/JsonLdSerializerProviderTest.java (original)
+++ incubator/stanbol/trunk/commons/web/base/src/test/java/org/apache/stanbol/commons/web/base/writers/JsonLdSerializerProviderTest.java Fri Sep 30 09:38:01 2011
@@ -99,9 +99,10 @@ public class JsonLdSerializerProviderTes
OutputStream serializedGraph = new ByteArrayOutputStream();
jsonldProvider.setIndentation(0);
+ jsonldProvider.setUseTypeCoercion(false);
jsonldProvider.serialize(serializedGraph, ci.getMetadata(), formatIdentifier);
- String expected = "{\"@\":\"<urn:iks-project:enhancer:test:text-annotation:Person>\",\"a\":[\"<http:\\/\\/fise.iks-project.eu\\/ontology\\/Enhancement>\",\"<http:\\/\\/fise.iks-project.eu\\/ontology\\/TextAnnotation>\"],\"http:\\/\\/fise.iks-project.eu\\/ontology\\/end\":\"\\\"20\\\"^^<http:\\/\\/www.w3.org\\/2001\\/XMLSchema#int>\",\"http:\\/\\/fise.iks-project.eu\\/ontology\\/selected-text\":\"\\\"Patrick Marshall\\\"^^<http:\\/\\/www.w3.org\\/2001\\/XMLSchema#string>\",\"http:\\/\\/fise.iks-project.eu\\/ontology\\/selection-context\":\"\\\"Dr. Patrick Marshall (1869 - November 1950) was a geologist who lived in New Zealand and worked at the University of Otago.\\\"^^<http:\\/\\/www.w3.org\\/2001\\/XMLSchema#string>\",\"http:\\/\\/fise.iks-project.eu\\/ontology\\/start\":\"\\\"4\\\"^^<http:\\/\\/www.w3.org\\/2001\\/XMLSchema#int>\",\"http:\\/\\/purl.org\\/dc\\/terms\\/created\":\"\\\"" + this.expectedW3CFormattedDate + "\\\"^^<http:\\/\\/www.w3.org\\/2001\\/XMLSche
ma#dateTime>\",\"http:\\/\\/purl.org\\/dc\\/terms\\/creator\":\"<urn:iks-project:enhancer:test:dummyEngine>\",\"http:\\/\\/purl.org\\/dc\\/terms\\/type\":\"<http:\\/\\/dbpedia.org\\/ontology\\/Person>\"}";
+ String expected = "{\"@context\":{\"dbp-ont\":\"http://dbpedia.org/ontology/\",\"dc\":\"http://purl.org/dc/terms/\",\"enhancer\":\"http://fise.iks-project.eu/ontology/\",\"xsd\":\"http://www.w3.org/2001/XMLSchema#\"},\"@subject\":\"<urn:iks-project:enhancer:test:text-annotation:Person>\",\"@type\":[\"<enhancer:Enhancement>\",\"<enhancer:TextAnnotation>\"],\"dc:created\":{\"@literal\":\"" + this.expectedW3CFormattedDate + "\",\"@datatype\":\"xsd:dateTime\"},\"dc:creator\":\"<urn:iks-project:enhancer:test:dummyEngine>\",\"dc:type\":\"<dbp-ont:Person>\",\"enhancer:end\":{\"@literal\":\"20\",\"@datatype\":\"xsd:int\"},\"enhancer:selected-text\":{\"@literal\":\"Patrick Marshall\",\"@datatype\":\"xsd:string\"},\"enhancer:selection-context\":{\"@literal\":\"Dr. Patrick Marshall (1869 - November 1950) was a geologist who lived in New Zealand and worked at the University of Otago.\",\"@datatype\":\"xsd:string\"},\"enhancer:start\":{\"@literal\":\"4\",\"@datatype\":\"xsd:int\"
}}";
String result = serializedGraph.toString();
Assert.assertEquals(expected, result);
}
@@ -116,10 +117,9 @@ public class JsonLdSerializerProviderTes
OutputStream serializedGraph = new ByteArrayOutputStream();
jsonldProvider.setIndentation(0);
- jsonldProvider.setUseTypeCoercion(true);
jsonldProvider.serialize(serializedGraph, ci.getMetadata(), formatIdentifier);
- String expected = "{\"#\":{\"#types\":{\"http:\\/\\/fise.iks-project.eu\\/ontology\\/end\":\"http:\\/\\/www.w3.org\\/2001\\/XMLSchema#int\",\"http:\\/\\/fise.iks-project.eu\\/ontology\\/selected-text\":\"http:\\/\\/www.w3.org\\/2001\\/XMLSchema#string\",\"http:\\/\\/fise.iks-project.eu\\/ontology\\/selection-context\":\"http:\\/\\/www.w3.org\\/2001\\/XMLSchema#string\",\"http:\\/\\/fise.iks-project.eu\\/ontology\\/start\":\"http:\\/\\/www.w3.org\\/2001\\/XMLSchema#int\",\"http:\\/\\/purl.org\\/dc\\/terms\\/created\":\"http:\\/\\/www.w3.org\\/2001\\/XMLSchema#dateTime\"}},\"@\":\"<urn:iks-project:enhancer:test:text-annotation:Person>\",\"a\":[\"<http:\\/\\/fise.iks-project.eu\\/ontology\\/Enhancement>\",\"<http:\\/\\/fise.iks-project.eu\\/ontology\\/TextAnnotation>\"],\"http:\\/\\/fise.iks-project.eu\\/ontology\\/end\":20,\"http:\\/\\/fise.iks-project.eu\\/ontology\\/selected-text\":\"Patrick Marshall\",\"http:\\/\\/fise.iks-project.eu\\/ontology\\/selection-context\"
:\"Dr. Patrick Marshall (1869 - November 1950) was a geologist who lived in New Zealand and worked at the University of Otago.\",\"http:\\/\\/fise.iks-project.eu\\/ontology\\/start\":4,\"http:\\/\\/purl.org\\/dc\\/terms\\/created\":\"" + this.expectedW3CFormattedDate + "\",\"http:\\/\\/purl.org\\/dc\\/terms\\/creator\":\"<urn:iks-project:enhancer:test:dummyEngine>\",\"http:\\/\\/purl.org\\/dc\\/terms\\/type\":\"<http:\\/\\/dbpedia.org\\/ontology\\/Person>\"}";
+ String expected = "{\"@context\":{\"dbp-ont\":\"http://dbpedia.org/ontology/\",\"dc\":\"http://purl.org/dc/terms/\",\"enhancer\":\"http://fise.iks-project.eu/ontology/\",\"xsd\":\"http://www.w3.org/2001/XMLSchema#\",\"@coerce\":{\"xsd:dateTime\":\"dc:created\",\"xsd:int\":[\"enhancer:end\",\"enhancer:start\"],\"xsd:string\":[\"enhancer:selected-text\",\"enhancer:selection-context\"]}},\"@subject\":\"<urn:iks-project:enhancer:test:text-annotation:Person>\",\"@type\":[\"<enhancer:Enhancement>\",\"<enhancer:TextAnnotation>\"],\"dc:created\":\"" + this.expectedW3CFormattedDate + "\",\"dc:creator\":\"<urn:iks-project:enhancer:test:dummyEngine>\",\"dc:type\":\"<dbp-ont:Person>\",\"enhancer:end\":20,\"enhancer:selected-text\":\"Patrick Marshall\",\"enhancer:selection-context\":\"Dr. Patrick Marshall (1869 - November 1950) was a geologist who lived in New Zealand and worked at the University of Otago.\",\"enhancer:start\":4}";
String result = serializedGraph.toString();
Assert.assertEquals(expected, result);
}
@@ -132,9 +132,10 @@ public class JsonLdSerializerProviderTes
getTextAnnotation(ci, "Person", "Patrick Marshall", context, OntologicalClasses.DBPEDIA_PERSON);
OutputStream serializedGraph = new ByteArrayOutputStream();
+ jsonldProvider.setUseTypeCoercion(false);
jsonldProvider.serialize(serializedGraph, ci.getMetadata(), formatIdentifier);
- String expected = "{\n \"@\": \"<urn:iks-project:enhancer:test:text-annotation:Person>\",\n \"a\": [\n \"<http:\\/\\/fise.iks-project.eu\\/ontology\\/Enhancement>\",\n \"<http:\\/\\/fise.iks-project.eu\\/ontology\\/TextAnnotation>\"\n ],\n \"http:\\/\\/fise.iks-project.eu\\/ontology\\/end\": \"\\\"20\\\"^^<http:\\/\\/www.w3.org\\/2001\\/XMLSchema#int>\",\n \"http:\\/\\/fise.iks-project.eu\\/ontology\\/selected-text\": \"\\\"Patrick Marshall\\\"^^<http:\\/\\/www.w3.org\\/2001\\/XMLSchema#string>\",\n \"http:\\/\\/fise.iks-project.eu\\/ontology\\/selection-context\": \"\\\"Dr. Patrick Marshall (1869 - November 1950) was a geologist who lived in New Zealand and worked at the University of Otago.\\\"^^<http:\\/\\/www.w3.org\\/2001\\/XMLSchema#string>\",\n \"http:\\/\\/fise.iks-project.eu\\/ontology\\/start\": \"\\\"4\\\"^^<http:\\/\\/www.w3.org\\/2001\\/XMLSchema#int>\",\n \"http:\\/\\/purl.org\\/dc\\/terms\\/created\": \"\\\"" + this.expectedW3CFormattedDa
te + "\\\"^^<http:\\/\\/www.w3.org\\/2001\\/XMLSchema#dateTime>\",\n \"http:\\/\\/purl.org\\/dc\\/terms\\/creator\": \"<urn:iks-project:enhancer:test:dummyEngine>\",\n \"http:\\/\\/purl.org\\/dc\\/terms\\/type\": \"<http:\\/\\/dbpedia.org\\/ontology\\/Person>\"\n}";
+ String expected = "{\n \"@context\": {\n \"dbp-ont\": \"http://dbpedia.org/ontology/\",\n \"dc\": \"http://purl.org/dc/terms/\",\n \"enhancer\": \"http://fise.iks-project.eu/ontology/\",\n \"xsd\": \"http://www.w3.org/2001/XMLSchema#\"\n },\n \"@subject\": \"<urn:iks-project:enhancer:test:text-annotation:Person>\",\n \"@type\": [\n \"<enhancer:Enhancement>\",\n \"<enhancer:TextAnnotation>\"\n ],\n \"dc:created\": {\n \"@literal\": \"" + this.expectedW3CFormattedDate + "\",\n \"@datatype\": \"xsd:dateTime\"\n },\n \"dc:creator\": \"<urn:iks-project:enhancer:test:dummyEngine>\",\n \"dc:type\": \"<dbp-ont:Person>\",\n \"enhancer:end\": {\n \"@literal\": \"20\",\n \"@datatype\": \"xsd:int\"\n },\n \"enhancer:selected-text\": {\n \"@literal\": \"Patrick Marshall\",\n \"@datatype\": \"xsd:string\"\n },\n \"enhancer:selection-context\": {\n \"@literal\": \"Dr. Patrick Marshall (1869 - November 1950) was a geologist who li
ved in New Zealand and worked at the University of Otago.\",\n \"@datatype\": \"xsd:string\"\n },\n \"enhancer:start\": {\n \"@literal\": \"4\",\n \"@datatype\": \"xsd:int\"\n }\n}";
String result = serializedGraph.toString();
Assert.assertEquals(expected, result);
}
@@ -153,10 +154,11 @@ public class JsonLdSerializerProviderTes
nsMap.put("http://dbpedia.org/ontology/", "dbpedia");
nsMap.put("http://purl.org/dc/terms", "dcterms");
jsonldProvider.setIndentation(0);
+ jsonldProvider.setUseTypeCoercion(false);
jsonldProvider.setNamespacePrefixMap(nsMap);
jsonldProvider.serialize(serializedGraph, ci.getMetadata(), formatIdentifier);
- String expected = "{\"#\":{\"dbpedia\":\"http:\\/\\/dbpedia.org\\/ontology\\/\",\"dcterms\":\"http:\\/\\/purl.org\\/dc\\/terms\",\"enhancer\":\"http:\\/\\/fise.iks-project.eu\\/ontology\\/\",\"xmlns\":\"http:\\/\\/www.w3.org\\/2001\\/XMLSchema#\"},\"@\":\"<urn:iks-project:enhancer:test:text-annotation:Person>\",\"a\":[\"<enhancer:Enhancement>\",\"<enhancer:TextAnnotation>\"],\"dcterms:\\/created\":\"\\\"" + this.expectedW3CFormattedDate + "\\\"^^<xmlns:dateTime>\",\"dcterms:\\/creator\":\"<urn:iks-project:enhancer:test:dummyEngine>\",\"dcterms:\\/type\":\"<dbpedia:Person>\",\"enhancer:end\":\"\\\"20\\\"^^<xmlns:int>\",\"enhancer:selected-text\":\"\\\"Patrick Marshall\\\"^^<xmlns:string>\",\"enhancer:selection-context\":\"\\\"Dr. Patrick Marshall (1869 - November 1950) was a geologist who lived in New Zealand and worked at the University of Otago.\\\"^^<xmlns:string>\",\"enhancer:start\":\"\\\"4\\\"^^<xmlns:int>\"}";
+ String expected = "{\"@context\":{\"dbpedia\":\"http://dbpedia.org/ontology/\",\"dcterms\":\"http://purl.org/dc/terms\",\"enhancer\":\"http://fise.iks-project.eu/ontology/\",\"xmlns\":\"http://www.w3.org/2001/XMLSchema#\"},\"@subject\":\"<urn:iks-project:enhancer:test:text-annotation:Person>\",\"@type\":[\"<enhancer:Enhancement>\",\"<enhancer:TextAnnotation>\"],\"dcterms:/created\":{\"@literal\":\"" + this.expectedW3CFormattedDate + "\",\"@datatype\":\"xmlns:dateTime\"},\"dcterms:/creator\":\"<urn:iks-project:enhancer:test:dummyEngine>\",\"dcterms:/type\":\"<dbpedia:Person>\",\"enhancer:end\":{\"@literal\":\"20\",\"@datatype\":\"xmlns:int\"},\"enhancer:selected-text\":{\"@literal\":\"Patrick Marshall\",\"@datatype\":\"xmlns:string\"},\"enhancer:selection-context\":{\"@literal\":\"Dr. Patrick Marshall (1869 - November 1950) was a geologist who lived in New Zealand and worked at the University of Otago.\",\"@datatype\":\"xmlns:string\"},\"enhancer:start\":{\"@literal\"
:\"4\",\"@datatype\":\"xmlns:int\"}}";
String result = serializedGraph.toString();
Assert.assertEquals(expected, result);
}
@@ -173,13 +175,13 @@ public class JsonLdSerializerProviderTes
nsMap.put("http://fise.iks-project.eu/ontology/", "enhancer");
nsMap.put("http://www.w3.org/2001/XMLSchema#", "xmlns");
nsMap.put("http://dbpedia.org/ontology/", "dbpedia");
- nsMap.put("http://purl.org/dc/terms", "dcterms");
+ nsMap.put("http://purl.org/dc/terms/", "dcterms");
jsonldProvider.setIndentation(0);
- jsonldProvider.setNamespacePrefixMap(nsMap);
jsonldProvider.setUseTypeCoercion(true);
+ jsonldProvider.setNamespacePrefixMap(nsMap);
jsonldProvider.serialize(serializedGraph, ci.getMetadata(), formatIdentifier);
- String expected = "{\"#\":{\"dbpedia\":\"http:\\/\\/dbpedia.org\\/ontology\\/\",\"dcterms\":\"http:\\/\\/purl.org\\/dc\\/terms\",\"enhancer\":\"http:\\/\\/fise.iks-project.eu\\/ontology\\/\",\"xmlns\":\"http:\\/\\/www.w3.org\\/2001\\/XMLSchema#\",\"#types\":{\"dcterms:\\/created\":\"xmlns:dateTime\",\"enhancer:end\":\"xmlns:int\",\"enhancer:selected-text\":\"xmlns:string\",\"enhancer:selection-context\":\"xmlns:string\",\"enhancer:start\":\"xmlns:int\"}},\"@\":\"<urn:iks-project:enhancer:test:text-annotation:Person>\",\"a\":[\"<enhancer:Enhancement>\",\"<enhancer:TextAnnotation>\"],\"dcterms:\\/created\":\"" + this.expectedW3CFormattedDate + "\",\"dcterms:\\/creator\":\"<urn:iks-project:enhancer:test:dummyEngine>\",\"dcterms:\\/type\":\"<dbpedia:Person>\",\"enhancer:end\":20,\"enhancer:selected-text\":\"Patrick Marshall\",\"enhancer:selection-context\":\"Dr. Patrick Marshall (1869 - November 1950) was a geologist who lived in New Zealand and worked at the University
of Otago.\",\"enhancer:start\":4}";
+ String expected = "{\"@context\":{\"dbpedia\":\"http://dbpedia.org/ontology/\",\"dcterms\":\"http://purl.org/dc/terms/\",\"enhancer\":\"http://fise.iks-project.eu/ontology/\",\"xmlns\":\"http://www.w3.org/2001/XMLSchema#\",\"@coerce\":{\"xmlns:dateTime\":\"dcterms:created\",\"xmlns:int\":[\"enhancer:end\",\"enhancer:start\"],\"xmlns:string\":[\"enhancer:selected-text\",\"enhancer:selection-context\"]}},\"@subject\":\"<urn:iks-project:enhancer:test:text-annotation:Person>\",\"@type\":[\"<enhancer:Enhancement>\",\"<enhancer:TextAnnotation>\"],\"dcterms:created\":\"" + this.expectedW3CFormattedDate + "\",\"dcterms:creator\":\"<urn:iks-project:enhancer:test:dummyEngine>\",\"dcterms:type\":\"<dbpedia:Person>\",\"enhancer:end\":20,\"enhancer:selected-text\":\"Patrick Marshall\",\"enhancer:selection-context\":\"Dr. Patrick Marshall (1869 - November 1950) was a geologist who lived in New Zealand and worked at the University of Otago.\",\"enhancer:start\":4}";
String result = serializedGraph.toString();
Assert.assertEquals(expected, result);
}
@@ -198,10 +200,11 @@ public class JsonLdSerializerProviderTes
nsMap.put("http://dbpedia.org/ontology/", "dbpedia");
nsMap.put("http://purl.org/dc/terms", "dcterms");
jsonldProvider.setIndentation(4);
+ jsonldProvider.setUseTypeCoercion(false);
jsonldProvider.setNamespacePrefixMap(nsMap);
jsonldProvider.serialize(serializedGraph, ci.getMetadata(), formatIdentifier);
- String expected = "{\n \"#\": {\n \"dbpedia\": \"http:\\/\\/dbpedia.org\\/ontology\\/\",\n \"dcterms\": \"http:\\/\\/purl.org\\/dc\\/terms\",\n \"enhancer\": \"http:\\/\\/fise.iks-project.eu\\/ontology\\/\",\n \"xmlns\": \"http:\\/\\/www.w3.org\\/2001\\/XMLSchema#\"\n },\n \"@\": \"<urn:iks-project:enhancer:test:text-annotation:Person>\",\n \"a\": [\n \"<enhancer:Enhancement>\",\n \"<enhancer:TextAnnotation>\"\n ],\n \"dcterms:\\/created\": \"\\\"" + this.expectedW3CFormattedDate + "\\\"^^<xmlns:dateTime>\",\n \"dcterms:\\/creator\": \"<urn:iks-project:enhancer:test:dummyEngine>\",\n \"dcterms:\\/type\": \"<dbpedia:Person>\",\n \"enhancer:end\": \"\\\"20\\\"^^<xmlns:int>\",\n \"enhancer:selected-text\": \"\\\"Patrick Marshall\\\"^^<xmlns:string>\",\n \"enhancer:selection-context\": \"\\\"Dr. Patrick Marshall (1869 - November 1950) was a geologist who lived in New Zealand and worked at the Univ
ersity of Otago.\\\"^^<xmlns:string>\",\n \"enhancer:start\": \"\\\"4\\\"^^<xmlns:int>\"\n}";
+ String expected = "{\n \"@context\": {\n \"dbpedia\": \"http://dbpedia.org/ontology/\",\n \"dcterms\": \"http://purl.org/dc/terms\",\n \"enhancer\": \"http://fise.iks-project.eu/ontology/\",\n \"xmlns\": \"http://www.w3.org/2001/XMLSchema#\"\n },\n \"@subject\": \"<urn:iks-project:enhancer:test:text-annotation:Person>\",\n \"@type\": [\n \"<enhancer:Enhancement>\",\n \"<enhancer:TextAnnotation>\"\n ],\n \"dcterms:/created\": {\n \"@literal\": \"" + this.expectedW3CFormattedDate + "\",\n \"@datatype\": \"xmlns:dateTime\"\n },\n \"dcterms:/creator\": \"<urn:iks-project:enhancer:test:dummyEngine>\",\n \"dcterms:/type\": \"<dbpedia:Person>\",\n \"enhancer:end\": {\n \"@literal\": \"20\",\n \"@datatype\": \"xmlns:int\"\n },\n \"enhancer:selected-text\": {\n \"@literal\": \"Patrick Marshall\",\n \"@datatype\": \"xmlns:string\"\n },\n \"enhancer:sele
ction-context\": {\n \"@literal\": \"Dr. Patrick Marshall (1869 - November 1950) was a geologist who lived in New Zealand and worked at the University of Otago.\",\n \"@datatype\": \"xmlns:string\"\n },\n \"enhancer:start\": {\n \"@literal\": \"4\",\n \"@datatype\": \"xmlns:int\"\n }\n}";
String result = serializedGraph.toString();
Assert.assertEquals(expected, result);
}
@@ -224,7 +227,7 @@ public class JsonLdSerializerProviderTes
jsonldProvider.setUseTypeCoercion(true);
jsonldProvider.serialize(serializedGraph, ci.getMetadata(), formatIdentifier);
- String expected = "{\n \"#\": {\n \"dbpedia\": \"http:\\/\\/dbpedia.org\\/ontology\\/\",\n \"dcterms\": \"http:\\/\\/purl.org\\/dc\\/terms\",\n \"enhancer\": \"http:\\/\\/fise.iks-project.eu\\/ontology\\/\",\n \"xmlns\": \"http:\\/\\/www.w3.org\\/2001\\/XMLSchema#\",\n \"#types\": {\n \"dcterms:\\/created\": \"xmlns:dateTime\",\n \"enhancer:end\": \"xmlns:int\",\n \"enhancer:selected-text\": \"xmlns:string\",\n \"enhancer:selection-context\": \"xmlns:string\",\n \"enhancer:start\": \"xmlns:int\"\n }\n },\n \"@\": \"<urn:iks-project:enhancer:test:text-annotation:Person>\",\n \"a\": [\n \"<enhancer:Enhancement>\",\n \"<enhancer:TextAnnotation>\"\n ],\n \"dcterms:\\/created\": \"" + this.expectedW3CFormattedDate + "\",\n \"dcterms:\\/creator\": \"<urn:iks-project:enhancer:test:dummyEngine>\",\n \"dcterms:\\/type\": \"<dbpedia:Person>\",\
n \"enhancer:end\": 20,\n \"enhancer:selected-text\": \"Patrick Marshall\",\n \"enhancer:selection-context\": \"Dr. Patrick Marshall (1869 - November 1950) was a geologist who lived in New Zealand and worked at the University of Otago.\",\n \"enhancer:start\": 4\n}";
+ String expected = "{\n \"@context\": {\n \"dbpedia\": \"http://dbpedia.org/ontology/\",\n \"dcterms\": \"http://purl.org/dc/terms\",\n \"enhancer\": \"http://fise.iks-project.eu/ontology/\",\n \"xmlns\": \"http://www.w3.org/2001/XMLSchema#\",\n \"@coerce\": {\n \"xmlns:dateTime\": \"dcterms:/created\",\n \"xmlns:int\": [\n \"enhancer:end\",\n \"enhancer:start\"\n ],\n \"xmlns:string\": [\n \"enhancer:selected-text\",\n \"enhancer:selection-context\"\n ]\n }\n },\n \"@subject\": \"<urn:iks-project:enhancer:test:text-annotation:Person>\",\n \"@type\": [\n \"<enhancer:Enhancement>\",\n \"<enhancer:TextAnnotation>\"\n ],\n \"dcterms:/created\": \"2010-10-27T12:00:00Z\",\n \"dcterms:/creator\": \"<urn:iks-project:enhancer:test:dummyEngine>\",\n \"dcterms:/type\": \"<dbpedia:Person
>\",\n \"enhancer:end\": 20,\n \"enhancer:selected-text\": \"Patrick Marshall\",\n \"enhancer:selection-context\": \"Dr. Patrick Marshall (1869 - November 1950) was a geologist who lived in New Zealand and worked at the University of Otago.\",\n \"enhancer:start\": 4\n}";
String result = serializedGraph.toString();
Assert.assertEquals(expected, result);
}
Modified: incubator/stanbol/trunk/factstore/src/test/java/org/apache/stanbol/factstore/model/FactSchemaTest.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/factstore/src/test/java/org/apache/stanbol/factstore/model/FactSchemaTest.java?rev=1177566&r1=1177565&r2=1177566&view=diff
==============================================================================
--- incubator/stanbol/trunk/factstore/src/test/java/org/apache/stanbol/factstore/model/FactSchemaTest.java (original)
+++ incubator/stanbol/trunk/factstore/src/test/java/org/apache/stanbol/factstore/model/FactSchemaTest.java Fri Sep 30 09:38:01 2011
@@ -29,8 +29,9 @@ public class FactSchemaTest {
factSchema.addRole("friend", "http://my.ontology.net/person");
factSchema.addRole("person", "http://my.ontology.net/person");
- String expected = "{\n \"@context\": {\n \"#types\": {\n \"friend\": \"http:\\/\\/my.ontology.net\\/person\",\n \"person\": \"http:\\/\\/my.ontology.net\\/person\"\n }\n }\n}";
+ String expected = "{\n \"@context\": {\n \"@types\": {\n \"friend\": \"http://my.ontology.net/person\",\n \"person\": \"http://my.ontology.net/person\"\n }\n }\n}";
String actual = factSchema.toJsonLdProfile().toString(2);
+ toConsole(actual);
Assert.assertEquals(expected, actual);
}
Modified: incubator/stanbol/trunk/factstore/src/test/java/org/apache/stanbol/factstore/web/resource/FactsResourceTest.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/factstore/src/test/java/org/apache/stanbol/factstore/web/resource/FactsResourceTest.java?rev=1177566&r1=1177565&r2=1177566&view=diff
==============================================================================
--- incubator/stanbol/trunk/factstore/src/test/java/org/apache/stanbol/factstore/web/resource/FactsResourceTest.java (original)
+++ incubator/stanbol/trunk/factstore/src/test/java/org/apache/stanbol/factstore/web/resource/FactsResourceTest.java Fri Sep 30 09:38:01 2011
@@ -79,7 +79,7 @@ public class FactsResourceTest {
Response response = fr
.putFactSchema(
- "{\"@context\":{\"iks\":\"http://iks-project.eu/ont/\",\"#types\":{\"person\":\"iks:person\",\"organization\":\"iks:organization\"}}}",
+ "{\"@context\":{\"iks\":\"http://iks-project.eu/ont/\",\"@types\":{\"person\":\"iks:person\",\"organization\":\"iks:organization\"}}}",
"http://www.test.de/this/urn/is/a/bit/too/long/to/be/used/in/this/fact/store/implementation/with/derby");
assertTrue(response.getStatus() == Status.BAD_REQUEST.getStatusCode());
}
@@ -90,7 +90,7 @@ public class FactsResourceTest {
Response response = fr
.putFactSchema(
- "{\"@context\":{\"iks\":\"http://iks-project.eu/ont/\",\"#types\":{\"person\":\"iks:person\",\"organization\":\"iks:organization\"}}}",
+ "{\"@context\":{\"iks\":\"http://iks-project.eu/ont/\",\"@types\":{\"person\":\"iks:person\",\"organization\":\"iks:organization\"}}}",
"test2");
assertTrue(response.getStatus() == Status.CREATED.getStatusCode());
}
@@ -110,7 +110,7 @@ public class FactsResourceTest {
FactsResource fr = new FactsResource(this.servletContext);
Response response = fr
- .postFacts("{\"@context\":{\"iks\":\"http://iks-project.eu/ont/\",\"upb\":\"http://upb.de/persons/\"},\"@profile\":\"iks:employeeOf\",\"@\":[{\"person\":{\"@iri\":\"upb:bnagel\"},\"organization\":{\"@iri\":\"http://uni-paderborn.de\"}},{\"person\":{\"@iri\":\"upb:fchrist\"},\"organization\":{\"@iri\":\"http://uni-paderborn.de\"}}]}");
+ .postFacts("{\"@context\":{\"iks\":\"http://iks-project.eu/ont/\",\"upb\":\"http://upb.de/persons/\"},\"@profile\":\"iks:employeeOf\",\"@subject\":[{\"person\":{\"@iri\":\"upb:bnagel\"},\"organization\":{\"@iri\":\"http://uni-paderborn.de\"}},{\"person\":{\"@iri\":\"upb:fchrist\"},\"organization\":{\"@iri\":\"http://uni-paderborn.de\"}}]}");
assertTrue(response.getStatus() == Status.OK.getStatusCode());
}
@@ -120,7 +120,7 @@ public class FactsResourceTest {
FactsResource fr = new FactsResource(this.servletContext);
Response response = fr
- .postFacts("{\"@context\":{\"iks\":\"http://iks-project.eu/ont/\",\"upb\":\"http://upb.de/persons/\"},\"@\":[{\"@profile\":\"iks:employeeOf\",\"person\":{\"@iri\":\"upb:bnagel\"},\"organization\":{\"@iri\":\"http://uni-paderborn.de\"}},{\"@profile\":\"iks:friendOf\",\"person\":{\"@iri\":\"upb:bnagel\"},\"friend\":{\"@iri\":\"upb:fchrist\"}}]}");
+ .postFacts("{\"@context\":{\"iks\":\"http://iks-project.eu/ont/\",\"upb\":\"http://upb.de/persons/\"},\"@subject\":[{\"@profile\":\"iks:employeeOf\",\"person\":{\"@iri\":\"upb:bnagel\"},\"organization\":{\"@iri\":\"http://uni-paderborn.de\"}},{\"@profile\":\"iks:friendOf\",\"person\":{\"@iri\":\"upb:bnagel\"},\"friend\":{\"@iri\":\"upb:fchrist\"}}]}");
assertTrue(response.getStatus() == Status.OK.getStatusCode());
}