Test jsonld parser
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/0d6a0f82 Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/0d6a0f82 Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/0d6a0f82 Branch: refs/heads/jena Commit: 0d6a0f8285d1cb8c4aafdcfb7519bcad246685b8 Parents: 7cb7ecb Author: Stian Soiland-Reyes <[email protected]> Authored: Tue Apr 12 17:17:18 2016 +0100 Committer: Stian Soiland-Reyes <[email protected]> Committed: Tue Apr 12 17:20:23 2016 +0100 ---------------------------------------------------------------------- .../rdf/jsonldjava/JsonLdParserBuilder.java | 9 +---- jsonld-java/src/main/resources/test.jsonld | 26 ++++++++++++++ .../rdf/jsonldjava/JsonLdParserBuilderTest.java | 36 ++++++++++++++++++++ 3 files changed, 63 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/0d6a0f82/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdParserBuilder.java ---------------------------------------------------------------------- diff --git a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdParserBuilder.java b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdParserBuilder.java index ff9131e..0eeeeba 100644 --- a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdParserBuilder.java +++ b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdParserBuilder.java @@ -43,14 +43,7 @@ public class JsonLdParserBuilder extends AbstractRDFParserBuilder { @Override protected RDFTermFactory createRDFTermFactory() { - if (getIntoGraph().map(x -> x instanceof JsonLdGraph).orElse(true)) { - JsonLdGraph graph = (JsonLdGraph) getIntoGraph().get(); - return new JsonLdRDFTermFactory(graph.bnodePrefix()); - } else { - // other kind of intoGraph - we'll let SimpleRDFTermFactory - // do the job slightly more efficiently instead - return super.createRDFTermFactory(); - } + return new JsonLdRDFTermFactory(); } @Override http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/0d6a0f82/jsonld-java/src/main/resources/test.jsonld ---------------------------------------------------------------------- diff --git a/jsonld-java/src/main/resources/test.jsonld b/jsonld-java/src/main/resources/test.jsonld new file mode 100644 index 0000000..cc10bdb --- /dev/null +++ b/jsonld-java/src/main/resources/test.jsonld @@ -0,0 +1,26 @@ +{ "http://purl.org/dc/elements/1.1/rights": "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. ", + "@context": { + "xsd": "http://www.w3.org/2001/XMLSchema#", + "pred1": "http://example.com/pred1", + "pred2": { "@id": "http://example.com/pred2", + "@type": "@id" }, + "pred3": { "@id": "http://example.com/pred3", + "@type": "xsd:integer" }, + "pred4": { "@id": "http://example.com/pred4", + "@type": "@id" }, + "Type": "http://example.com/Type" + } , + "@id": "http://example.com/test", + "@type": "Type", + "pred1": "Hello", + "pred2": "http://example.com/other", + "pred3": 1337, + "pred4": { "@id": "http://example.com/graph", + "@graph": [ + { "@id": "http://example.com/test", + "pred1": "Other value", + "pred2": "http://example.com/graph" + } + ] + } +} http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/0d6a0f82/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdParserBuilderTest.java ---------------------------------------------------------------------- diff --git a/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdParserBuilderTest.java b/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdParserBuilderTest.java new file mode 100644 index 0000000..df8511c --- /dev/null +++ b/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdParserBuilderTest.java @@ -0,0 +1,36 @@ +/** + * 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.commons.rdf.jsonldjava; + +import java.net.URL; +import java.util.concurrent.TimeUnit; + +import org.apache.commons.rdf.api.Graph; +import org.apache.commons.rdf.api.IRI; +import org.apache.commons.rdf.api.RDFSyntax; +import org.junit.Test; + +public class JsonLdParserBuilderTest { + @Test + public void parseByUrl() throws Exception { + URL url = getClass().getResource("/test.jsonld"); + IRI iri = new JsonLdRDFTermFactory().createIRI(url.toString()); + Graph g = new JsonLdParserBuilder().contentType(RDFSyntax.JSONLD).source(iri).parse().get(10, TimeUnit.SECONDS); + System.out.println(g); + } +}
