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/05 17:00:55 UTC
[1/2] git commit: bug fixes for reasoning,
implemented a map with custom equivalence relation
Updated Branches:
refs/heads/develop 3d94677f6 -> 1c4b4a5c8
bug fixes for reasoning, implemented a map with custom equivalence relation
Project: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/commit/28f0b0c6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/tree/28f0b0c6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/diff/28f0b0c6
Branch: refs/heads/develop
Commit: 28f0b0c6900d5e8302485ed005768715a54eda81
Parents: 9c95634
Author: Sebastian Schaffert <ss...@apache.org>
Authored: Thu Sep 5 17:00:33 2013 +0200
Committer: Sebastian Schaffert <ss...@apache.org>
Committed: Thu Sep 5 17:00:33 2013 +0200
----------------------------------------------------------------------
.../commons/collections/EquivalenceHashMap.java | 563 +++++++++++++++++++
.../commons/collections/EquivalenceHashSet.java | 34 +-
.../commons/sesame/model/StatementCommons.java | 20 +
.../kiwi/reasoner/engine/ReasoningEngine.java | 34 +-
.../reasoner/model/program/Justification.java | 4 +-
.../KiWiRDFSchemaRepositoryConnectionTest.java | 7 +-
.../kiwi/persistence/h2/statements.properties | 4 +-
.../persistence/mysql/statements.properties | 4 +-
.../persistence/pgsql/statements.properties | 4 +-
9 files changed, 647 insertions(+), 27 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/28f0b0c6/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/collections/EquivalenceHashMap.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/collections/EquivalenceHashMap.java b/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/collections/EquivalenceHashMap.java
new file mode 100644
index 0000000..451f2ac
--- /dev/null
+++ b/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/collections/EquivalenceHashMap.java
@@ -0,0 +1,563 @@
+/*
+ * 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.collections;
+
+import com.google.common.base.Equivalence;
+import com.google.common.base.Function;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.Iterators;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
+
+import java.lang.reflect.Array;
+import java.util.*;
+
+/**
+ * A hashmap implementation accepting different notions of equvialence for keys (based on the Guava Equivalence class).
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class EquivalenceHashMap<K,V> implements Map<K,V> {
+
+ private Equivalence equivalence;
+
+ private HashMap<ElementWrapper, V> delegate;
+
+
+ private UnwrapFunction unwrapper = new UnwrapFunction();
+ private WrapFunction wrapper = new WrapFunction();
+
+
+ public EquivalenceHashMap(Equivalence equivalence) {
+ this.equivalence = equivalence;
+ this.delegate = new HashMap<>();
+ }
+
+ /**
+ * Removes all of the mappings from this map (optional operation).
+ * The map will be empty after this call returns.
+ *
+ * @throws UnsupportedOperationException if the <tt>clear</tt> operation
+ * is not supported by this map
+ */
+ @Override
+ public void clear() {
+ delegate.clear();
+ }
+
+ /**
+ * Returns the number of key-value mappings in this map. If the
+ * map contains more than <tt>Integer.MAX_VALUE</tt> elements, returns
+ * <tt>Integer.MAX_VALUE</tt>.
+ *
+ * @return the number of key-value mappings in this map
+ */
+ @Override
+ public int size() {
+ return delegate.size();
+ }
+
+ /**
+ * Returns <tt>true</tt> if this map contains no key-value mappings.
+ *
+ * @return <tt>true</tt> if this map contains no key-value mappings
+ */
+ @Override
+ public boolean isEmpty() {
+ return delegate.isEmpty();
+ }
+
+ /**
+ * Returns <tt>true</tt> if this map contains a mapping for the specified
+ * key. More formally, returns <tt>true</tt> if and only if
+ * this map contains a mapping for a key <tt>k</tt> such that
+ * <tt>(key==null ? k==null : key.equals(k))</tt>. (There can be
+ * at most one such mapping.)
+ *
+ * @param key key whose presence in this map is to be tested
+ * @return <tt>true</tt> if this map contains a mapping for the specified
+ * key
+ * @throws ClassCastException if the key is of an inappropriate type for
+ * this map
+ * (<a href="Collection.html#optional-restrictions">optional</a>)
+ * @throws NullPointerException if the specified key is null and this map
+ * does not permit null keys
+ * (<a href="Collection.html#optional-restrictions">optional</a>)
+ */
+ @Override
+ public boolean containsKey(Object key) {
+ return delegate.containsKey(new ElementWrapper((K)key));
+ }
+
+ /**
+ * Returns <tt>true</tt> if this map maps one or more keys to the
+ * specified value. More formally, returns <tt>true</tt> if and only if
+ * this map contains at least one mapping to a value <tt>v</tt> such that
+ * <tt>(value==null ? v==null : value.equals(v))</tt>. This operation
+ * will probably require time linear in the map size for most
+ * implementations of the <tt>Map</tt> interface.
+ *
+ * @param value value whose presence in this map is to be tested
+ * @return <tt>true</tt> if this map maps one or more keys to the
+ * specified value
+ * @throws ClassCastException if the value is of an inappropriate type for
+ * this map
+ * (<a href="Collection.html#optional-restrictions">optional</a>)
+ * @throws NullPointerException if the specified value is null and this
+ * map does not permit null values
+ * (<a href="Collection.html#optional-restrictions">optional</a>)
+ */
+ @Override
+ public boolean containsValue(Object value) {
+ return delegate.containsValue(value);
+ }
+
+ /**
+ * Returns the value to which the specified key is mapped,
+ * or {@code null} if this map contains no mapping for the key.
+ * <p/>
+ * <p>More formally, if this map contains a mapping from a key
+ * {@code k} to a value {@code v} such that {@code (key==null ? k==null :
+ * key.equals(k))}, then this method returns {@code v}; otherwise
+ * it returns {@code null}. (There can be at most one such mapping.)
+ * <p/>
+ * <p>If this map permits null values, then a return value of
+ * {@code null} does not <i>necessarily</i> indicate that the map
+ * contains no mapping for the key; it's also possible that the map
+ * explicitly maps the key to {@code null}. The {@link #containsKey
+ * containsKey} operation may be used to distinguish these two cases.
+ *
+ * @param key the key whose associated value is to be returned
+ * @return the value to which the specified key is mapped, or
+ * {@code null} if this map contains no mapping for the key
+ * @throws ClassCastException if the key is of an inappropriate type for
+ * this map
+ * (<a href="Collection.html#optional-restrictions">optional</a>)
+ * @throws NullPointerException if the specified key is null and this map
+ * does not permit null keys
+ * (<a href="Collection.html#optional-restrictions">optional</a>)
+ */
+ @Override
+ public V get(Object key) {
+ return delegate.get(new ElementWrapper((K)key));
+ }
+
+ /**
+ * Associates the specified value with the specified key in this map
+ * (optional operation). If the map previously contained a mapping for
+ * the key, the old value is replaced by the specified value. (A map
+ * <tt>m</tt> is said to contain a mapping for a key <tt>k</tt> if and only
+ * if {@link #containsKey(Object) m.containsKey(k)} would return
+ * <tt>true</tt>.)
+ *
+ * @param key key with which the specified value is to be associated
+ * @param value value to be associated with the specified key
+ * @return the previous value associated with <tt>key</tt>, or
+ * <tt>null</tt> if there was no mapping for <tt>key</tt>.
+ * (A <tt>null</tt> return can also indicate that the map
+ * previously associated <tt>null</tt> with <tt>key</tt>,
+ * if the implementation supports <tt>null</tt> values.)
+ * @throws UnsupportedOperationException if the <tt>put</tt> operation
+ * is not supported by this map
+ * @throws ClassCastException if the class of the specified key or value
+ * prevents it from being stored in this map
+ * @throws NullPointerException if the specified key or value is null
+ * and this map does not permit null keys or values
+ * @throws IllegalArgumentException if some property of the specified key
+ * or value prevents it from being stored in this map
+ */
+ @Override
+ public V put(K key, V value) {
+ return delegate.put(new ElementWrapper(key), value);
+ }
+
+ /**
+ * Removes the mapping for a key from this map if it is present
+ * (optional operation). More formally, if this map contains a mapping
+ * from key <tt>k</tt> to value <tt>v</tt> such that
+ * <code>(key==null ? k==null : key.equals(k))</code>, that mapping
+ * is removed. (The map can contain at most one such mapping.)
+ * <p/>
+ * <p>Returns the value to which this map previously associated the key,
+ * or <tt>null</tt> if the map contained no mapping for the key.
+ * <p/>
+ * <p>If this map permits null values, then a return value of
+ * <tt>null</tt> does not <i>necessarily</i> indicate that the map
+ * contained no mapping for the key; it's also possible that the map
+ * explicitly mapped the key to <tt>null</tt>.
+ * <p/>
+ * <p>The map will not contain a mapping for the specified key once the
+ * call returns.
+ *
+ * @param key key whose mapping is to be removed from the map
+ * @return the previous value associated with <tt>key</tt>, or
+ * <tt>null</tt> if there was no mapping for <tt>key</tt>.
+ * @throws UnsupportedOperationException if the <tt>remove</tt> operation
+ * is not supported by this map
+ * @throws ClassCastException if the key is of an inappropriate type for
+ * this map
+ * (<a href="Collection.html#optional-restrictions">optional</a>)
+ * @throws NullPointerException if the specified key is null and this
+ * map does not permit null keys
+ * (<a href="Collection.html#optional-restrictions">optional</a>)
+ */
+ @Override
+ public V remove(Object key) {
+ return delegate.remove(new ElementWrapper((K)key));
+ }
+
+ /**
+ * Copies all of the mappings from the specified map to this map
+ * (optional operation). The effect of this call is equivalent to that
+ * of calling {@link #put(Object, Object) put(k, v)} on this map once
+ * for each mapping from key <tt>k</tt> to value <tt>v</tt> in the
+ * specified map. The behavior of this operation is undefined if the
+ * specified map is modified while the operation is in progress.
+ *
+ * @param m mappings to be stored in this map
+ * @throws UnsupportedOperationException if the <tt>putAll</tt> operation
+ * is not supported by this map
+ * @throws ClassCastException if the class of a key or value in the
+ * specified map prevents it from being stored in this map
+ * @throws NullPointerException if the specified map is null, or if
+ * this map does not permit null keys or values, and the
+ * specified map contains null keys or values
+ * @throws IllegalArgumentException if some property of a key or value in
+ * the specified map prevents it from being stored in this map
+ */
+ @Override
+ public void putAll(Map<? extends K, ? extends V> m) {
+ for(Entry entry : m.entrySet()) {
+ put((K)entry.getKey(),(V)entry.getValue());
+ }
+ }
+
+ /**
+ * Returns a {@link java.util.Set} view of the keys contained in this map.
+ * The set is backed by the map, so changes to the map are
+ * reflected in the set, and vice-versa. If the map is modified
+ * while an iteration over the set is in progress (except through
+ * the iterator's own <tt>remove</tt> operation), the results of
+ * the iteration are undefined. The set supports element removal,
+ * which removes the corresponding mapping from the map, via the
+ * <tt>Iterator.remove</tt>, <tt>Set.remove</tt>,
+ * <tt>removeAll</tt>, <tt>retainAll</tt>, and <tt>clear</tt>
+ * operations. It does not support the <tt>add</tt> or <tt>addAll</tt>
+ * operations.
+ *
+ * @return a set view of the keys contained in this map
+ */
+ @Override
+ public Set<K> keySet() {
+ final Set<ElementWrapper> wrapped = delegate.keySet();
+
+ return new Set<K>() {
+ @Override
+ public int size() {
+ return wrapped.size();
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return wrapped.isEmpty();
+ }
+
+ @Override
+ public boolean contains(Object o) {
+ return wrapped.contains(new ElementWrapper((K)o));
+ }
+
+ @Override
+ public Iterator<K> iterator() {
+ return Iterators.transform(wrapped.iterator(),unwrapper);
+ }
+
+ @Override
+ public Object[] toArray() {
+ return Iterators.toArray(this.iterator(), Object.class);
+ }
+
+ @Override
+ public <T> T[] toArray(T[] a) {
+ T[] result;
+ if(a.length < size()) {
+ result = (T[]) Array.newInstance(a.getClass().getComponentType(), size());
+ } else {
+ result = a;
+ }
+ int pos = 0;
+ for(ElementWrapper w : wrapped) {
+ try {
+ result[pos++] = (T) w.delegate;
+ } catch (ClassCastException ex) {
+ throw new ArrayStoreException("invalid type for array");
+ }
+ }
+ if(pos < result.length) {
+ result[pos] = null;
+ }
+ return result;
+ }
+
+ @Override
+ public boolean add(K k) {
+ return wrapped.add(new ElementWrapper(k));
+ }
+
+ @Override
+ public boolean remove(Object o) {
+ return wrapped.remove(new ElementWrapper((K)o));
+ }
+
+ @Override
+ public boolean containsAll(Collection<?> c) {
+ return wrapped.containsAll(Collections2.transform(c, wrapper));
+ }
+
+ @Override
+ public boolean addAll(Collection<? extends K> c) {
+ return wrapped.addAll(Collections2.transform(c, wrapper));
+ }
+
+ @Override
+ public boolean retainAll(Collection<?> c) {
+ return wrapped.retainAll(Collections2.transform(c, wrapper));
+ }
+
+ @Override
+ public boolean removeAll(Collection<?> c) {
+ return wrapped.removeAll(Collections2.transform(c, wrapper));
+ }
+
+ @Override
+ public void clear() {
+ wrapped.clear();
+ }
+ };
+ }
+
+ /**
+ * Returns a {@link java.util.Collection} view of the values contained in this map.
+ * The collection is backed by the map, so changes to the map are
+ * reflected in the collection, and vice-versa. If the map is
+ * modified while an iteration over the collection is in progress
+ * (except through the iterator's own <tt>remove</tt> operation),
+ * the results of the iteration are undefined. The collection
+ * supports element removal, which removes the corresponding
+ * mapping from the map, via the <tt>Iterator.remove</tt>,
+ * <tt>Collection.remove</tt>, <tt>removeAll</tt>,
+ * <tt>retainAll</tt> and <tt>clear</tt> operations. It does not
+ * support the <tt>add</tt> or <tt>addAll</tt> operations.
+ *
+ * @return a collection view of the values contained in this map
+ */
+ @Override
+ public Collection<V> values() {
+ return delegate.values();
+ }
+
+ /**
+ * Returns a {@link java.util.Set} view of the mappings contained in this map.
+ * The set is backed by the map, so changes to the map are
+ * reflected in the set, and vice-versa. If the map is modified
+ * while an iteration over the set is in progress (except through
+ * the iterator's own <tt>remove</tt> operation, or through the
+ * <tt>setValue</tt> operation on a map entry returned by the
+ * iterator) the results of the iteration are undefined. The set
+ * supports element removal, which removes the corresponding
+ * mapping from the map, via the <tt>Iterator.remove</tt>,
+ * <tt>Set.remove</tt>, <tt>removeAll</tt>, <tt>retainAll</tt> and
+ * <tt>clear</tt> operations. It does not support the
+ * <tt>add</tt> or <tt>addAll</tt> operations.
+ *
+ * @return a set view of the mappings contained in this map
+ */
+ @Override
+ public Set<Entry<K, V>> entrySet() {
+ final Set<Entry<ElementWrapper,V>> wrapped = delegate.entrySet();
+ final EntryUnwrapFunction entryUnwrapFunction = new EntryUnwrapFunction();
+ final EntryWrapFunction entryWrapFunction = new EntryWrapFunction();
+
+ return new Set<Entry<K, V>>() {
+ @Override
+ public int size() {
+ return wrapped.size();
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return wrapped.isEmpty();
+ }
+
+ @Override
+ public boolean contains(Object o) {
+ return wrapped.contains(new ElementWrapper((K)o));
+ }
+
+ @Override
+ public Iterator<Entry<K, V>> iterator() {
+ return Iterators.transform(wrapped.iterator(), entryUnwrapFunction);
+ }
+
+ @Override
+ public Object[] toArray() {
+ return Iterators.toArray(this.iterator(), Object.class);
+ }
+
+ @Override
+ public <T> T[] toArray(T[] a) {
+ T[] result;
+ if(a.length < size()) {
+ result = (T[]) Array.newInstance(a.getClass().getComponentType(), size());
+ } else {
+ result = a;
+ }
+ int pos = 0;
+ for(Entry<ElementWrapper,V> w : wrapped) {
+ try {
+ result[pos++] = (T) entryUnwrapFunction.apply(w);
+ } catch (ClassCastException ex) {
+ throw new ArrayStoreException("invalid type for array");
+ }
+ }
+ if(pos < result.length) {
+ result[pos] = null;
+ }
+ return result;
+ }
+
+ @Override
+ public boolean add(Entry<K, V> k) {
+ return wrapped.add(entryWrapFunction.apply(k));
+ }
+
+ @Override
+ public boolean remove(Object o) {
+ return wrapped.remove(entryWrapFunction.apply((Entry<K, V>)o));
+ }
+
+ @Override
+ public boolean containsAll(Collection<?> c) {
+ return wrapped.containsAll(Collections2.transform(c, entryWrapFunction));
+ }
+
+ @Override
+ public boolean addAll(Collection<? extends Entry<K, V>> c) {
+ return wrapped.addAll(Collections2.transform(c, entryWrapFunction));
+ }
+
+ @Override
+ public boolean retainAll(Collection<?> c) {
+ return wrapped.retainAll(Collections2.transform(c, entryWrapFunction));
+ }
+
+ @Override
+ public boolean removeAll(Collection<?> c) {
+ return wrapped.removeAll(Collections2.transform(c, entryWrapFunction));
+ }
+
+ @Override
+ public void clear() {
+ wrapped.clear();
+ }
+ };
+ }
+
+ private class ElementWrapper {
+
+ private K delegate;
+
+ private ElementWrapper(K delegate) {
+ this.delegate = delegate;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if(o instanceof EquivalenceHashMap<?,?>.ElementWrapper) {
+ return equivalence.equivalent(ElementWrapper.this.delegate, ((ElementWrapper)o).delegate);
+ } else {
+ return false;
+ }
+ }
+
+ @Override
+ public int hashCode() {
+ return equivalence.hash(delegate);
+ }
+ }
+
+ private class UnwrapFunction implements Function<ElementWrapper, K> {
+ @Override
+ public K apply(ElementWrapper input) {
+ return input.delegate;
+ }
+ }
+
+ private class WrapFunction implements Function<Object,ElementWrapper> {
+ @Override
+ public ElementWrapper apply(Object input) {
+ return new ElementWrapper((K)input);
+ }
+ }
+
+ private class EntryUnwrapFunction implements Function<Entry<ElementWrapper,V>, Entry<K, V>> {
+ @Override
+ public Entry<K, V> apply(final Entry<ElementWrapper, V> input) {
+ return new Entry<K, V>() {
+ @Override
+ public K getKey() {
+ return input.getKey().delegate;
+ }
+
+ @Override
+ public V getValue() {
+ return input.getValue();
+ }
+
+ @Override
+ public V setValue(V value) {
+ return input.setValue(value);
+ }
+ };
+ }
+ }
+
+ private class EntryWrapFunction implements Function<Object,Entry<ElementWrapper,V>> {
+ @Override
+ public Entry<ElementWrapper, V> apply(Object o) {
+ final Entry<K, V> input = (Entry<K,V>)o;
+ return new Entry<ElementWrapper, V>() {
+ @Override
+ public ElementWrapper getKey() {
+ return new ElementWrapper(input.getKey());
+ }
+
+ @Override
+ public V getValue() {
+ return input.getValue();
+ }
+
+ @Override
+ public V setValue(V value) {
+ return input.setValue(value);
+ }
+ };
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/28f0b0c6/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/collections/EquivalenceHashSet.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/collections/EquivalenceHashSet.java b/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/collections/EquivalenceHashSet.java
index 09c8a15..9927efb 100644
--- a/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/collections/EquivalenceHashSet.java
+++ b/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/collections/EquivalenceHashSet.java
@@ -36,6 +36,10 @@ public class EquivalenceHashSet<E> implements Set<E> {
private HashSet<ElementWrapper> delegate;
+ private UnwrapFunction unwrapper = new UnwrapFunction();
+ private WrapFunction wrapper = new WrapFunction();
+
+
public EquivalenceHashSet() {
this.equivalence = Equivalence.equals();
this.delegate = new HashSet<>();
@@ -133,7 +137,7 @@ public class EquivalenceHashSet<E> implements Set<E> {
*/
@Override
public Iterator<E> iterator() {
- return Iterators.transform(delegate.iterator(), new UnwrapFunction());
+ return Iterators.transform(delegate.iterator(), unwrapper);
}
/**
@@ -316,7 +320,7 @@ public class EquivalenceHashSet<E> implements Set<E> {
*/
@Override
public boolean containsAll(Collection<?> c) {
- return delegate.containsAll(Collections2.transform(c,new WrapFunction()));
+ return delegate.containsAll(Collections2.transform(c,wrapper));
}
/**
@@ -342,7 +346,7 @@ public class EquivalenceHashSet<E> implements Set<E> {
*/
@Override
public boolean addAll(Collection<? extends E> c) {
- return delegate.addAll(Collections2.transform(c, new WrapFunction()));
+ return delegate.addAll(Collections2.transform(c, wrapper));
}
/**
@@ -368,7 +372,7 @@ public class EquivalenceHashSet<E> implements Set<E> {
*/
@Override
public boolean retainAll(Collection<?> c) {
- return delegate.retainAll(Collections2.transform(c, new WrapFunction()));
+ return delegate.retainAll(Collections2.transform(c, wrapper));
}
/**
@@ -394,7 +398,7 @@ public class EquivalenceHashSet<E> implements Set<E> {
*/
@Override
public boolean removeAll(Collection<?> c) {
- return delegate.removeAll(Collections2.transform(c, new WrapFunction()));
+ return delegate.removeAll(Collections2.transform(c, wrapper));
}
/**
@@ -409,6 +413,26 @@ public class EquivalenceHashSet<E> implements Set<E> {
delegate.clear();
}
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ EquivalenceHashSet that = (EquivalenceHashSet) o;
+
+ if (!delegate.equals(that.delegate)) return false;
+ if (!equivalence.equals(that.equivalence)) return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = equivalence.hashCode();
+ result = 31 * result + delegate.hashCode();
+ return result;
+ }
+
private class ElementWrapper {
private E delegate;
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/28f0b0c6/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
index a8f0d28..41e68e4 100644
--- 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
@@ -49,6 +49,16 @@ public class StatementCommons {
protected int doHash(Statement statement) {
return Objects.hashCode(statement.getSubject(), statement.getPredicate(), statement.getObject());
}
+
+ @Override
+ public boolean equals(Object obj) {
+ return this.getClass().equals(obj.getClass());
+ }
+
+ @Override
+ public int hashCode() {
+ return this.getClass().hashCode();
+ }
};
}
@@ -74,6 +84,16 @@ public class StatementCommons {
protected int doHash(Statement statement) {
return Objects.hashCode(statement.getSubject(), statement.getPredicate(), statement.getObject(), statement.getContext());
}
+
+ @Override
+ public boolean equals(Object obj) {
+ return this.getClass().equals(obj.getClass());
+ }
+
+ @Override
+ public int hashCode() {
+ return this.getClass().hashCode();
+ }
};
}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/28f0b0c6/libraries/kiwi/kiwi-reasoner/src/main/java/org/apache/marmotta/kiwi/reasoner/engine/ReasoningEngine.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-reasoner/src/main/java/org/apache/marmotta/kiwi/reasoner/engine/ReasoningEngine.java b/libraries/kiwi/kiwi-reasoner/src/main/java/org/apache/marmotta/kiwi/reasoner/engine/ReasoningEngine.java
index 9e24148..c7eb138 100644
--- a/libraries/kiwi/kiwi-reasoner/src/main/java/org/apache/marmotta/kiwi/reasoner/engine/ReasoningEngine.java
+++ b/libraries/kiwi/kiwi-reasoner/src/main/java/org/apache/marmotta/kiwi/reasoner/engine/ReasoningEngine.java
@@ -17,10 +17,15 @@
*/
package org.apache.marmotta.kiwi.reasoner.engine;
+import com.google.common.collect.HashMultimap;
+import com.google.common.collect.Multimap;
import info.aduna.iteration.CloseableIteration;
import info.aduna.iteration.EmptyIteration;
import info.aduna.iteration.Iterations;
import info.aduna.iteration.SingletonIteration;
+import org.apache.marmotta.commons.collections.EquivalenceHashMap;
+import org.apache.marmotta.commons.collections.EquivalenceHashSet;
+import org.apache.marmotta.commons.sesame.model.StatementCommons;
import org.apache.marmotta.kiwi.model.caching.TripleTable;
import org.apache.marmotta.kiwi.model.rdf.KiWiNode;
import org.apache.marmotta.kiwi.model.rdf.KiWiResource;
@@ -121,7 +126,7 @@ public class ReasoningEngine implements TransactionListener {
* In-memory cache to store all patterns that are candidates for matching triples and accessing the rules
* they belong to.
*/
- private Map<Pattern,Rule> patternRuleMap;
+ private Multimap<Pattern,Rule> patternRuleMap;
/**
* Internal counter to count executions of the reasoner (informational purposes only)
@@ -153,7 +158,7 @@ public class ReasoningEngine implements TransactionListener {
public void loadPrograms() {
log.info("program configuration changed, reloading ...");
- patternRuleMap = new HashMap<Pattern, Rule>();
+ patternRuleMap = HashMultimap.<Pattern,Rule>create();
try {
KiWiReasoningConnection connection = persistence.getConnection();
@@ -311,7 +316,6 @@ public class ReasoningEngine implements TransactionListener {
/**
* Stop the currently active reasoning task. Informational purposes only.
- * @param name
*/
protected void endTask() {
@@ -345,7 +349,7 @@ public class ReasoningEngine implements TransactionListener {
private void executeReasoner(TransactionData data) {
updateTaskStatus("fetching worklist");
- Set<KiWiTriple> newTriples = new HashSet<KiWiTriple>();
+ Set<KiWiTriple> newTriples = new EquivalenceHashSet<>(StatementCommons.quadrupleEquivalence());
for(Statement stmt : data.getAddedTriples()) {
KiWiTriple t = (KiWiTriple)stmt;
if(t.isMarkedForReasoning()) {
@@ -360,7 +364,7 @@ public class ReasoningEngine implements TransactionListener {
long start2 = System.currentTimeMillis();
updateTaskStatus("reasoning over " + newTriples.size() + " new triples");
processRules(newTriples);
- log.debug("REASONER: reasoning for {} new triples took {} ms overall",newTriples.size(),System.currentTimeMillis()-start2);
+ log.debug("REASONER: reasoning for {} new triples took {} ms overall", newTriples.size(), System.currentTimeMillis() - start2);
}
if(data.getRemovedTriples().size() > 0) {
@@ -488,7 +492,7 @@ public class ReasoningEngine implements TransactionListener {
* This method iterates over all triples that are passed as argument and
* checks whether they are used as supporting triples justifications. All
* such justifications are removed. Triples that are no longer supported
- * will later be cleaned up by {@link #cleanupUnsupported()}
+ * will later be cleaned up by {@link #cleanupUnsupported(org.apache.marmotta.kiwi.reasoner.persistence.KiWiReasoningConnection)}
*
* @param removedTriples
*/
@@ -549,8 +553,10 @@ public class ReasoningEngine implements TransactionListener {
for(KiWiTriple triple : addedTriples) {
QueryResult match = matches(pattern,triple);
if(match != null) {
- log.debug("pattern {} matched with triple {}", pattern.toString(), triple.toString());
- processRule(patternRuleMap.get(pattern), match, pattern);
+ for(Rule rule : patternRuleMap.get(pattern)) {
+ log.debug("REASONER(rule '{}'): pattern {} matched with triple {}", rule.getName(), pattern.toString(), triple.toString());
+ processRule(rule, match, pattern);
+ }
}
}
// TODO: for parallel reasoning, the problem is that we should only create one thread per rule and not
@@ -590,7 +596,7 @@ public class ReasoningEngine implements TransactionListener {
private void processRule(Rule rule, QueryResult match, Pattern p) {
// get the variable bindings for the rule evaluation
- log.debug("REASONER: evaluating rule body for rule {} ...", rule);
+ log.debug("REASONER(rule '{}'): evaluating rule body {} ...", rule.getName() != null ? rule.getName() : rule.getId(), rule);
// create a collection consisting of the body minus the pattern that already matched
Set<Pattern> body = new HashSet<Pattern>(rule.getBody());
@@ -836,7 +842,7 @@ public class ReasoningEngine implements TransactionListener {
*/
private void removeDuplicateJustifications(KiWiReasoningConnection connection, Set<Justification> justifications) throws SQLException {
// remove duplicate justifications
- HashMap<KiWiTriple,Collection<Justification>> justificationCache = new HashMap<KiWiTriple, Collection<Justification>>();
+ Map<KiWiTriple,Collection<Justification>> justificationCache = new EquivalenceHashMap<KiWiTriple, Collection<Justification>>(StatementCommons.quadrupleEquivalence());
for(Iterator<Justification> it = justifications.iterator(); it.hasNext(); ) {
Justification j = it.next();
@@ -922,6 +928,14 @@ public class ReasoningEngine implements TransactionListener {
}
public void shutdown() {
+ for(int i = 0; i<10 && isRunning(); i++) {
+ log.warn("reasoner not yet finished, waiting for 10 seconds (try={})", i+1);
+ try {
+ Thread.sleep(10000);
+ } catch (InterruptedException e) {
+ }
+ }
+
log.info("shutting down reasoning service ...");
reasonerThread.shutdown();
}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/28f0b0c6/libraries/kiwi/kiwi-reasoner/src/main/java/org/apache/marmotta/kiwi/reasoner/model/program/Justification.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-reasoner/src/main/java/org/apache/marmotta/kiwi/reasoner/model/program/Justification.java b/libraries/kiwi/kiwi-reasoner/src/main/java/org/apache/marmotta/kiwi/reasoner/model/program/Justification.java
index c338c86..c6f5a6e 100644
--- a/libraries/kiwi/kiwi-reasoner/src/main/java/org/apache/marmotta/kiwi/reasoner/model/program/Justification.java
+++ b/libraries/kiwi/kiwi-reasoner/src/main/java/org/apache/marmotta/kiwi/reasoner/model/program/Justification.java
@@ -18,6 +18,8 @@
package org.apache.marmotta.kiwi.reasoner.model.program;
+import org.apache.marmotta.commons.collections.EquivalenceHashSet;
+import org.apache.marmotta.commons.sesame.model.StatementCommons;
import org.apache.marmotta.kiwi.model.rdf.KiWiTriple;
import java.util.Date;
@@ -64,7 +66,7 @@ public class Justification {
private Date createdAt;
public Justification() {
- supportingTriples = new HashSet<KiWiTriple>();
+ supportingTriples = new EquivalenceHashSet<>(StatementCommons.quadrupleEquivalence());
supportingRules = new HashSet<Rule>();
}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/28f0b0c6/libraries/kiwi/kiwi-reasoner/src/test/java/org/apache/marmotta/kiwi/reasoner/test/sesame/KiWiRDFSchemaRepositoryConnectionTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-reasoner/src/test/java/org/apache/marmotta/kiwi/reasoner/test/sesame/KiWiRDFSchemaRepositoryConnectionTest.java b/libraries/kiwi/kiwi-reasoner/src/test/java/org/apache/marmotta/kiwi/reasoner/test/sesame/KiWiRDFSchemaRepositoryConnectionTest.java
index fd227ad..b08c0cf 100644
--- a/libraries/kiwi/kiwi-reasoner/src/test/java/org/apache/marmotta/kiwi/reasoner/test/sesame/KiWiRDFSchemaRepositoryConnectionTest.java
+++ b/libraries/kiwi/kiwi-reasoner/src/test/java/org/apache/marmotta/kiwi/reasoner/test/sesame/KiWiRDFSchemaRepositoryConnectionTest.java
@@ -18,6 +18,7 @@
package org.apache.marmotta.kiwi.reasoner.test.sesame;
import org.apache.marmotta.kiwi.config.KiWiConfiguration;
+import org.apache.marmotta.kiwi.persistence.h2.H2Dialect;
import org.apache.marmotta.kiwi.reasoner.engine.ReasoningConfiguration;
import org.apache.marmotta.kiwi.reasoner.sail.KiWiReasoningSail;
import org.apache.marmotta.kiwi.sail.KiWiStore;
@@ -52,6 +53,7 @@ import static org.junit.Assert.fail;
*
*/
@RunWith(KiWiDatabaseRunner.class)
+@KiWiDatabaseRunner.ForDialects(dialect = H2Dialect.class)
public class KiWiRDFSchemaRepositoryConnectionTest extends RDFSchemaRepositoryConnectionTest {
public Logger log = LoggerFactory.getLogger(this.getClass());
@@ -147,9 +149,4 @@ public class KiWiRDFSchemaRepositoryConnectionTest extends RDFSchemaRepositoryCo
public void testInferencerTransactionIsolation() throws Exception {
}
- @Override
- @Test
- @Ignore("in KiWi, inferencing is persisted and not just a view")
- public void testSizeCommit() throws Exception {
- }
}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/28f0b0c6/libraries/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/h2/statements.properties
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/h2/statements.properties b/libraries/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/h2/statements.properties
index f064342..3bb64a9 100644
--- a/libraries/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/h2/statements.properties
+++ b/libraries/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/h2/statements.properties
@@ -64,8 +64,8 @@ store.triple = INSERT INTO triples (id,subject,predicate,object,context,
load.triple = SELECT id FROM triples WHERE subject = ? AND predicate = ? AND object = ? AND context = ? AND deleted = false AND inferred = true
-query.size = SELECT count(*) FROM triples WHERE deleted = false
-query.size_ctx = SELECT count(*) FROM triples WHERE context = ? AND deleted = false
+query.size = SELECT count(*) FROM triples WHERE deleted = false AND inferred = false
+query.size_ctx = SELECT count(*) FROM triples WHERE context = ? AND deleted = false AND inferred = false
query.contexts = SELECT DISTINCT context FROM triples WHERE deleted = false
query.namespaces = SELECT id,prefix,uri,createdAt FROM namespaces
query.resources = SELECT id,ntype,svalue,createdAt FROM nodes WHERE ntype = 'uri' OR ntype = 'bnode'
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/28f0b0c6/libraries/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/mysql/statements.properties
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/mysql/statements.properties b/libraries/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/mysql/statements.properties
index af561df..a94272a 100644
--- a/libraries/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/mysql/statements.properties
+++ b/libraries/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/mysql/statements.properties
@@ -72,8 +72,8 @@ store.triple = INSERT IGNORE INTO triples (id,subject,predicate,object,c
load.triple = SELECT id FROM triples WHERE subject = ? AND predicate = ? AND object = ? AND context = ? AND deleted = false AND inferred = true
-query.size = SELECT count(*) FROM triples WHERE deleted = false
-query.size_ctx = SELECT count(*) FROM triples WHERE context = ? AND deleted = false
+query.size = SELECT count(*) FROM triples WHERE deleted = false AND inferred = false
+query.size_ctx = SELECT count(*) FROM triples WHERE context = ? AND deleted = false AND inferred = false
query.contexts = SELECT DISTINCT context FROM triples WHERE deleted = false
query.namespaces = SELECT id,prefix,uri,createdAt FROM namespaces
query.resources = SELECT id,ntype,svalue,createdAt FROM nodes WHERE ntype = 'uri' OR ntype = 'bnode'
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/28f0b0c6/libraries/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/pgsql/statements.properties
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/pgsql/statements.properties b/libraries/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/pgsql/statements.properties
index 9870b71..2ae6fa6 100644
--- a/libraries/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/pgsql/statements.properties
+++ b/libraries/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/pgsql/statements.properties
@@ -64,8 +64,8 @@ store.namespace = INSERT INTO namespaces (id,prefix,uri,createdAt) VALUES (
store.triple = INSERT INTO triples (id,subject,predicate,object,context,inferred,createdAt) VALUES (?,?,?,?,?,?,?)
load.triple = SELECT id FROM triples WHERE subject = ? AND predicate = ? AND object = ? AND context = ? AND deleted = false
-query.size = SELECT count(*) FROM triples WHERE deleted = false
-query.size_ctx = SELECT count(*) FROM triples WHERE context = ? AND deleted = false
+query.size = SELECT count(*) FROM triples WHERE deleted = false AND inferred = false
+query.size_ctx = SELECT count(*) FROM triples WHERE context = ? AND deleted = false AND inferred = false
query.contexts = SELECT DISTINCT context FROM triples WHERE deleted = false
query.namespaces = SELECT id,prefix,uri,createdAt FROM namespaces
query.resources = SELECT id,ntype,svalue,createdAt FROM nodes WHERE ntype = 'uri' OR ntype = 'bnode'
[2/2] git commit: Merge branch 'develop' of
https://git-wip-us.apache.org/repos/asf/incubator-marmotta into develop
Posted by ss...@apache.org.
Merge branch 'develop' of https://git-wip-us.apache.org/repos/asf/incubator-marmotta into develop
Project: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/commit/1c4b4a5c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/tree/1c4b4a5c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/diff/1c4b4a5c
Branch: refs/heads/develop
Commit: 1c4b4a5c8ca4de0566272a7fa6291580c8eb4e65
Parents: 28f0b0c 3d94677
Author: Sebastian Schaffert <ss...@apache.org>
Authored: Thu Sep 5 17:00:49 2013 +0200
Committer: Sebastian Schaffert <ss...@apache.org>
Committed: Thu Sep 5 17:00:49 2013 +0200
----------------------------------------------------------------------
.../ldclient/provider/html/mapping/CssDateLiteralMapper.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------