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 void
Adds an index to the symbol table.abstract long
createFunctionCode
(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 functionlong
Internalize a ground term.abstract long
Returns a code for an object but does not internalize the object.long
search for code of a termabstract long
getFunctionCode
(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 Function
getValueFunction
(long code) get function for symbol codeabstract Object
getValueSymbol
(long code) get object for symbol codeboolean
Match returns for each variable v in t the symbol s v has to be substituted by.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 groundtermarguments The result provides for variable position p the code of sboolean
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.abstract void
removes the given symbol table index.semiSubstitute
(Object t, long[] substitutions) substitutes the variables in a term by the codes found in substitutions.long
substitute
(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) boolean
Unifiable returns whether two structures are unifiable This method is cheaper than unify as it delivers no result substitutionsboolean
Unifies two structures (variables, terms, functions or literals).boolean
unify
(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, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
Methods inherited from interface com.semedy.reasoner.symboltable.ReasoningSymbolTable
isCreatedDuringReasoning
Methods 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:
getCode
in interfaceSymbolTable
- Parameters:
t
- , the user term to be internalized- Returns:
- code, the code of the term
- Throws:
SemReasonerException
EDBException
IOException
-
encode
Internalize a ground term. All constants, function symbols are internalized.- Specified by:
encode
in interfaceSymbolTable
- Parameters:
t
- , the user term to be internalized- Returns:
- code, the code of the term
- Throws:
SemReasonerException
IOException
EDBException
-
getValue
Description copied from interface:SymbolTable
Produces 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:
getValue
in interfaceSymbolTable
- Parameters:
code
- , the code of the internal term- Returns:
- Throws:
IOException
SemReasonerException
-
getValueSymbol
get object for symbol code- Specified by:
getValueSymbol
in interfaceSymbolTable
- Parameters:
code
- , symbol code- Returns:
- code for whole function
- Throws:
SemReasonerException
IOException
-
getValueFunction
get function for symbol code- Specified by:
getValueFunction
in interfaceSymbolTable
- Parameters:
code
- , symbol code- Returns:
- code for whole function
- Throws:
SemReasonerException
IOException
-
getFunctionCode
get function code- Specified by:
getFunctionCode
in interfaceSymbolTable
- 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
public abstract long createFunctionCode(long[] t, Function f) throws SemReasonerException, IOException, EDBException create function code- Specified by:
createFunctionCode
in interfaceSymbolTable
- 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
-
getFunctionEncoding
get the encoding of a function code, if it is there- Specified by:
getFunctionEncoding
in interfaceSymbolTable
- Parameters:
code
-- Returns:
- t[0] code of function symbol, t[1]..t[n] codes for n arguments
- Throws:
SemReasonerException
IOException
-
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:
match
in interfaceReasoningSymbolTable
- Specified by:
match
in 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:
SemReasonerException
IOException
-
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:
matchArguments
in interfaceReasoningSymbolTable
- Specified by:
matchArguments
in 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:
IOException
SemReasonerException
-
matchArguments
public boolean matchArguments(Object t, TupleBuffer groundtermarguments, long[] substitutions) throws SemReasonerException, IOException - Specified by:
matchArguments
in interfaceSymbolTable
- Throws:
SemReasonerException
IOException
-
substitute
public Object substitute(Object t, Map<Variable, Object> subs) throws IOException, SemReasonerException- Specified by:
substitute
in interfaceSymbolTable
- Throws:
IOException
SemReasonerException
-
unify
public boolean unify(Object t, Object f, Map<Variable, Object> substitutions, Map<Variable, throws SemReasonerException, IOExceptionSet<Variable>> equivalences) Description copied from interface:SymbolTable
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!- Specified by:
unify
in 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:
IOException
SemReasonerException
-
unify
public boolean unify(Object t, Object f, Map<Variable, Object> substitutions) throws SemReasonerException, IOExceptionDescription copied from interface:SymbolTable
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
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:
unify
in 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:
IOException
SemReasonerException
-
unifiable
Description copied from interface:ReasoningSymbolTable
Unifiable returns whether two structures are unifiable This method is cheaper than unify as it delivers no result substitutions- Specified by:
unifiable
in interfaceReasoningSymbolTable
- Specified by:
unifiable
in 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:
IOException
SemReasonerException
-
substituteFunction
public Object substituteFunction(Function f, Map<Variable, Object> subs) throws SemReasonerException, IOException- Throws:
SemReasonerException
IOException
-
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:
substitute
in interfaceReasoningSymbolTable
- Specified by:
substitute
in interfaceSymbolTable
- Parameters:
t
- , internal termsubstitutions
-- Returns:
- Throws:
IOException
SemReasonerException
-
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:
IOException
SemReasonerException
-
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:
substitute
in interfaceSymbolTable
- Parameters:
t
- , internal termsubstitutions
-- Returns:
- Throws:
IOException
SemReasonerException
-
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:
substituteArguments
in interfaceReasoningSymbolTable
- Specified by:
substituteArguments
in interfaceSymbolTable
- Parameters:
t
- , internal termsubstitutions
-- Returns:
- Throws:
IOException
SemReasonerException
-
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:
substituteArguments
in interfaceSymbolTable
- Parameters:
t
- , internal termsubstitutions
-- Returns:
- Throws:
IOException
SemReasonerException
-
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:
createNonGroundFunction
in interfaceReasoningSymbolTable
- Specified by:
createNonGroundFunction
in interfaceSymbolTable
- Parameters:
f
- , the user term- Returns:
- internalized term
- Throws:
IOException
SemReasonerException
-
decodeNonGroundFunction
Description copied from interface:SymbolTable
decompiles a ground internal function into an external function- Specified by:
decodeNonGroundFunction
in interfaceSymbolTable
- Parameters:
t
- , the term- Returns:
- Throws:
SemReasonerException
IOException
-
notifySymbolAdded
Description copied from interface:SymbolTable
add symbol to text indices- Specified by:
notifySymbolAdded
in interfaceSymbolTable
- Throws:
IOException
-
getTextIndex
Description copied from interface:SymbolTable
get text index- Specified by:
getTextIndex
in interfaceSymbolTable
- Returns:
-
getGeoIndex
Description copied from interface:SymbolTable
get geo index- Specified by:
getGeoIndex
in interfaceSymbolTable
- Returns:
-
addSymbolTableIndex
Description copied from interface:SymbolTable
Adds an index to the symbol table.
Examples are the text index and the geo index.- Specified by:
addSymbolTableIndex
in interfaceSymbolTable
- Parameters:
index
- the index
-
removeSymbolTableIndex
Description copied from interface:SymbolTable
removes the given symbol table index.- Specified by:
removeSymbolTableIndex
in interfaceSymbolTable
- Parameters:
index
- the index
-
removeAllSymbolTableIndexes
public void removeAllSymbolTableIndexes()Description copied from interface:SymbolTable
removes all symbol table indexes.- Specified by:
removeAllSymbolTableIndexes
in interfaceSymbolTable
-
recreateSymbolTableIndexes
Description copied from interface:SymbolTable
recreates all symbol table indexes from scratch.- Specified by:
recreateSymbolTableIndexes
in interfaceSymbolTable
- Throws:
SemReasonerException
- if an error occursIOException
-
refreshSearchIndexes
public void refreshSearchIndexes(boolean waitForPendingTasks) Description copied from interface:SymbolTable
refreshes the search indices, i.e. waits until they are up-to-date.- Specified by:
refreshSearchIndexes
in 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:SymbolTable
Returns 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:
encodeNotInternalize
in interfaceSymbolTable
- Returns:
- Throws:
SemReasonerException
IOException
EDBException
-