public abstract class StreamingTermStore<T extends ReasonerTerm> extends Object implements VariableTermStore<T,RandomVariableAtom>
Modifier and Type | Field and Description |
---|---|
protected StreamingIterator<T> |
activeIterator |
protected AtomManager |
atomManager |
static int |
INITIAL_PATH_CACHE_SIZE |
protected boolean |
initialRound |
protected int |
numPages |
protected String |
pageDir |
protected int |
pageSize |
protected boolean |
randomizePageAccess |
protected List<WeightedRule> |
rules |
protected int |
seenTermCount |
protected int[] |
shuffleMap
When we shuffle pages, we need to know how they were shuffled so the volatile
cache can be writtten in the same order.
|
protected boolean |
shufflePage |
protected ByteBuffer |
termBuffer
The IO buffer for terms.
|
protected List<T> |
termCache
Terms in the current page.
|
protected HyperplaneTermGenerator<T,RandomVariableAtom> |
termGenerator |
protected List<String> |
termPagePaths |
protected List<T> |
termPool
Terms that we will reuse when we start pulling from the cache.
|
protected Map<RandomVariableAtom,Integer> |
variables |
protected ByteBuffer |
volatileBuffer
The IO buffer for volatile values.
|
protected List<String> |
volatilePagePaths |
protected boolean |
warnRules |
Constructor and Description |
---|
StreamingTermStore(List<Rule> rules,
AtomManager atomManager,
HyperplaneTermGenerator<T,RandomVariableAtom> termGenerator) |
Modifier and Type | Method and Description |
---|---|
void |
add(GroundRule rule,
T term)
Add a term to the store that was generated from the given ground rule.
|
void |
cacheIterationComplete()
A callback for the non-initial round iterator.
|
void |
clear()
Remove any existing terms and prepare for a new set.
|
void |
close()
Close down the term store, it will not be used any more.
|
RandomVariableAtom |
createLocalVariable(RandomVariableAtom atom)
Create a variable local to a specific term.
|
void |
ensureCapacity(int capacity)
Ensure that the underlying stuctures can have the required term capacity.
|
void |
ensureVariableCapacity(int capacity)
Ensure that the underlying stuctures can have the required variable capacity.
|
T |
get(int index) |
protected abstract StreamingIterator<T> |
getCacheIterator()
Get an iterator that will read and write from disk.
|
protected abstract StreamingIterator<T> |
getInitialRoundIterator()
Get an iterator that will perform grounding queries and write the initial pages to disk.
|
protected abstract StreamingIterator<T> |
getNoWriteIterator()
Get an iterator that will not write to disk.
|
int |
getNumVariables() |
String |
getTermPagePath(int index) |
int |
getVariableIndex(RandomVariableAtom variable)
Get the index that matches up to getVariableValues().
|
Iterable<RandomVariableAtom> |
getVariables() |
float |
getVariableValue(int index)
Get the variable for the given index.
|
float[] |
getVariableValues()
Get the truth values for variabe atoms.
|
String |
getVolatilePagePath(int index) |
void |
initForOptimization()
A notification by the Reasoner that optimization is about to begin.
|
void |
initialIterationComplete(int termCount,
int numPages,
ByteBuffer termBuffer,
ByteBuffer volatileBuffer)
A callback for the initial round iterator.
|
boolean |
isLoaded()
Is the term store loaded, and can it give an accurate term and variable count.
|
void |
iterationComplete()
A notification by the Reasoner that a single iteration is complete.
|
Iterator<T> |
iterator() |
Iterator<T> |
noWriteIterator()
Get an iterator that goes over all the terms for only reading.
|
void |
reset()
Reset the existing terms for another round of inference.
|
int |
size() |
protected abstract boolean |
supportsRule(Rule rule)
Check if this term store supports this rule.
|
void |
syncAtoms()
Ensure that all the variable atoms have the same value as the array returned by getVariableValues().
|
void |
updateVariableValue(int index,
float gradient,
float gradientStep)
Update the variable value at the given index.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
forEach, spliterator
public static final int INITIAL_PATH_CACHE_SIZE
protected List<WeightedRule> rules
protected AtomManager atomManager
protected Map<RandomVariableAtom,Integer> variables
protected boolean initialRound
protected StreamingIterator<T extends ReasonerTerm> activeIterator
protected int seenTermCount
protected int numPages
protected HyperplaneTermGenerator<T extends ReasonerTerm,RandomVariableAtom> termGenerator
protected int pageSize
protected String pageDir
protected boolean shufflePage
protected boolean randomizePageAccess
protected boolean warnRules
protected ByteBuffer termBuffer
protected ByteBuffer volatileBuffer
protected List<T extends ReasonerTerm> termCache
protected List<T extends ReasonerTerm> termPool
protected int[] shuffleMap
public StreamingTermStore(List<Rule> rules, AtomManager atomManager, HyperplaneTermGenerator<T,RandomVariableAtom> termGenerator)
public boolean isLoaded()
VariableTermStore
isLoaded
in interface VariableTermStore<T extends ReasonerTerm,RandomVariableAtom>
public int getNumVariables()
getNumVariables
in interface VariableTermStore<T extends ReasonerTerm,RandomVariableAtom>
public Iterable<RandomVariableAtom> getVariables()
getVariables
in interface VariableTermStore<T extends ReasonerTerm,RandomVariableAtom>
public float[] getVariableValues()
VariableTermStore
getVariableValues
in interface VariableTermStore<T extends ReasonerTerm,RandomVariableAtom>
public float getVariableValue(int index)
VariableTermStore
getVariableValue
in interface VariableTermStore<T extends ReasonerTerm,RandomVariableAtom>
public void updateVariableValue(int index, float gradient, float gradientStep)
VariableTermStore
updateVariableValue
in interface VariableTermStore<T extends ReasonerTerm,RandomVariableAtom>
public int getVariableIndex(RandomVariableAtom variable)
VariableTermStore
getVariableIndex
in interface VariableTermStore<T extends ReasonerTerm,RandomVariableAtom>
public void syncAtoms()
VariableTermStore
syncAtoms
in interface VariableTermStore<T extends ReasonerTerm,RandomVariableAtom>
public RandomVariableAtom createLocalVariable(RandomVariableAtom atom)
TermStore
createLocalVariable
in interface TermStore<T extends ReasonerTerm,RandomVariableAtom>
public void ensureVariableCapacity(int capacity)
TermStore
ensureVariableCapacity
in interface TermStore<T extends ReasonerTerm,RandomVariableAtom>
public int size()
size
in interface TermStore<T extends ReasonerTerm,RandomVariableAtom>
public void add(GroundRule rule, T term)
TermStore
add
in interface TermStore<T extends ReasonerTerm,RandomVariableAtom>
public T get(int index)
get
in interface TermStore<T extends ReasonerTerm,RandomVariableAtom>
public void ensureCapacity(int capacity)
TermStore
ensureCapacity
in interface TermStore<T extends ReasonerTerm,RandomVariableAtom>
public String getTermPagePath(int index)
public String getVolatilePagePath(int index)
public void initialIterationComplete(int termCount, int numPages, ByteBuffer termBuffer, ByteBuffer volatileBuffer)
public void cacheIterationComplete()
public Iterator<T> noWriteIterator()
noWriteIterator
in interface TermStore<T extends ReasonerTerm,RandomVariableAtom>
public Iterator<T> iterator()
iterator
in interface Iterable<T extends ReasonerTerm>
public void clear()
TermStore
clear
in interface TermStore<T extends ReasonerTerm,RandomVariableAtom>
public void reset()
TermStore
reset
in interface TermStore<T extends ReasonerTerm,RandomVariableAtom>
public void close()
TermStore
close
in interface TermStore<T extends ReasonerTerm,RandomVariableAtom>
public void initForOptimization()
TermStore
initForOptimization
in interface TermStore<T extends ReasonerTerm,RandomVariableAtom>
public void iterationComplete()
TermStore
iterationComplete
in interface TermStore<T extends ReasonerTerm,RandomVariableAtom>
protected abstract boolean supportsRule(Rule rule)
protected abstract StreamingIterator<T> getInitialRoundIterator()
protected abstract StreamingIterator<T> getCacheIterator()
protected abstract StreamingIterator<T> getNoWriteIterator()
Copyright © 2020 University of California, Santa Cruz. All rights reserved.