Package com.semedy.reasoner.symboltable
Class AbstractSymbolTable
java.lang.Object
com.semedy.reasoner.symboltable.AbstractSymbolTable
- All Implemented Interfaces:
SymbolTable,ReasoningSymbolTable,Closeable,AutoCloseable,Iterable<Object>
- Direct Known Subclasses:
MultiSymbolTable,ReasoningSymbolTableRAM,SymbolTableBplus,SymbolTableRAM
provides all functionality for handling a symbol table in main memory
-
Constructor Summary
ConstructorsConstructorDescriptionAbstractSymbolTable(ExternalDataTypeProvider dataTypes, boolean directencoding, int maxTermLength) is it the reasoning symbol table -
Method Summary
Modifier and TypeMethodDescriptionabstract voidAdds an index to the symbol table.abstract longcreateFunctionCode(long[] t, Function f) create function codeCompile a non-ground user term into a non-ground internal term.decompiles a ground internal function into an external functionlongInternalize a ground term.abstract longReturns a code for an object but does not internalize the object.longsearch for code of a termabstract longgetFunctionCode(long[] t) get function codeabstract long[]getFunctionEncoding(long code) get the encoding of a function code, if it is thereget geo indexget text indexgetValue(long code) Produces a value from the code of an internal term.abstract FunctiongetValueFunction(long code) get function for symbol codeabstract ObjectgetValueSymbol(long code) get object for symbol codebooleanMatch returns for each variable v in t the symbol s v has to be substituted by.booleanmatchArguments(Object t, long[] groundtermarguments, long[] substitutions) Match returns for each variable v in t the symbol s v has to be substituted by to match the arguments of t with groundtermarguments The result provides for variable position p the code of sbooleanmatchArguments(Object t, TupleBuffer groundtermarguments, long[] substitutions) voidnotifySymbolAdded(Object symbol, long code) add symbol to text indicesvoidrecreates all symbol table indexes from scratch.voidrefreshSearchIndexes(boolean waitForPendingTasks) refreshes the search indices, i.e. waits until they are up-to-date.voidremoves all symbol table indexes.abstract voidremoves the given symbol table index.semiSubstitute(Object t, long[] substitutions) substitutes the variables in a term by the codes found in substitutions.longsubstitute(Object t, long[] substitutions) substitutes the variables in an internal term by the codes found in substitutions, internalizes the resulting term and returns the code of the term Attention: do not use this method in several threads in parallel, it is NOT threadsafe!substitute(Object t, Object[] substitutions) substitutes the variables in a compound by the terms (non-ground) found in substitutions, internalizes the resulting term and returns the code of the term Attention: do not use this method in several threads in parallel, it is NOT threadsafe!substitute(Object t, Map<Variable, Object> subs) long[]substituteArguments(Object t, long[] substitutions) Substitutes the variables in an internal term by the codes found in substitutions,
internalizes the resulting term and returns the code of the term.Object[]substituteArguments(Object t, Object[] substitutions) substitutes the variables in an internal term by the terms (non-ground) found in substitutions, internalizes the resulting term and returns the code of the term Attention: do not use this method in several threads in parallel, it is NOT threadsafe!substituteFunction(Function f, Map<Variable, Object> subs) booleanUnifiable returns whether two structures are unifiable This method is cheaper than unify as it delivers no result substitutionsbooleanUnifies two structures (variables, terms, functions or literals).booleanunify(Object t, Object f, Map<Variable, Object> substitutions, Map<Variable, Set<Variable>> equivalences) Unifies two structures (variables, terms, functions or literals).Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliteratorMethods inherited from interface com.semedy.reasoner.symboltable.ReasoningSymbolTable
isCreatedDuringReasoningMethods inherited from interface com.semedy.reasoner.api.symboltable.SymbolTable
checkSanity, clear, close, commit, delete, encodeWOEncoding, flush, getExternalDataTypes, hasIndices, inTransaction, isBulkMode, isEmpty, iterator, lastModificationTime, removeNotInternalized, resetTransaction, rollback, setBulkMode, size, transactionBegin, transactionCommit, transactionRollback
-
Constructor Details
-
AbstractSymbolTable
public AbstractSymbolTable(ExternalDataTypeProvider dataTypes, boolean directencoding, int maxTermLength) is it the reasoning symbol table
-
-
Method Details
-
getCode
search for code of a term- Specified by:
getCodein interfaceSymbolTable- Parameters:
t- , the user term to be internalized- Returns:
- code, the code of the term
- Throws:
SemReasonerExceptionEDBExceptionIOException
-
encode
Internalize a ground term. All constants, function symbols are internalized.- Specified by:
encodein interfaceSymbolTable- Parameters:
t- , the user term to be internalized- Returns:
- code, the code of the term
- Throws:
SemReasonerExceptionIOExceptionEDBException
-
getValue
Description copied from interface:SymbolTableProduces a value from the code of an internal term.
Should be used only inside of built-ins and for generating the final answer.- Specified by:
getValuein interfaceSymbolTable- Parameters:
code- , the code of the internal term- Returns:
- Throws:
IOExceptionSemReasonerException
-
getValueSymbol
get object for symbol code- Specified by:
getValueSymbolin interfaceSymbolTable- Parameters:
code- , symbol code- Returns:
- code for whole function
- Throws:
SemReasonerExceptionIOException
-
getValueFunction
get function for symbol code- Specified by:
getValueFunctionin interfaceSymbolTable- Parameters:
code- , symbol code- Returns:
- code for whole function
- Throws:
SemReasonerExceptionIOException
-
getFunctionCode
get function code- Specified by:
getFunctionCodein interfaceSymbolTable- Parameters:
t- , t[0] code of function symbol, t[1]..t[n] codes for n arguments- Returns:
- code for whole function
- Throws:
SemReasonerExceptionIOException
-
createFunctionCode
public abstract long createFunctionCode(long[] t, Function f) throws SemReasonerException, IOException, EDBException create function code- Specified by:
createFunctionCodein interfaceSymbolTable- Parameters:
t- , t[0] code of function symbol, t[1]..t[n] codes for n arguments- Returns:
- code for whole function
- Throws:
SemReasonerExceptionIOExceptionEDBException
-
getFunctionEncoding
get the encoding of a function code, if it is there- Specified by:
getFunctionEncodingin interfaceSymbolTable- Parameters:
code-- Returns:
- t[0] code of function symbol, t[1]..t[n] codes for n arguments
- Throws:
SemReasonerExceptionIOException
-
match
public boolean match(Object t, long code, long[] substitutions) throws SemReasonerException, IOException Match returns for each variable v in t the symbol s v has to be substituted by. The result provides for variable position p the code of s- Specified by:
matchin interfaceReasoningSymbolTable- Specified by:
matchin interfaceSymbolTable- Parameters:
t- , the internaltermcode- , the code of the ground termsubstitutions- , the substitutions substitutions[variableposition] is substituted term for variable- Returns:
- true, if match operation was successful
- Throws:
SemReasonerExceptionIOException
-
matchArguments
public boolean matchArguments(Object t, long[] groundtermarguments, long[] substitutions) throws SemReasonerException, IOException Match returns for each variable v in t the symbol s v has to be substituted by to match the arguments of t with groundtermarguments The result provides for variable position p the code of s- Specified by:
matchArgumentsin interfaceReasoningSymbolTable- Specified by:
matchArgumentsin interfaceSymbolTable- Parameters:
t- , the entity (Variable, Function, Long, Literal)groundtermarguments- , the codes of the arguments of the ground termsubstitutions- , the substitutions substitutions[variable position] is substituted term for variable- Returns:
- true, if match operation was successful
- Throws:
IOExceptionSemReasonerException
-
matchArguments
public boolean matchArguments(Object t, TupleBuffer groundtermarguments, long[] substitutions) throws SemReasonerException, IOException - Specified by:
matchArgumentsin interfaceSymbolTable- Throws:
SemReasonerExceptionIOException
-
substitute
public Object substitute(Object t, Map<Variable, Object> subs) throws IOException, SemReasonerException- Specified by:
substitutein interfaceSymbolTable- Throws:
IOExceptionSemReasonerException
-
unify
public boolean unify(Object t, Object f, Map<Variable, Object> substitutions, Map<Variable, throws SemReasonerException, IOExceptionSet<Variable>> equivalences) Description copied from interface:SymbolTableUnifies two structures (variables, terms, functions or literals). The structures have to be internalized (encoded).
Unify returns for each variable v in t the symbol s v has to be substituted by.
The result (substitutions) provides for each variable the substituted term.
In equivalentVariables the equivalence classes for variables are created
Attention: do not use this method with same objects t,f in several threads in parallel, it is NOT threadsafe!- Specified by:
unifyin interfaceSymbolTable- Parameters:
t- , the first entity (Variable, Function, Long, Literal)f- , the second entity (Variable, Function, Long, Literal)substitutions- , substitutions of variables with functions or ground termsequivalences- , equivalence classes for variables- Returns:
- true, if unify operation was successful
- Throws:
IOExceptionSemReasonerException
-
unify
public boolean unify(Object t, Object f, Map<Variable, Object> substitutions) throws SemReasonerException, IOExceptionDescription copied from interface:SymbolTableUnifies two structures (variables, terms, functions or literals). The structures have to be internalized (encoded).
Unify returns for each variable v in t the symbol s v has to be substituted by.
The result (substitutions) provides for each variable the substituted term.
In equivalentVariables the equivalence classes for variables are created
The equivalent variables are expressed as substitutions as well
Attention: do not use this method with same objects t,f in several threads in parallel, it is NOT threadsafe!- Specified by:
unifyin interfaceSymbolTable- Parameters:
t- , the first entity (Variable, Function, Long, Literal)f- , the second entity (Variable, Function, Long, Literal)substitutions- , substitutions of variables with functions or ground terms- Returns:
- true, if unify operation was successful
- Throws:
IOExceptionSemReasonerException
-
unifiable
Description copied from interface:ReasoningSymbolTableUnifiable returns whether two structures are unifiable This method is cheaper than unify as it delivers no result substitutions- Specified by:
unifiablein interfaceReasoningSymbolTable- Specified by:
unifiablein interfaceSymbolTable- Parameters:
t- , the first entity (Variable, Function, Long, Literal)f- , the second entity (Variable, Function, Long, Literal)- Returns:
- true, if unifiable operation was successful
- Throws:
IOExceptionSemReasonerException
-
substituteFunction
public Object substituteFunction(Function f, Map<Variable, Object> subs) throws SemReasonerException, IOException- Throws:
SemReasonerExceptionIOException
-
substitute
substitutes the variables in an internal term by the codes found in substitutions, internalizes the resulting term and returns the code of the term Attention: do not use this method in several threads in parallel, it is NOT threadsafe! If you want to do that you have to create a clone of t for every thread!- Specified by:
substitutein interfaceReasoningSymbolTable- Specified by:
substitutein interfaceSymbolTable- Parameters:
t- , internal termsubstitutions-- Returns:
- Throws:
IOExceptionSemReasonerException
-
semiSubstitute
public Object semiSubstitute(Object t, long[] substitutions) throws SemReasonerException, IOException substitutes the variables in a term by the codes found in substitutions. The term is NOT internalized. These substitutions are accessed using method getSubsitutedArgument in functional terms. Is used in builtins only. This method does not access the symbol table. Attention: do not use this method in several threads in parallel, it is NOT threadsafe! If you want to do that you have to create a clone of t for every thread!- Parameters:
t- , internal termsubstitutions-- Returns:
- Throws:
IOExceptionSemReasonerException
-
substitute
substitutes the variables in a compound by the terms (non-ground) found in substitutions, internalizes the resulting term and returns the code of the term Attention: do not use this method in several threads in parallel, it is NOT threadsafe! If you want to do that you have to create a clone of t for every thread!- Specified by:
substitutein interfaceSymbolTable- Parameters:
t- , internal termsubstitutions-- Returns:
- Throws:
IOExceptionSemReasonerException
-
substituteArguments
public long[] substituteArguments(Object t, long[] substitutions) throws SemReasonerException, IOException Substitutes the variables in an internal term by the codes found in substitutions,
internalizes the resulting term and returns the code of the term.
Attention: do not use this method in several threads in parallel, it is NOT threadsafe!
If you want to do that you have to create a clone of t for every thread!- Specified by:
substituteArgumentsin interfaceReasoningSymbolTable- Specified by:
substituteArgumentsin interfaceSymbolTable- Parameters:
t- , internal termsubstitutions-- Returns:
- Throws:
IOExceptionSemReasonerException
-
substituteArguments
public Object[] substituteArguments(Object t, Object[] substitutions) throws SemReasonerException, IOException substitutes the variables in an internal term by the terms (non-ground) found in substitutions, internalizes the resulting term and returns the code of the term Attention: do not use this method in several threads in parallel, it is NOT threadsafe! If you want to do that you have to create a clone of t for every thread!- Specified by:
substituteArgumentsin interfaceSymbolTable- Parameters:
t- , internal termsubstitutions-- Returns:
- Throws:
IOExceptionSemReasonerException
-
createNonGroundFunction
Compile a non-ground user term into a non-ground internal term.
This internal term is hidden. It should be used in the internal
operations created by a rule compiler.
It must be used for matching operations and for substitution operations (see methods below)- Specified by:
createNonGroundFunctionin interfaceReasoningSymbolTable- Specified by:
createNonGroundFunctionin interfaceSymbolTable- Parameters:
f- , the user term- Returns:
- internalized term
- Throws:
IOExceptionSemReasonerException
-
decodeNonGroundFunction
Description copied from interface:SymbolTabledecompiles a ground internal function into an external function- Specified by:
decodeNonGroundFunctionin interfaceSymbolTable- Parameters:
t- , the term- Returns:
- Throws:
SemReasonerExceptionIOException
-
notifySymbolAdded
Description copied from interface:SymbolTableadd symbol to text indices- Specified by:
notifySymbolAddedin interfaceSymbolTable- Throws:
IOException
-
getTextIndex
Description copied from interface:SymbolTableget text index- Specified by:
getTextIndexin interfaceSymbolTable- Returns:
-
getGeoIndex
Description copied from interface:SymbolTableget geo index- Specified by:
getGeoIndexin interfaceSymbolTable- Returns:
-
addSymbolTableIndex
Description copied from interface:SymbolTableAdds an index to the symbol table.
Examples are the text index and the geo index.- Specified by:
addSymbolTableIndexin interfaceSymbolTable- Parameters:
index- the index
-
removeSymbolTableIndex
Description copied from interface:SymbolTableremoves the given symbol table index.- Specified by:
removeSymbolTableIndexin interfaceSymbolTable- Parameters:
index- the index
-
removeAllSymbolTableIndexes
public void removeAllSymbolTableIndexes()Description copied from interface:SymbolTableremoves all symbol table indexes.- Specified by:
removeAllSymbolTableIndexesin interfaceSymbolTable
-
recreateSymbolTableIndexes
Description copied from interface:SymbolTablerecreates all symbol table indexes from scratch.- Specified by:
recreateSymbolTableIndexesin interfaceSymbolTable- Throws:
SemReasonerException- if an error occursIOException
-
refreshSearchIndexes
public void refreshSearchIndexes(boolean waitForPendingTasks) Description copied from interface:SymbolTablerefreshes the search indices, i.e. waits until they are up-to-date.- Specified by:
refreshSearchIndexesin interfaceSymbolTable- Parameters:
waitForPendingTasks- Wait until all pending tasks are finished, which may included tasks which are not related to index lookups. To do so might take a lot of time.
-
encodeNotInternalize
public abstract long encodeNotInternalize(Object t) throws SemReasonerException, IOException, EDBException Description copied from interface:SymbolTableReturns a code for an object but does not internalize the object.
This means that there might be different codes
for the same object.- Specified by:
encodeNotInternalizein interfaceSymbolTable- Returns:
- Throws:
SemReasonerExceptionIOExceptionEDBException
-