Package org.aksw.commons.index.core
Class StorageNodeDictionary<D1,C1,D2,C2,V,X extends StorageNodeMutable<D2,C2,V>>
- java.lang.Object
-
- org.aksw.commons.index.core.StorageNodeDictionary<D1,C1,D2,C2,V,X>
-
- All Implemented Interfaces:
StorageNode<D1,C1,V>,StorageNodeMutable<D1,C1,V>
public class StorageNodeDictionary<D1,C1,D2,C2,V,X extends StorageNodeMutable<D2,C2,V>> extends Object implements StorageNodeMutable<D1,C1,V>
A wrapper for a storage node that adds a dictionary for the components Can be used to map e.g. Nodes to Integers or canonical instances Maybe this fits better on a TupleAccessor? The issue with storage nodes is that they are stateless. So if we wanted to wrap an exiting structure with a dictionary we would end up with: Dictionary, Map Probably it would not be too bad because we could still easily get the nested map structure out Actually, why shouldn't the storage node have a state? StorageNode intStorage; TupleAccessor intAccessor; TupleAccessor tripleAccessor = TupleAccessorTriple.INSTANCE StorageNodeDictionary tripleStorageWrapper = StorageNodeDictionary.wrap(intStorage, nodeAccessor, (dict, c) -> dict.size(), intAccessor) BiMap tripleStorageWrapper.getDictionary(); - Author:
- raven
-
-
Field Summary
Fields Modifier and Type Field Description protected Xdelegateprotected com.google.common.collect.BiMap<C1,C2>dictionaryprotected org.aksw.commons.tuple.TupleAccessor<D1,C1>sourceTupleAccessorprotected org.aksw.commons.tuple.TupleAccessor<D2,C2>targetTupleAccessor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(V store, D1 sourceTuple)ObjectchooseSubStore(V store, int subStoreIdx)voidclear(V store)Clear a store's content.List<? extends StorageNode<D1,C1,?>>getChildren()Each node in the storage expression may have 0 or more childrenC1getKeyComponentRaw(Object key, int idx)Obtain components from the internal representation of key that was used for indexing w.r.t.int[]getKeyTupleIdxs()The component indexes by which this node indexes May be empty but never nullorg.aksw.commons.tuple.TupleAccessor<D1,C1>getTupleAccessor()Future: Allow the storageNode to answer how efficiently it can answer the constraints in a given constraint list E.g.booleanisEmpty(V store)protected C2makeEntry(C1 c1)D2mapSourceToTarget(D1 sourceTuple)D1mapTargetToSource(D2 targetTuple)VnewStore()booleanremove(V store, D1 sourceTuple)<T> java.util.stream.Stream<?>streamEntries(V store, T tupleLike, org.aksw.commons.tuple.TupleAccessorCore<? super T,? extends C1> tupleAccessor)Stream all entries under equality constraints obtained from a tuple-like pattern<T> Streamer<V,? extends Map.Entry<?,?>>streamerForKeyAndSubStoreAlts(T pattern, org.aksw.commons.tuple.TupleAccessorCore<? super T,? extends C1> accessor)The streamer returns entry that hold a tuple-like key and conceptually alternatives of sub-stores The tuple components of the key can be accessed usingStorageNode.getKeyComponentRaw(Object, int)There are as many components as the length ofStorageNode.getKeyTupleIdxs()If there is 0 components then any invocation ofStorageNode.getKeyComponentRaw(Object, int)will fail with aUnsupportedOperationException.<T> Streamer<V,?>streamerForKeys(T pattern, org.aksw.commons.tuple.TupleAccessorCore<? super T,? extends C1> accessor)<T> Streamer<V,C1>streamerForKeysAsComponent(T pattern, org.aksw.commons.tuple.TupleAccessorCore<? super T,? extends C1> accessor)Compiles from a given pattern a function that can stream the matching keys from the appropriate store.<T> Streamer<V,List<C1>>streamerForKeysAsTuples(T pattern, org.aksw.commons.tuple.TupleAccessorCore<? super T,? extends C1> accessor)Compiles from a given pattern a function that can stream the matching keys from the appropriate store.<T> Streamer<V,?>streamerForValues(T pattern, org.aksw.commons.tuple.TupleAccessorCore<? super T,? extends C1> accessor)Returns an object that can extract the stream of values at an index node under constraints map: { entry.value | entry in map and entry.key matches condition} leafSet: set.entries.stream() A leaf set does not have any keys that could affect the result stream-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.aksw.commons.index.core.StorageNode
chooseSubStoreRaw, getPublicDelegate, getStoreAsList, getStoreAsMap, getStoreAsSet, holdsDomainTuples, isAltNode, isDelegate, isListNode, isMapNode, isSetNode, streamEntries, streamEntriesRaw, streamEntriesRaw
-
Methods inherited from interface org.aksw.commons.index.core.StorageNodeMutable
addRaw, clearRaw, isEmptyRaw, removeRaw
-
-
-
-
Field Detail
-
delegate
protected X extends StorageNodeMutable<D2,C2,V> delegate
-
-
Method Detail
-
add
public boolean add(V store, D1 sourceTuple)
- Specified by:
addin interfaceStorageNodeMutable<D1,C1,D2>
-
remove
public boolean remove(V store, D1 sourceTuple)
- Specified by:
removein interfaceStorageNodeMutable<D1,C1,D2>
-
clear
public void clear(V store)
Description copied from interface:StorageNodeMutableClear a store's content. Cascades to any sub-stores.- Specified by:
clearin interfaceStorageNodeMutable<D1,C1,D2>
-
isEmpty
public boolean isEmpty(V store)
- Specified by:
isEmptyin interfaceStorageNodeMutable<D1,C1,D2>
-
getChildren
public List<? extends StorageNode<D1,C1,?>> getChildren()
Description copied from interface:StorageNodeEach node in the storage expression may have 0 or more children- Specified by:
getChildrenin interfaceStorageNode<D1,C1,D2>- Returns:
-
getKeyTupleIdxs
public int[] getKeyTupleIdxs()
Description copied from interface:StorageNodeThe component indexes by which this node indexes May be empty but never null- Specified by:
getKeyTupleIdxsin interfaceStorageNode<D1,C1,D2>- Returns:
-
getTupleAccessor
public org.aksw.commons.tuple.TupleAccessor<D1,C1> getTupleAccessor()
Description copied from interface:StorageNodeFuture: Allow the storageNode to answer how efficiently it can answer the constraints in a given constraint list E.g. O(1) or O(log(n)) or O(n)- Specified by:
getTupleAccessorin interfaceStorageNode<D1,C1,D2>- Returns:
-
streamerForKeysAsComponent
public <T> Streamer<V,C1> streamerForKeysAsComponent(T pattern, org.aksw.commons.tuple.TupleAccessorCore<? super T,? extends C1> accessor)
Description copied from interface:StorageNodeCompiles from a given pattern a function that can stream the matching keys from the appropriate store. The keys must be instances of the component type otherwise an exception is raised- Specified by:
streamerForKeysAsComponentin interfaceStorageNode<D1,C1,D2>- Returns:
-
streamerForKeysAsTuples
public <T> Streamer<V,List<C1>> streamerForKeysAsTuples(T pattern, org.aksw.commons.tuple.TupleAccessorCore<? super T,? extends C1> accessor)
Description copied from interface:StorageNodeCompiles from a given pattern a function that can stream the matching keys from the appropriate store. The keys must be instances of the component type otherwise an exception is raised if getKeyTupleIdxs().length == 0 then returns a single tuple that projects no components- Specified by:
streamerForKeysAsTuplesin interfaceStorageNode<D1,C1,D2>- Returns:
-
streamerForKeys
public <T> Streamer<V,?> streamerForKeys(T pattern, org.aksw.commons.tuple.TupleAccessorCore<? super T,? extends C1> accessor)
- Specified by:
streamerForKeysin interfaceStorageNode<D1,C1,D2>
-
getKeyComponentRaw
public C1 getKeyComponentRaw(Object key, int idx)
Description copied from interface:StorageNodeObtain components from the internal representation of key that was used for indexing w.r.t.StorageNode.getKeyTupleIdxs().- Specified by:
getKeyComponentRawin interfaceStorageNode<D1,C1,D2>idx- In the range 0 to {@link getKeyTupleIdxs().length} (exclusive) If a key has no components calling this method will always raiseIndexOutOfBoundsException- Returns:
-
chooseSubStore
public Object chooseSubStore(V store, int subStoreIdx)
- Specified by:
chooseSubStorein interfaceStorageNode<D1,C1,D2>
-
streamerForValues
public <T> Streamer<V,?> streamerForValues(T pattern, org.aksw.commons.tuple.TupleAccessorCore<? super T,? extends C1> accessor)
Description copied from interface:StorageNodeReturns an object that can extract the stream of values at an index node under constraints map: { entry.value | entry in map and entry.key matches condition} leafSet: set.entries.stream() A leaf set does not have any keys that could affect the result stream- Specified by:
streamerForValuesin interfaceStorageNode<D1,C1,D2>- Returns:
-
streamerForKeyAndSubStoreAlts
public <T> Streamer<V,? extends Map.Entry<?,?>> streamerForKeyAndSubStoreAlts(T pattern, org.aksw.commons.tuple.TupleAccessorCore<? super T,? extends C1> accessor)
Description copied from interface:StorageNodeThe streamer returns entry that hold a tuple-like key and conceptually alternatives of sub-stores The tuple components of the key can be accessed usingStorageNode.getKeyComponentRaw(Object, int)There are as many components as the length ofStorageNode.getKeyTupleIdxs()If there is 0 components then any invocation ofStorageNode.getKeyComponentRaw(Object, int)will fail with aUnsupportedOperationException. To extract a specific alternative from the substore useStorageNode.chooseSubStore(Object, int). IfStorageNode.getChildren()is not empty then there are as many substore indices as there are children If there are no children then there is an implicit single sub store with index 0- Specified by:
streamerForKeyAndSubStoreAltsin interfaceStorageNode<D1,C1,D2>- Returns:
-
streamEntries
public <T> java.util.stream.Stream<?> streamEntries(V store, T tupleLike, org.aksw.commons.tuple.TupleAccessorCore<? super T,? extends C1> tupleAccessor)
Description copied from interface:StorageNodeStream all entries under equality constraints obtained from a tuple-like pattern- Specified by:
streamEntriesin interfaceStorageNode<D1,C1,D2>- Returns:
-
-