Class ReasoningSymbolTableNotInternalize
java.lang.Object
com.semedy.reasoner.reasoning.processes.ReasoningSymbolTableNotInternalize
- All Implemented Interfaces:
SymbolTable,ReasoningSymbolTable,Closeable,AutoCloseable,Iterable<Object>
Wrapper around a reasoning symbol table which does not internalize terms
- Author:
- angele
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds an index to the symbol table.booleancheckSanity(boolean shadow) check sanityvoidclear()remove all symbolsvoidclose()Close symbol table.voidcommit()commit transactionlongcreateFunctionCode(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 functionvoiddelete()delete all / release fileslongInternalize a value.longReturns a code for an object but does not internalize the object.longInternalize a value.voidflush()flushes symbol table.longsearches the code for a value returns 0 if term is not registeredget the provider for external data typeslonggetFunctionCode(long[] t) get function codelong[]getFunctionEncoding(long code) Returns the codes of the arguments of a function given by codeget geo indexget text indexgetValue(long code) Produces a value from the code of an internal term.getValueFunction(long code) Produces a value from the code of an internal function.getValueSymbol(long code) Produces a value from the code of an internal term.booleanare there any indices attached to symbol table?booleanis symbol table within a transactionbooleanis symbol table in bulk modebooleanisCreatedDuringReasoning(long code) indicated for a code, that the corresponding symbol has been created during reasoningbooleanisEmpty()is symbol table empty (now symbols stored)iterator()get an iterator for all symbolslongreturns the last time a modification took placebooleanMatch 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.booleanmatchArguments(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.voidremoveNotInternalized(long code) remove a non internalized term from symbol tablevoidremoves the given symbol table index.voidrenameTerm(Object oldterm, Object newterm) voidreOpen()voidreset transactionvoidrollback()rollback transactionvoidsetBulkMode(boolean b) for loading into an empty symbol table bulk mode should be usedlongsize()returns the number of symbols in the symbol tablelongsubstitute(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 with same object t 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 terms and returns either the code of the term
or a non-ground term.substitute(Object t, Map<Variable, Object> substitutions) long[]substituteArguments(Object t, long[] substitutions) substitutes the variables in a compound t by the codes found in substitutions, internalizes the resulting terms and returns the arguments of t.Object[]substituteArguments(Object t, Object[] substitutions) Substitutes the variables in a compound t by the terms (non-ground) in substitutions,
internalizes the resulting terms and returns the arguments of t.voidbegin a transaction.voidcommit last changesvoidabort last changesbooleanUnifiable 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>> equivalentVariables) 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, spliterator
-
Constructor Details
-
ReasoningSymbolTableNotInternalize
-
-
Method Details
-
getExternalDataTypes
Description copied from interface:SymbolTableget the provider for external data types- Specified by:
getExternalDataTypesin interfaceSymbolTable- Returns:
-
iterator
Description copied from interface:SymbolTableget an iterator for all symbols- Specified by:
iteratorin interfaceIterable<Object>- Specified by:
iteratorin interfaceSymbolTable- Returns:
- an iterator over all symbols in this symbol table
-
encode
Description copied from interface:SymbolTableInternalize a value. All values are internalized,
i.e. for every different value there exists exactly one instance and thus
also exactly one code- Specified by:
encodein interfaceSymbolTable- Parameters:
t- , the user term to be internalized- Returns:
- code, the code of the term
- Throws:
IOExceptionEDBExceptionSemReasonerException
-
getCode
Description copied from interface:SymbolTablesearches the code for a value returns 0 if term is not registered- Specified by:
getCodein interfaceSymbolTable- Returns:
- Throws:
IOExceptionSemReasonerException
-
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
-
renameTerm
-
clear
Description copied from interface:SymbolTableremove all symbols- Specified by:
clearin interfaceSymbolTable- Throws:
IOExceptionSymboltableException
-
delete
Description copied from interface:SymbolTabledelete all / release files- Specified by:
deletein interfaceSymbolTable- Throws:
IOExceptionSymboltableException
-
close
Description copied from interface:SymbolTableClose symbol table. Must be called to correctly finalize symbol table- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceSymbolTable- Throws:
IOException
-
reOpen
public void reOpen() -
transactionBegin
Description copied from interface:SymbolTablebegin a transaction.- Specified by:
transactionBeginin interfaceSymbolTable- Throws:
SymboltableException
-
transactionRollback
Description copied from interface:SymbolTableabort last changes- Specified by:
transactionRollbackin interfaceSymbolTable- Throws:
SymboltableException
-
transactionCommit
Description copied from interface:SymbolTablecommit last changes- Specified by:
transactionCommitin interfaceSymbolTable- Throws:
IOExceptionSymboltableException
-
decodeNonGroundFunction
Description copied from interface:SymbolTabledecompiles a ground internal function into an external function- Specified by:
decodeNonGroundFunctionin interfaceSymbolTable- Parameters:
t- , the term- Returns:
- Throws:
IOExceptionSymboltableException
-
substitute
Description copied from interface:SymbolTableSubstitutes the variables in a compound by the terms (non-ground) found in substitutions,
internalizes the resulting terms and returns either the code of the term
or a non-ground term.
Attention: do not use this method with same object t 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- , entity (Variable, Function, Long, Literal)substitutions- , gives for variable with position p the substituted value substitutions[p]- Returns:
- Throws:
IOExceptionSymboltableException
-
substitute
public Object substitute(Object t, Map<Variable, Object> substitutions) throws SymboltableException, IOException- Specified by:
substitutein interfaceSymbolTable- Throws:
SymboltableExceptionIOException
-
substituteArguments
public Object[] substituteArguments(Object t, Object[] substitutions) throws SymboltableException, IOException Description copied from interface:SymbolTableSubstitutes the variables in a compound t by the terms (non-ground) in substitutions,
internalizes the resulting terms and returns the arguments of t.
for all variables a ground term has to be given in substitutions.
Attention: do not use this method with same object t 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- , entity (Variable, Function, Long, Literal)substitutions- , gives for variable with position p the substituted value substitutions[p]- Returns:
- Throws:
IOExceptionSymboltableException
-
unify
public boolean unify(Object t, Object f, Map<Variable, Object> substitutions, Map<Variable, throws SymboltableException, IOExceptionSet<Variable>> equivalentVariables) 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 termsequivalentVariables- , equivalence classes for variables- Returns:
- true, if unify operation was successful
- Throws:
IOExceptionSymboltableException
-
unify
public boolean unify(Object t, Object f, Map<Variable, Object> substitutions) throws SymboltableException, 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:
IOExceptionSymboltableException
-
size
public long size()Description copied from interface:SymbolTablereturns the number of symbols in the symbol table- Specified by:
sizein 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:
IOExceptionSymboltableException
-
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.
-
createNonGroundFunction
Description copied from interface:ReasoningSymbolTableCompile 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:
t- , the user term- Returns:
- term (Function)
- Throws:
IOExceptionSymboltableException
-
match
public boolean match(Object t, long groundterm, long[] substitutions) throws SymboltableException, IOException Description copied from interface:ReasoningSymbolTableMatch 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 entity (Variable, Function, Long, Literal)groundterm- , the code of the ground termsubstitutions- , the substitutions substitutions[variable position] is substituted term for variable- Returns:
- true, if match operation was successful
- Throws:
IOExceptionSymboltableException
-
matchArguments
public boolean matchArguments(Object t, long[] groundtermarguments, long[] substitutions) throws SymboltableException, IOException Description copied from interface:ReasoningSymbolTableMatch 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:
IOExceptionSymboltableException
-
substitute
Description copied from interface:ReasoningSymbolTablesubstitutes 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 with same object t 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- , entity (Variable, Function, Long, Literal)substitutions- , gives for variable with position p the substituted value substitutions[p]- Returns:
- Throws:
IOExceptionSymboltableException
-
substituteArguments
public long[] substituteArguments(Object t, long[] substitutions) throws SymboltableException, IOException Description copied from interface:ReasoningSymbolTablesubstitutes the variables in a compound t by the codes found in substitutions, internalizes the resulting terms and returns the arguments of t. Attention: do not use this method with same object t 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- , entity (Variable, Function, Long, Literal)substitutions- , gives for variable with position p the substituted value substitutions[p]- Returns:
- Throws:
IOExceptionSymboltableException
-
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:
IOExceptionSymboltableException
-
isCreatedDuringReasoning
public boolean isCreatedDuringReasoning(long code) Description copied from interface:ReasoningSymbolTableindicated for a code, that the corresponding symbol has been created during reasoning- Specified by:
isCreatedDuringReasoningin interfaceReasoningSymbolTable- Returns:
-
encodeNotInternalize
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:
IOExceptionSemReasonerException
-
hasIndices
public boolean hasIndices()Description copied from interface:SymbolTableare there any indices attached to symbol table?- Specified by:
hasIndicesin interfaceSymbolTable- Returns:
-
flush
Description copied from interface:SymbolTableflushes symbol table.- Specified by:
flushin interfaceSymbolTable- Throws:
IOException
-
matchArguments
public boolean matchArguments(Object t, TupleBuffer groundtermarguments, long[] substitutions) throws SymboltableException, IOException - Specified by:
matchArgumentsin interfaceSymbolTable- Throws:
SymboltableExceptionIOException
-
removeNotInternalized
Description copied from interface:SymbolTableremove a non internalized term from symbol table- Specified by:
removeNotInternalizedin interfaceSymbolTable- Throws:
IOException
-
notifySymbolAdded
Description copied from interface:SymbolTableadd symbol to text indices- Specified by:
notifySymbolAddedin interfaceSymbolTable
-
getFunctionEncoding
Description copied from interface:SymbolTableReturns the codes of the arguments of a function given by code- Specified by:
getFunctionEncodingin interfaceSymbolTable- Parameters:
code- , the code of the function- Returns:
- Throws:
IOExceptionSemReasonerException
-
commit
Description copied from interface:SymbolTablecommit transaction- Specified by:
commitin interfaceSymbolTable- Throws:
EDBExceptionIOException
-
rollback
public void rollback()Description copied from interface:SymbolTablerollback transaction- Specified by:
rollbackin interfaceSymbolTable
-
checkSanity
Description copied from interface:SymbolTablecheck sanity- Specified by:
checkSanityin interfaceSymbolTable- Returns:
- Throws:
IOException
-
lastModificationTime
public long lastModificationTime()Description copied from interface:SymbolTablereturns the last time a modification took place- Specified by:
lastModificationTimein interfaceSymbolTable- Returns:
-
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:
-
isEmpty
public boolean isEmpty()Description copied from interface:SymbolTableis symbol table empty (now symbols stored)- Specified by:
isEmptyin interfaceSymbolTable- Returns:
-
setBulkMode
Description copied from interface:SymbolTablefor loading into an empty symbol table bulk mode should be used- Specified by:
setBulkModein interfaceSymbolTable- Throws:
IOExceptionEDBException
-
getFunctionCode
Description copied from interface:SymbolTableget 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 long createFunctionCode(long[] t, Function f) throws SemReasonerException, IOException, EDBException Description copied from interface:SymbolTablecreate 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:
SemReasonerExceptionEDBExceptionIOException
-
getValueFunction
Description copied from interface:SymbolTableProduces a value from the code of an internal function.
Should be used only inside of built-ins and for generating the final answer.- Specified by:
getValueFunctionin interfaceSymbolTable- Parameters:
code- , the code of the internal term- Returns:
- Throws:
IOExceptionSemReasonerException
-
getValueSymbol
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:
getValueSymbolin interfaceSymbolTable- Parameters:
code- , the code of the internal term- Returns:
- Throws:
IOExceptionSemReasonerException
-
encodeWOEncoding
Description copied from interface:SymbolTableInternalize a value. All values are internalized,
i.e. for every different value there exists exactly one instance and thus
also exactly one code
Encoding is done without encoding characters in strings- Specified by:
encodeWOEncodingin interfaceSymbolTable- Parameters:
t- , the user term to be internalized- Returns:
- code, the code of the term
- Throws:
EDBExceptionIOExceptionSemReasonerException
-
isBulkMode
public boolean isBulkMode()Description copied from interface:SymbolTableis symbol table in bulk mode- Specified by:
isBulkModein interfaceSymbolTable- Returns:
-
resetTransaction
public void resetTransaction()Description copied from interface:SymbolTablereset transaction- Specified by:
resetTransactionin interfaceSymbolTable
-
inTransaction
public boolean inTransaction()Description copied from interface:SymbolTableis symbol table within a transaction- Specified by:
inTransactionin interfaceSymbolTable- Returns:
-