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 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 user term into a non-ground internal term.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
isCreatedDuringReasoning
(long code) indicated for a code, that the corresponding symbol has been created during reasoningboolean
isEmpty()
is symbol table empty (now symbols stored)iterator()
get an iterator for all symbolslong
returns the last time a modification took placeboolean
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.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
renameTerm
(Object oldterm, Object newterm) void
reOpen()
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 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.void
begin a transaction.void
commit last changesvoid
abort last changesboolean
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>> equivalentVariables) 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
-
Constructor Details
-
ReasoningSymbolTableNotInternalize
-
-
Method Details
-
getExternalDataTypes
Description copied from interface:SymbolTable
get the provider for external data types- Specified by:
getExternalDataTypes
in interfaceSymbolTable
- Returns:
-
iterator
Description copied from interface:SymbolTable
get an iterator for all symbols- Specified by:
iterator
in interfaceIterable<Object>
- Specified by:
iterator
in interfaceSymbolTable
- Returns:
- an iterator over all symbols in this symbol table
-
encode
Description copied from interface:SymbolTable
Internalize 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:
encode
in interfaceSymbolTable
- Parameters:
t
- , the user term to be internalized- Returns:
- code, the code of the term
- Throws:
IOException
EDBException
SemReasonerException
-
getCode
Description copied from interface:SymbolTable
searches the code for a value returns 0 if term is not registered- Specified by:
getCode
in interfaceSymbolTable
- Returns:
- Throws:
IOException
SemReasonerException
-
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
-
renameTerm
-
clear
Description copied from interface:SymbolTable
remove all symbols- Specified by:
clear
in interfaceSymbolTable
- Throws:
IOException
SymboltableException
-
delete
Description copied from interface:SymbolTable
delete all / release files- Specified by:
delete
in interfaceSymbolTable
- Throws:
IOException
SymboltableException
-
close
Description copied from interface:SymbolTable
Close symbol table. Must be called to correctly finalize symbol table- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceSymbolTable
- Throws:
IOException
-
reOpen
public void reOpen() -
transactionBegin
Description copied from interface:SymbolTable
begin a transaction.- Specified by:
transactionBegin
in interfaceSymbolTable
- Throws:
SymboltableException
-
transactionRollback
Description copied from interface:SymbolTable
abort last changes- Specified by:
transactionRollback
in interfaceSymbolTable
- Throws:
SymboltableException
-
transactionCommit
Description copied from interface:SymbolTable
commit last changes- Specified by:
transactionCommit
in interfaceSymbolTable
- Throws:
IOException
SymboltableException
-
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:
IOException
SymboltableException
-
substitute
Description copied from interface:SymbolTable
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!- Specified by:
substitute
in interfaceSymbolTable
- Parameters:
t
- , entity (Variable, Function, Long, Literal)substitutions
- , gives for variable with position p the substituted value substitutions[p]- Returns:
- Throws:
IOException
SymboltableException
-
substitute
public Object substitute(Object t, Map<Variable, Object> substitutions) throws SymboltableException, IOException- Specified by:
substitute
in interfaceSymbolTable
- Throws:
SymboltableException
IOException
-
substituteArguments
public Object[] substituteArguments(Object t, Object[] substitutions) throws SymboltableException, IOException Description copied from interface:SymbolTable
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!- Specified by:
substituteArguments
in interfaceSymbolTable
- Parameters:
t
- , entity (Variable, Function, Long, Literal)substitutions
- , gives for variable with position p the substituted value substitutions[p]- Returns:
- Throws:
IOException
SymboltableException
-
unify
public boolean unify(Object t, Object f, Map<Variable, Object> substitutions, Map<Variable, throws SymboltableException, IOExceptionSet<Variable>> equivalentVariables) 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 termsequivalentVariables
- , equivalence classes for variables- Returns:
- true, if unify operation was successful
- Throws:
IOException
SymboltableException
-
unify
public boolean unify(Object t, Object f, Map<Variable, Object> substitutions) throws SymboltableException, 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
SymboltableException
-
size
public long size()Description copied from interface:SymbolTable
returns the number of symbols in the symbol table- Specified by:
size
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:
IOException
SymboltableException
-
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.
-
createNonGroundFunction
Description copied from interface:ReasoningSymbolTable
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:
t
- , the user term- Returns:
- term (Function)
- Throws:
IOException
SymboltableException
-
match
public boolean match(Object t, long groundterm, long[] substitutions) throws SymboltableException, IOException Description copied from interface:ReasoningSymbolTable
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 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
SymboltableException
-
matchArguments
public boolean matchArguments(Object t, long[] groundtermarguments, long[] substitutions) throws SymboltableException, IOException Description copied from interface:ReasoningSymbolTable
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
SymboltableException
-
substitute
Description copied from interface:ReasoningSymbolTable
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! 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
- , entity (Variable, Function, Long, Literal)substitutions
- , gives for variable with position p the substituted value substitutions[p]- Returns:
- Throws:
IOException
SymboltableException
-
substituteArguments
public long[] substituteArguments(Object t, long[] substitutions) throws SymboltableException, IOException Description copied from interface:ReasoningSymbolTable
substitutes 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:
substituteArguments
in interfaceReasoningSymbolTable
- Specified by:
substituteArguments
in interfaceSymbolTable
- Parameters:
t
- , entity (Variable, Function, Long, Literal)substitutions
- , gives for variable with position p the substituted value substitutions[p]- Returns:
- Throws:
IOException
SymboltableException
-
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
SymboltableException
-
isCreatedDuringReasoning
public boolean isCreatedDuringReasoning(long code) Description copied from interface:ReasoningSymbolTable
indicated for a code, that the corresponding symbol has been created during reasoning- Specified by:
isCreatedDuringReasoning
in interfaceReasoningSymbolTable
- Returns:
-
encodeNotInternalize
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:
IOException
SemReasonerException
-
hasIndices
public boolean hasIndices()Description copied from interface:SymbolTable
are there any indices attached to symbol table?- Specified by:
hasIndices
in interfaceSymbolTable
- Returns:
-
flush
Description copied from interface:SymbolTable
flushes symbol table.- Specified by:
flush
in interfaceSymbolTable
- Throws:
IOException
-
matchArguments
public boolean matchArguments(Object t, TupleBuffer groundtermarguments, long[] substitutions) throws SymboltableException, IOException - Specified by:
matchArguments
in interfaceSymbolTable
- Throws:
SymboltableException
IOException
-
removeNotInternalized
Description copied from interface:SymbolTable
remove a non internalized term from symbol table- Specified by:
removeNotInternalized
in interfaceSymbolTable
- Throws:
IOException
-
notifySymbolAdded
Description copied from interface:SymbolTable
add symbol to text indices- Specified by:
notifySymbolAdded
in interfaceSymbolTable
-
getFunctionEncoding
Description copied from interface:SymbolTable
Returns the codes of the arguments of a function given by code- Specified by:
getFunctionEncoding
in interfaceSymbolTable
- Parameters:
code
- , the code of the function- Returns:
- Throws:
IOException
SemReasonerException
-
commit
Description copied from interface:SymbolTable
commit transaction- Specified by:
commit
in interfaceSymbolTable
- Throws:
EDBException
IOException
-
rollback
public void rollback()Description copied from interface:SymbolTable
rollback transaction- Specified by:
rollback
in interfaceSymbolTable
-
checkSanity
Description copied from interface:SymbolTable
check sanity- Specified by:
checkSanity
in interfaceSymbolTable
- Returns:
- Throws:
IOException
-
lastModificationTime
public long lastModificationTime()Description copied from interface:SymbolTable
returns the last time a modification took place- Specified by:
lastModificationTime
in interfaceSymbolTable
- Returns:
-
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:
-
isEmpty
public boolean isEmpty()Description copied from interface:SymbolTable
is symbol table empty (now symbols stored)- Specified by:
isEmpty
in interfaceSymbolTable
- Returns:
-
setBulkMode
Description copied from interface:SymbolTable
for loading into an empty symbol table bulk mode should be used- Specified by:
setBulkMode
in interfaceSymbolTable
- Throws:
IOException
EDBException
-
getFunctionCode
Description copied from interface:SymbolTable
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 long createFunctionCode(long[] t, Function f) throws SemReasonerException, IOException, EDBException Description copied from interface:SymbolTable
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
EDBException
IOException
-
getValueFunction
Description copied from interface:SymbolTable
Produces 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:
getValueFunction
in interfaceSymbolTable
- Parameters:
code
- , the code of the internal term- Returns:
- Throws:
IOException
SemReasonerException
-
getValueSymbol
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:
getValueSymbol
in interfaceSymbolTable
- Parameters:
code
- , the code of the internal term- Returns:
- Throws:
IOException
SemReasonerException
-
encodeWOEncoding
Description copied from interface:SymbolTable
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- Specified by:
encodeWOEncoding
in interfaceSymbolTable
- Parameters:
t
- , the user term to be internalized- Returns:
- code, the code of the term
- Throws:
EDBException
IOException
SemReasonerException
-
isBulkMode
public boolean isBulkMode()Description copied from interface:SymbolTable
is symbol table in bulk mode- Specified by:
isBulkMode
in interfaceSymbolTable
- Returns:
-
resetTransaction
public void resetTransaction()Description copied from interface:SymbolTable
reset transaction- Specified by:
resetTransaction
in interfaceSymbolTable
-
inTransaction
public boolean inTransaction()Description copied from interface:SymbolTable
is symbol table within a transaction- Specified by:
inTransaction
in interfaceSymbolTable
- Returns:
-