You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@marmotta.apache.org by ss...@apache.org on 2013/09/03 15:41:27 UTC
git commit: started with a marmotta-commons class for statement
utility methods,
for the moment different implementations of Guava Equivalence to more properly
solve the different semantics of triple equivalence in Sesame (see
https://openrdf.atlassian.n
Updated Branches:
refs/heads/develop c48c85995 -> dc2f18a1e
started with a marmotta-commons class for statement utility methods, for the moment different implementations of Guava Equivalence to more properly solve the different semantics of triple equivalence in Sesame (see https://openrdf.atlassian.net/browse/SES-1924)
Project: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/commit/dc2f18a1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/tree/dc2f18a1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/diff/dc2f18a1
Branch: refs/heads/develop
Commit: dc2f18a1ebb37a432c6cb143a361191638dcdfd6
Parents: c48c859
Author: Sebastian Schaffert <ss...@apache.org>
Authored: Tue Sep 3 15:41:29 2013 +0200
Committer: Sebastian Schaffert <ss...@apache.org>
Committed: Tue Sep 3 15:41:29 2013 +0200
----------------------------------------------------------------------
.../commons/sesame/model/StatementCommons.java | 81 ++++++++++++++++++++
1 file changed, 81 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/dc2f18a1/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/sesame/model/StatementCommons.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/sesame/model/StatementCommons.java b/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/sesame/model/StatementCommons.java
new file mode 100644
index 0000000..a8f0d28
--- /dev/null
+++ b/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/sesame/model/StatementCommons.java
@@ -0,0 +1,81 @@
+/*
+ * 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.marmotta.commons.sesame.model;
+
+import com.google.common.base.Equivalence;
+import com.google.common.base.Objects;
+import org.openrdf.model.Statement;
+
+/**
+ * Provide some utility functions for managing statements (e.g. different forms of equivalence)
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class StatementCommons {
+
+ /**
+ * Return triple equivalence, taking only into account subject, predicate and object
+ *
+ * @return
+ */
+ public static Equivalence<Statement> tripleEquivalence() {
+ return new Equivalence<Statement>() {
+ @Override
+ protected boolean doEquivalent(Statement a, Statement b) {
+ if(a == b) return true;
+
+ if(!Objects.equal(a.getSubject(), b.getSubject())) return false;
+ if(!Objects.equal(a.getPredicate(), b.getPredicate())) return false;
+ if(!Objects.equal(a.getObject(), b.getObject())) return false;
+ return true;
+ }
+
+ @Override
+ protected int doHash(Statement statement) {
+ return Objects.hashCode(statement.getSubject(), statement.getPredicate(), statement.getObject());
+ }
+ };
+ }
+
+ /**
+ * Return quadruple equivalence, taking into account subject, predicate, object, and context.
+ *
+ * @return
+ */
+ public static Equivalence<Statement> quadrupleEquivalence() {
+ return new Equivalence<Statement>() {
+ @Override
+ protected boolean doEquivalent(Statement a, Statement b) {
+ if(a == b) return true;
+
+ if(!Objects.equal(a.getSubject(), b.getSubject())) return false;
+ if(!Objects.equal(a.getPredicate(), b.getPredicate())) return false;
+ if(!Objects.equal(a.getObject(), b.getObject())) return false;
+ if(!Objects.equal(a.getContext(), b.getContext())) return false;
+ return true;
+ }
+
+ @Override
+ protected int doHash(Statement statement) {
+ return Objects.hashCode(statement.getSubject(), statement.getPredicate(), statement.getObject(), statement.getContext());
+ }
+ };
+
+ }
+
+}