Interface SymbolTable
- All Superinterfaces:
AutoCloseable,Closeable,Iterable<Object>
- All Known Subinterfaces:
ReasoningSymbolTable
- All Known Implementing Classes:
AbstractSymbolTable,MultiSymbolTable,ReasoningSymbolTableNotInternalize,ReasoningSymbolTableRAM,SymbolTableBplus,SymbolTableRAM
Provides basic functionality for handling symbols, i.e. constants and functions.
Symbols are encoded in reasoning, i.e. to every symbol a numeric code is assigned.
Symbols are ground terms and ground functions. Within literals and non-ground functions
the ground terms must also be encoded such that unify, match etc. work correctly.
The symbol table maps symbols to their codes
Symbols are encoded in reasoning, i.e. to every symbol a numeric code is assigned.
Symbols are ground terms and ground functions. Within literals and non-ground functions
the ground terms must also be encoded such that unify, match etc. work correctly.
The symbol table maps symbols to their codes
-
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 function into a non-ground internalized function.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 modebooleanisEmpty()is symbol table empty (now symbols stored)iterator()get an iterator for all symbolslongreturns the last time a modification took placebooleanMatches a non-ground structure (function or literal) with a ground structure (function or literal).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 ground term arguments.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.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 a compound by the codes found in substitutions,
internalizes the resulting term and returns the code of the term.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 changesbooleanUnifies two structures (functions or literals).booleanUnifies 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 interface java.lang.Iterable
forEach, spliterator
-
Method Details
-
getFunctionCode
get function code- Parameters:
t- , t[0] code of function symbol, t[1]..t[n] codes for n arguments- Returns:
- code for whole function
- Throws:
SemReasonerExceptionIOException
-
createFunctionCode
long createFunctionCode(long[] t, Function f) throws SemReasonerException, IOException, EDBException create function code- Parameters:
t- , t[0] code of function symbol, t[1]..t[n] codes for n arguments- Returns:
- code for whole function
- Throws:
SemReasonerExceptionIOExceptionEDBException
-
checkSanity
check sanity- Parameters:
shadow-- Returns:
- Throws:
IOException
-
isEmpty
boolean isEmpty()is symbol table empty (now symbols stored)- Returns:
-
lastModificationTime
long lastModificationTime()returns the last time a modification took place- Returns:
-
getExternalDataTypes
ExternalDataTypeProvider getExternalDataTypes()get the provider for external data types- Returns:
-
iterator
get an iterator for all symbols -
encode
Internalize a value. All values are internalized,
i.e. for every different value there exists exactly one instance and thus
also exactly one code- Parameters:
t- , the user term to be internalized- Returns:
- code, the code of the term
- Throws:
IOExceptionEDBExceptionSemReasonerException
-
encodeWOEncoding
Internalize 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- Parameters:
t- , the user term to be internalized- Returns:
- code, the code of the term
- Throws:
IOExceptionEDBExceptionSemReasonerException
-
notifySymbolAdded
add symbol to text indices- Parameters:
symbol-code-- Throws:
IOException
-
encodeNotInternalize
Returns a code for an object but does not internalize the object.
This means that there might be different codes
for the same object.- Parameters:
t-- Returns:
- Throws:
IOExceptionSemReasonerException
-
removeNotInternalized
remove a non internalized term from symbol table- Parameters:
code-- Throws:
IOException
-
getFunctionEncoding
Returns the codes of the arguments of a function given by code- Parameters:
code- , the code of the function- Returns:
- Throws:
IOExceptionSemReasonerException
-
getCode
searches the code for a value returns 0 if term is not registered- Parameters:
t-- Returns:
- Throws:
SemReasonerExceptionIOException
-
getValue
Produces a value from the code of an internal term.
Should be used only inside of built-ins and for generating the final answer.- Parameters:
code- , the code of the internal term- Returns:
- Throws:
IOExceptionSemReasonerException
-
getValueSymbol
Produces a value from the code of an internal term.
Should be used only inside of built-ins and for generating the final answer.- Parameters:
code- , the code of the internal term- Returns:
- Throws:
IOExceptionSemReasonerException
-
getValueFunction
Produces a value from the code of an internal function.
Should be used only inside of built-ins and for generating the final answer.- Parameters:
code- , the code of the internal term- Returns:
- Throws:
IOExceptionSemReasonerException
-
clear
remove all symbols -
delete
delete all / release files- Throws:
IOExceptionSemReasonerException
-
close
Close symbol table. Must be called to correctly finalize symbol table- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
flush
flushes symbol table.- Throws:
IOException
-
transactionBegin
begin a transaction.- Throws:
SemReasonerException- if an error occursIOException
-
transactionRollback
abort last changes- Throws:
SemReasonerException- if an error occursIOException
-
transactionCommit
commit last changes- Throws:
SemReasonerException- if an error occursIOException
-
createNonGroundFunction
Compile a non-ground function into a non-ground internalized function.
The resulting function must be used for matching operations and for
substitution operations (see methods below)- Parameters:
t- , the user term- Returns:
- term (Function)
- Throws:
IOExceptionSemReasonerException
-
decodeNonGroundFunction
decompiles a ground internal function into an external function- Parameters:
t- , the term- Returns:
- Throws:
SemReasonerExceptionIOException
-
match
boolean match(Object t, long groundterm, long[] substitutions) throws IOException, SemReasonerException Matches a non-ground structure (function or literal) with a ground structure (function or literal).
The functions and literals have to be internalized (encoded).
Match returns for each variable v in t the symbol s v has to be substituted by.
The result provides for variable at position p the code of s- 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:
IOExceptionSemReasonerException
-
matchArguments
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 ground term arguments.
The result provides for variable at position p the code of s- 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
boolean matchArguments(Object t, TupleBuffer groundtermarguments, long[] substitutions) throws SemReasonerException, IOException - Throws:
SemReasonerExceptionIOException
-
substitute
Substitutes the variables in a compound by the codes found in substitutions,
internalizes the resulting term and returns the code of the term.
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,
as it is NOT threadsafe! If you want to do that you have to create a
clone of t for every thread!- Parameters:
t- , entity (Variable, Function, Long, Literal)substitutions- , gives for variable with position p the substituted value substitutions[p]- Returns:
- Throws:
IOExceptionSemReasonerException
-
substitute
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.
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!- Parameters:
t- , entity (Variable, Function, Long, Literal)substitutions- , gives for variable with position p the substituted value substitutions[p]- Returns:
- Throws:
IOExceptionSemReasonerException
-
substitute
Object substitute(Object t, Map<Variable, Object> substitutions) throws IOException, SemReasonerException- Throws:
IOExceptionSemReasonerException
-
substituteArguments
Substitutes the variables in a compound t by the codes found 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!- Parameters:
t- , entity (Variable, Function, Long, Literal)substitutions- , gives for variable with position p the substituted value substitutions[p]- Returns:
- Throws:
IOExceptionSemReasonerException
-
substituteArguments
Object[] substituteArguments(Object t, Object[] substitutions) throws SemReasonerException, IOException Substitutes 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!- Parameters:
t- , entity (Variable, Function, Long, Literal)substitutions- , gives for variable with position p the substituted value substitutions[p]- Returns:
- Throws:
IOExceptionSemReasonerException
-
unifiable
Unifies two structures (functions or literals). The functions and literals have to be internalized (encoded). Unifiable returns whether two structures (functions or literals) are unifiable.
This method is cheaper than unify as it delivers no result substitutions- 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
-
unify
boolean unify(Object t, Object f, Map<Variable, Object> substitutions, Map<Variable, throws SemReasonerException, IOExceptionSet<Variable>> equivalentVariables) Unifies 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!- 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:
IOExceptionSemReasonerException
-
unify
boolean unify(Object t, Object f, Map<Variable, Object> substitutions) throws SemReasonerException, IOExceptionUnifies 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!- 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
-
size
long size()returns the number of symbols in the symbol table- Returns:
-
getTextIndex
TextIndex getTextIndex()get text index- Returns:
-
getGeoIndex
GeoIndex getGeoIndex()get geo index- Returns:
-
addSymbolTableIndex
Adds an index to the symbol table.
Examples are the text index and the geo index.- Parameters:
index- the index
-
removeSymbolTableIndex
removes the given symbol table index.- Parameters:
index- the index
-
removeAllSymbolTableIndexes
void removeAllSymbolTableIndexes()removes all symbol table indexes. -
recreateSymbolTableIndexes
recreates all symbol table indexes from scratch.- Throws:
SemReasonerException- if an error occursIOException
-
refreshSearchIndexes
void refreshSearchIndexes(boolean waitForPendingTasks) refreshes the search indices, i.e. waits until they are up-to-date.- 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.
-
hasIndices
boolean hasIndices()are there any indices attached to symbol table?- Returns:
-
commit
commit transaction- Throws:
IOExceptionEDBException
-
rollback
void rollback()rollback transaction -
setBulkMode
for loading into an empty symbol table bulk mode should be used- Throws:
IOExceptionEDBException
-
isBulkMode
boolean isBulkMode()is symbol table in bulk mode- Returns:
-
resetTransaction
void resetTransaction()reset transaction -
inTransaction
boolean inTransaction()is symbol table within a transaction- Returns:
-