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 TypeMethodDescriptionvoid
Adds an index to the symbol table.boolean
checkSanity
(boolean shadow) check sanityvoid
clear()
remove all symbolsvoid
close()
Close symbol table.void
commit()
commit transactionlong
createFunctionCode
(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 functionvoid
delete()
delete all / release fileslong
Internalize a value.long
Returns a code for an object but does not internalize the object.long
Internalize a value.void
flush()
flushes symbol table.long
searches the code for a value returns 0 if term is not registeredget the provider for external data typeslong
getFunctionCode
(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.boolean
are there any indices attached to symbol table?boolean
is symbol table within a transactionboolean
is symbol table in bulk modeboolean
isEmpty()
is symbol table empty (now symbols stored)iterator()
get an iterator for all symbolslong
returns the last time a modification took placeboolean
Matches a non-ground structure (function or literal) with a ground structure (function or literal).boolean
matchArguments
(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.boolean
matchArguments
(Object t, TupleBuffer groundtermarguments, long[] substitutions) void
notifySymbolAdded
(Object symbol, long code) add symbol to text indicesvoid
recreates all symbol table indexes from scratch.void
refreshSearchIndexes
(boolean waitForPendingTasks) refreshes the search indices, i.e. waits until they are up-to-date.void
removes all symbol table indexes.void
removeNotInternalized
(long code) remove a non internalized term from symbol tablevoid
removes the given symbol table index.void
reset transactionvoid
rollback()
rollback transactionvoid
setBulkMode
(boolean b) for loading into an empty symbol table bulk mode should be usedlong
size()
returns the number of symbols in the symbol tablelong
substitute
(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.void
begin a transaction.void
commit last changesvoid
abort last changesboolean
Unifies two structures (functions or literals).boolean
Unifies two structures (variables, terms, functions or literals).boolean
unify
(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:
SemReasonerException
IOException
-
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:
SemReasonerException
IOException
EDBException
-
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:
IOException
EDBException
SemReasonerException
-
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:
IOException
EDBException
SemReasonerException
-
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:
IOException
SemReasonerException
-
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:
IOException
SemReasonerException
-
getCode
searches the code for a value returns 0 if term is not registered- Parameters:
t
-- Returns:
- Throws:
SemReasonerException
IOException
-
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:
IOException
SemReasonerException
-
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:
IOException
SemReasonerException
-
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:
IOException
SemReasonerException
-
clear
remove all symbols -
delete
delete all / release files- Throws:
IOException
SemReasonerException
-
close
Close symbol table. Must be called to correctly finalize symbol table- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in 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:
IOException
SemReasonerException
-
decodeNonGroundFunction
decompiles a ground internal function into an external function- Parameters:
t
- , the term- Returns:
- Throws:
SemReasonerException
IOException
-
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:
IOException
SemReasonerException
-
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:
IOException
SemReasonerException
-
matchArguments
boolean matchArguments(Object t, TupleBuffer groundtermarguments, long[] substitutions) throws SemReasonerException, IOException - Throws:
SemReasonerException
IOException
-
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:
IOException
SemReasonerException
-
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:
IOException
SemReasonerException
-
substitute
Object substitute(Object t, Map<Variable, Object> substitutions) throws IOException, SemReasonerException- Throws:
IOException
SemReasonerException
-
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:
IOException
SemReasonerException
-
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:
IOException
SemReasonerException
-
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:
IOException
SemReasonerException
-
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:
IOException
SemReasonerException
-
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:
IOException
SemReasonerException
-
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:
IOException
EDBException
-
rollback
void rollback()rollback transaction -
setBulkMode
for loading into an empty symbol table bulk mode should be used- Throws:
IOException
EDBException
-
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:
-