From 8e96e5b74f69468babb87900f60b50727ae11621 Mon Sep 17 00:00:00 2001 From: Giuseppe Loseto Date: Mon, 27 Jun 2016 11:06:14 +0200 Subject: [PATCH] Update to RDF4J --- .../marmotta-util-rdfpatch/pom.xml | 41 +++++++++++-------- .../platform/ldp/patch/RdfPatchIO.java | 10 ++--- .../platform/ldp/patch/RdfPatchUtil.java | 10 ++--- .../platform/ldp/patch/model/PatchLine.java | 4 +- .../ldp/patch/model/WildcardStatement.java | 17 +++++--- .../ldp/patch/parser/RdfPatchParser.java | 2 +- .../src/main/javacc/rdf-patch.jj | 24 +++++------ .../platform/ldp/patch/RdfPatchIOTest.java | 2 +- .../platform/ldp/patch/RdfPatchUtilTest.java | 18 ++++---- .../patch/parser/RdfPatchParserImplTest.java | 23 ++++++----- 10 files changed, 81 insertions(+), 70 deletions(-) diff --git a/commons/marmotta-sesame-tools/marmotta-util-rdfpatch/pom.xml b/commons/marmotta-sesame-tools/marmotta-util-rdfpatch/pom.xml index 4ae2133f2..4c3620fbe 100644 --- a/commons/marmotta-sesame-tools/marmotta-util-rdfpatch/pom.xml +++ b/commons/marmotta-sesame-tools/marmotta-util-rdfpatch/pom.xml @@ -21,7 +21,7 @@ org.apache.marmotta marmotta-parent - 3.4.0-SNAPSHOT + 3.3.0 ../../../parent/ @@ -80,27 +80,30 @@ - + - org.openrdf.sesame - sesame-model - + org.eclipse.rdf4j + rdf4j-model + 2.0M2 + - org.openrdf.sesame - sesame-repository-api - + org.eclipse.rdf4j + rdf4j-repository-api + 2.0M2 + - org.openrdf.sesame - sesame-rio-turtle + org.eclipse.rdf4j + rdf4j-rio-turtle + 2.0M2 - org.openrdf.sesame - sesame-rio-datatypes + org.eclipse.rdf4j + rdf4j-rio-datatypes - org.openrdf.sesame - sesame-rio-languages + org.eclipse.rdf4j + rdf4j-rio-languages @@ -138,13 +141,15 @@ test - org.openrdf.sesame - sesame-sail-memory + org.eclipse.rdf4j + rdf4j-sail-memory + 2.0M2 test - org.openrdf.sesame - sesame-repository-sail + org.eclipse.rdf4j + rdf4j-repository-sail + 2.0M2 test diff --git a/commons/marmotta-sesame-tools/marmotta-util-rdfpatch/src/main/java/org/apache/marmotta/platform/ldp/patch/RdfPatchIO.java b/commons/marmotta-sesame-tools/marmotta-util-rdfpatch/src/main/java/org/apache/marmotta/platform/ldp/patch/RdfPatchIO.java index 30d0ce47a..788e7327b 100644 --- a/commons/marmotta-sesame-tools/marmotta-util-rdfpatch/src/main/java/org/apache/marmotta/platform/ldp/patch/RdfPatchIO.java +++ b/commons/marmotta-sesame-tools/marmotta-util-rdfpatch/src/main/java/org/apache/marmotta/platform/ldp/patch/RdfPatchIO.java @@ -19,8 +19,8 @@ import org.apache.commons.io.output.StringBuilderWriter; import org.apache.marmotta.platform.ldp.patch.model.PatchLine; -import org.openrdf.model.*; -import org.openrdf.rio.turtle.TurtleUtil; +import org.eclipse.rdf4j.model.*; +import org.eclipse.rdf4j.rio.turtle.TurtleUtil; import java.io.*; import java.util.Collections; @@ -122,7 +122,7 @@ public static void writePatch(Writer writer, List patch, Map inverseNamespaceMap) { if (v == null) { return "R"; - } else if (v instanceof URI) { + } else if (v instanceof IRI) { final String uri = v.stringValue(); String prefix = null; @@ -148,8 +148,8 @@ private static String io(Value v, Map inverseNamespaceMap) { } else { sb.append("\"").append(TurtleUtil.encodeString(label)).append("\""); } - if (l.getLanguage() != null) { - sb.append("@").append(l.getLanguage()); + if (l.getLanguage() != null && l.getLanguage().isPresent()) { + sb.append("@").append(l.getLanguage().get()); } else if (l.getDatatype() != null) { sb.append("^^").append(io(l.getDatatype(), inverseNamespaceMap)); } diff --git a/commons/marmotta-sesame-tools/marmotta-util-rdfpatch/src/main/java/org/apache/marmotta/platform/ldp/patch/RdfPatchUtil.java b/commons/marmotta-sesame-tools/marmotta-util-rdfpatch/src/main/java/org/apache/marmotta/platform/ldp/patch/RdfPatchUtil.java index bd86e67b9..e6fa569ac 100644 --- a/commons/marmotta-sesame-tools/marmotta-util-rdfpatch/src/main/java/org/apache/marmotta/platform/ldp/patch/RdfPatchUtil.java +++ b/commons/marmotta-sesame-tools/marmotta-util-rdfpatch/src/main/java/org/apache/marmotta/platform/ldp/patch/RdfPatchUtil.java @@ -23,11 +23,11 @@ import org.apache.marmotta.platform.ldp.patch.parser.ParseException; import org.apache.marmotta.platform.ldp.patch.parser.RdfPatchParser; import org.apache.marmotta.platform.ldp.patch.parser.RdfPatchParserImpl; -import org.openrdf.model.*; -import org.openrdf.repository.Repository; -import org.openrdf.repository.RepositoryConnection; -import org.openrdf.repository.RepositoryException; -import org.openrdf.repository.RepositoryResult; +import org.eclipse.rdf4j.model.*; +import org.eclipse.rdf4j.repository.Repository; +import org.eclipse.rdf4j.repository.RepositoryConnection; +import org.eclipse.rdf4j.repository.RepositoryException; +import org.eclipse.rdf4j.repository.RepositoryResult; import java.io.IOException; import java.io.InputStream; diff --git a/commons/marmotta-sesame-tools/marmotta-util-rdfpatch/src/main/java/org/apache/marmotta/platform/ldp/patch/model/PatchLine.java b/commons/marmotta-sesame-tools/marmotta-util-rdfpatch/src/main/java/org/apache/marmotta/platform/ldp/patch/model/PatchLine.java index 026cbadf4..7dc40126d 100644 --- a/commons/marmotta-sesame-tools/marmotta-util-rdfpatch/src/main/java/org/apache/marmotta/platform/ldp/patch/model/PatchLine.java +++ b/commons/marmotta-sesame-tools/marmotta-util-rdfpatch/src/main/java/org/apache/marmotta/platform/ldp/patch/model/PatchLine.java @@ -17,8 +17,8 @@ */ package org.apache.marmotta.platform.ldp.patch.model; -import org.openrdf.model.Statement; -import org.openrdf.model.vocabulary.RDFS; +import org.eclipse.rdf4j.model.Statement; +import org.eclipse.rdf4j.model.vocabulary.RDFS; /** * A single PatchLine, i.e. a operation of a Patch. diff --git a/commons/marmotta-sesame-tools/marmotta-util-rdfpatch/src/main/java/org/apache/marmotta/platform/ldp/patch/model/WildcardStatement.java b/commons/marmotta-sesame-tools/marmotta-util-rdfpatch/src/main/java/org/apache/marmotta/platform/ldp/patch/model/WildcardStatement.java index 4180a23a2..83d28aeee 100644 --- a/commons/marmotta-sesame-tools/marmotta-util-rdfpatch/src/main/java/org/apache/marmotta/platform/ldp/patch/model/WildcardStatement.java +++ b/commons/marmotta-sesame-tools/marmotta-util-rdfpatch/src/main/java/org/apache/marmotta/platform/ldp/patch/model/WildcardStatement.java @@ -18,10 +18,12 @@ package org.apache.marmotta.platform.ldp.patch.model; import org.apache.commons.lang3.ObjectUtils; -import org.openrdf.model.Resource; -import org.openrdf.model.Statement; -import org.openrdf.model.URI; -import org.openrdf.model.Value; +import org.eclipse.rdf4j.model.IRI; +import org.eclipse.rdf4j.model.Resource; +import org.eclipse.rdf4j.model.Statement; +import org.eclipse.rdf4j.model.URI; +import org.eclipse.rdf4j.model.Value; +import org.eclipse.rdf4j.model.impl.SimpleValueFactory; /** * The Statement in a RdfPatch. @@ -46,8 +48,11 @@ public Resource getSubject() { } @Override - public URI getPredicate() { - return predicate; + public IRI getPredicate() { + if (predicate != null) + return SimpleValueFactory.getInstance().createIRI(predicate.toString()); + else + return null; } @Override diff --git a/commons/marmotta-sesame-tools/marmotta-util-rdfpatch/src/main/java/org/apache/marmotta/platform/ldp/patch/parser/RdfPatchParser.java b/commons/marmotta-sesame-tools/marmotta-util-rdfpatch/src/main/java/org/apache/marmotta/platform/ldp/patch/parser/RdfPatchParser.java index 4963b7be9..17bca7de8 100644 --- a/commons/marmotta-sesame-tools/marmotta-util-rdfpatch/src/main/java/org/apache/marmotta/platform/ldp/patch/parser/RdfPatchParser.java +++ b/commons/marmotta-sesame-tools/marmotta-util-rdfpatch/src/main/java/org/apache/marmotta/platform/ldp/patch/parser/RdfPatchParser.java @@ -18,7 +18,7 @@ package org.apache.marmotta.platform.ldp.patch.parser; import org.apache.marmotta.platform.ldp.patch.model.PatchLine; -import org.openrdf.model.ValueFactory; +import org.eclipse.rdf4j.model.ValueFactory; import java.util.List; diff --git a/commons/marmotta-sesame-tools/marmotta-util-rdfpatch/src/main/javacc/rdf-patch.jj b/commons/marmotta-sesame-tools/marmotta-util-rdfpatch/src/main/javacc/rdf-patch.jj index 4b518a9c8..ec6272c00 100644 --- a/commons/marmotta-sesame-tools/marmotta-util-rdfpatch/src/main/javacc/rdf-patch.jj +++ b/commons/marmotta-sesame-tools/marmotta-util-rdfpatch/src/main/javacc/rdf-patch.jj @@ -31,9 +31,9 @@ package org.apache.marmotta.platform.ldp.patch.parser; import org.apache.marmotta.platform.ldp.patch.model.PatchLine; import org.apache.marmotta.platform.ldp.patch.model.WildcardStatement; -import org.openrdf.model.*; -import org.openrdf.model.impl.ValueFactoryImpl; -import org.openrdf.rio.turtle.TurtleUtil; +import org.eclipse.rdf4j.model.*; +import org.eclipse.rdf4j.model.impl.SimpleValueFactory; +import org.eclipse.rdf4j.rio.turtle.TurtleUtil; import java.io.InputStream; import java.util.HashMap; @@ -43,7 +43,7 @@ import java.util.List; public class RdfPatchParserImpl implements RdfPatchParser { private HashMap namespaces = new HashMap(); - private ValueFactory valueFactory = ValueFactoryImpl.getInstance(); + private ValueFactory valueFactory = SimpleValueFactory.getInstance(); public RdfPatchParserImpl(ValueFactory vf, InputStream is) { this(is); @@ -67,17 +67,17 @@ public class RdfPatchParserImpl implements RdfPatchParser { } - private URI createURI(String uri) { - return this.valueFactory.createURI(unwrapUri(uri)); + private IRI createIRI(String uri) { + return this.valueFactory.createIRI(unwrapUri(uri)); } - private URI createURI(String prefix, String local) { - return this.valueFactory.createURI(namespaces.get(prefix)+local); + private IRI createIRI(String prefix, String local) { + return this.valueFactory.createIRI(namespaces.get(prefix)+local); } - private URI createURIfromQname(String qname) { + private IRI createIRIfromQname(String qname) { final String[] split = qname.split(":", 2); - return createURI(split[0], split[1]); + return createIRI(split[0], split[1]); } private BNode createBNode(String id) { @@ -216,6 +216,6 @@ private URI parseURI() : { Token u; } { - u = { return createURI(u.image); } | - u = { return createURIfromQname(u.image); } + u = { return createIRI(u.image); } | + u = { return createIRIfromQname(u.image); } } diff --git a/commons/marmotta-sesame-tools/marmotta-util-rdfpatch/src/test/java/org/apache/marmotta/platform/ldp/patch/RdfPatchIOTest.java b/commons/marmotta-sesame-tools/marmotta-util-rdfpatch/src/test/java/org/apache/marmotta/platform/ldp/patch/RdfPatchIOTest.java index 9130c819b..0349b65ab 100644 --- a/commons/marmotta-sesame-tools/marmotta-util-rdfpatch/src/test/java/org/apache/marmotta/platform/ldp/patch/RdfPatchIOTest.java +++ b/commons/marmotta-sesame-tools/marmotta-util-rdfpatch/src/test/java/org/apache/marmotta/platform/ldp/patch/RdfPatchIOTest.java @@ -22,7 +22,7 @@ import org.apache.marmotta.platform.ldp.patch.parser.RdfPatchParserImpl; import org.junit.Assert; import org.junit.Test; -import org.openrdf.model.vocabulary.DCTERMS; +import org.eclipse.rdf4j.model.vocabulary.DCTERMS; import java.io.StringReader; import java.util.Collections; diff --git a/commons/marmotta-sesame-tools/marmotta-util-rdfpatch/src/test/java/org/apache/marmotta/platform/ldp/patch/RdfPatchUtilTest.java b/commons/marmotta-sesame-tools/marmotta-util-rdfpatch/src/test/java/org/apache/marmotta/platform/ldp/patch/RdfPatchUtilTest.java index 6d9b32611..eb5775637 100644 --- a/commons/marmotta-sesame-tools/marmotta-util-rdfpatch/src/test/java/org/apache/marmotta/platform/ldp/patch/RdfPatchUtilTest.java +++ b/commons/marmotta-sesame-tools/marmotta-util-rdfpatch/src/test/java/org/apache/marmotta/platform/ldp/patch/RdfPatchUtilTest.java @@ -25,15 +25,15 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import org.openrdf.model.Literal; -import org.openrdf.model.URI; -import org.openrdf.model.vocabulary.FOAF; -import org.openrdf.repository.Repository; -import org.openrdf.repository.RepositoryConnection; -import org.openrdf.repository.RepositoryException; -import org.openrdf.repository.sail.SailRepository; -import org.openrdf.rio.RDFFormat; -import org.openrdf.sail.memory.MemoryStore; +import org.eclipse.rdf4j.model.Literal; +import org.eclipse.rdf4j.model.URI; +import org.eclipse.rdf4j.model.vocabulary.FOAF; +import org.eclipse.rdf4j.repository.Repository; +import org.eclipse.rdf4j.repository.RepositoryConnection; +import org.eclipse.rdf4j.repository.RepositoryException; +import org.eclipse.rdf4j.repository.sail.SailRepository; +import org.eclipse.rdf4j.rio.RDFFormat; +import org.eclipse.rdf4j.sail.memory.MemoryStore; import java.util.List; diff --git a/commons/marmotta-sesame-tools/marmotta-util-rdfpatch/src/test/java/org/apache/marmotta/platform/ldp/patch/parser/RdfPatchParserImplTest.java b/commons/marmotta-sesame-tools/marmotta-util-rdfpatch/src/test/java/org/apache/marmotta/platform/ldp/patch/parser/RdfPatchParserImplTest.java index c03cbf51d..96cf4fc31 100644 --- a/commons/marmotta-sesame-tools/marmotta-util-rdfpatch/src/test/java/org/apache/marmotta/platform/ldp/patch/parser/RdfPatchParserImplTest.java +++ b/commons/marmotta-sesame-tools/marmotta-util-rdfpatch/src/test/java/org/apache/marmotta/platform/ldp/patch/parser/RdfPatchParserImplTest.java @@ -22,10 +22,9 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import org.openrdf.model.*; -import org.openrdf.model.impl.LiteralImpl; -import org.openrdf.model.impl.URIImpl; -import org.openrdf.model.vocabulary.FOAF; +import org.eclipse.rdf4j.model.*; +import org.eclipse.rdf4j.model.impl.SimpleValueFactory; +import org.eclipse.rdf4j.model.vocabulary.FOAF; import java.util.Iterator; import java.util.List; @@ -39,19 +38,21 @@ public class RdfPatchParserImplTest { private RdfPatchParserImpl parser; - private URI alice, bob, charlie; + private IRI alice, bob, charlie; private Literal lcBob, ucBob; @Before public void setUp() { parser = new RdfPatchParserImpl(this.getClass().getResourceAsStream("/illustrative.rdfp")); + + ValueFactory f = SimpleValueFactory.getInstance(); - alice = new URIImpl("http://example/alice"); - bob = new URIImpl("http://example/bob"); - charlie = new URIImpl("http://example/charlie"); + alice = f.createIRI("http://example/alice"); + bob = f.createIRI("http://example/bob"); + charlie = f.createIRI("http://example/charlie"); - lcBob = new LiteralImpl("bob"); - ucBob = new LiteralImpl("Bob"); + lcBob = f.createLiteral("bob"); + ucBob = f.createLiteral("Bob"); } @After @@ -79,7 +80,7 @@ public void testParsing() throws ParseException { checkPatchLine(it.next(), PatchLine.Operator.DELETE, null, null, charlie); } - private void checkPatchLine(PatchLine line, PatchLine.Operator operator, Resource subejct, URI predicate, Value object) { + private void checkPatchLine(PatchLine line, PatchLine.Operator operator, Resource subejct, IRI predicate, Value object) { Assert.assertEquals("Wrong patch operation", operator, line.getOperator()); Statement statement = line.getStatement();