Interface SymbolTable

All Superinterfaces:
AutoCloseable, Closeable, Iterable<Object>
All Known Subinterfaces:
ReasoningSymbolTable
All Known Implementing Classes:
AbstractSymbolTable, MultiSymbolTable, ReasoningSymbolTableNotInternalize, ReasoningSymbolTableRAM, SymbolTableBplus, SymbolTableRAM

public interface SymbolTable extends Closeable, Iterable<Object>
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
  • Method Details

    • getFunctionCode

      long getFunctionCode(long[] t) throws SemReasonerException, IOException
      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

      boolean checkSanity(boolean shadow) throws IOException
      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

      Iterator<Object> iterator()
      get an iterator for all symbols
      Specified by:
      iterator in interface Iterable<Object>
      Returns:
      an iterator over all symbols in this symbol table
    • 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

      long encodeWOEncoding(Object t) throws SemReasonerException, IOException, EDBException
      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

      void notifySymbolAdded(Object symbol, long code) throws IOException
      add symbol to text indices
      Parameters:
      symbol -
      code -
      Throws:
      IOException
    • encodeNotInternalize

      long encodeNotInternalize(Object t) throws SemReasonerException, IOException
      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

      void removeNotInternalized(long code) throws IOException
      remove a non internalized term from symbol table
      Parameters:
      code -
      Throws:
      IOException
    • getFunctionEncoding

      long[] getFunctionEncoding(long code) throws IOException, SemReasonerException
      Returns the codes of the arguments of a function given by code
      Parameters:
      code - , the code of the function
      Returns:
      Throws:
      IOException
      SemReasonerException
    • getCode

      long getCode(Object t) throws SemReasonerException, IOException
      searches the code for a value returns 0 if term is not registered
      Parameters:
      t -
      Returns:
      Throws:
      SemReasonerException
      IOException
    • getValue

      Object getValue(long code) throws SemReasonerException, IOException
      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

      Object getValueSymbol(long code) throws SemReasonerException, IOException
      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

      Function getValueFunction(long code) throws SemReasonerException, IOException
      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
      Throws:
      IOException
      EDBException
      SemReasonerException
    • delete

      void delete() throws SemReasonerException, IOException
      delete all / release files
      Throws:
      IOException
      SemReasonerException
    • close

      void close() throws IOException
      Close symbol table. Must be called to correctly finalize symbol table
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException
    • flush

      void flush() throws IOException
      flushes symbol table.
      Throws:
      IOException
    • transactionBegin

      void transactionBegin() throws SemReasonerException, IOException
      begin a transaction.
      Throws:
      SemReasonerException - if an error occurs
      IOException
    • transactionRollback

      void transactionRollback() throws SemReasonerException, IOException
      abort last changes
      Throws:
      SemReasonerException - if an error occurs
      IOException
    • transactionCommit

      void transactionCommit() throws SemReasonerException, IOException
      commit last changes
      Throws:
      SemReasonerException - if an error occurs
      IOException
    • createNonGroundFunction

      Function createNonGroundFunction(Function t) throws SemReasonerException, IOException
      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

      Function decodeNonGroundFunction(Function t) throws SemReasonerException, IOException
      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 term
      substitutions - , 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 term
      substitutions - , 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

      long substitute(Object t, long[] substitutions) throws SemReasonerException, IOException
      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

      Object substitute(Object t, Object[] substitutions) throws SemReasonerException, IOException
      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

      long[] substituteArguments(Object t, long[] substitutions) throws SemReasonerException, IOException
      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

      boolean unifiable(Object t, Object f) throws SemReasonerException, IOException
      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,Set<Variable>> equivalentVariables) throws SemReasonerException, IOException
      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 terms
      equivalentVariables - , 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, IOException
      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!
      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

      void addSymbolTableIndex(SymbolTableIndex index)
      Adds an index to the symbol table.
      Examples are the text index and the geo index.
      Parameters:
      index - the index
    • removeSymbolTableIndex

      void removeSymbolTableIndex(SymbolTableIndex index)
      removes the given symbol table index.
      Parameters:
      index - the index
    • removeAllSymbolTableIndexes

      void removeAllSymbolTableIndexes()
      removes all symbol table indexes.
    • recreateSymbolTableIndexes

      void recreateSymbolTableIndexes() throws SemReasonerException, IOException
      recreates all symbol table indexes from scratch.
      Throws:
      SemReasonerException - if an error occurs
      IOException
    • 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

      void commit() throws EDBException, IOException
      commit transaction
      Throws:
      IOException
      EDBException
    • rollback

      void rollback()
      rollback transaction
    • setBulkMode

      void setBulkMode(boolean b) throws IOException, EDBException
      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: