Class StockPrice

java.lang.Object
com.semedy.reasoner.builtin.functional.StockPrice
All Implemented Interfaces:
Builtin, DynamicBuiltin, FunctionalBuiltin

public class StockPrice extends Object implements FunctionalBuiltin, DynamicBuiltin
The Class StockPriceBuiltin implements the FunctionalBuiltin interface. It contains the Stock-Price-Builtin, which allows to fetch the last price quote of stock. It stores the last quote in a ConcurrentHashMap and updates the quotes every 10 minutes. After the initial request the cached stock price quotes are returned.
  • Constructor Details

    • StockPrice

      public StockPrice()
  • Method Details

    • evaluate

      public boolean evaluate(long[] input, BitSet grounds) throws SemReasonerException, InterruptedException, IOException
      Evaluate returns the stock price for the given symbol. If the symbol has been already cached, it returns the cached price. If the symbol is new, it requests the price and caches it. Afterwards the cached price is returned, which is updated every 10 minutes.
      Specified by:
      evaluate in interface FunctionalBuiltin
      Parameters:
      input - the input
      grounds - the grounds
      Returns:
      true, if successful
      Throws:
      ReasoningException - the reasoning exception
      InterruptedException - the interrupted exception
      IOException - Signals that an I/O exception has occurred.
      SemReasonerException
    • isEvaluable

      public boolean isEvaluable(BitSet grounds, BitSet variableInstantiations, Object[] args) throws BuiltinException
      Description copied from interface: Builtin
      is builtin evaluable with a certain instantiation of variables
      Specified by:
      isEvaluable in interface Builtin
      Parameters:
      grounds - , which arguments are ground
      variableInstantiations - , which variables are instantiated
      args - , the arguments
      Returns:
      was it evaluable
      Throws:
      BuiltinException
    • init

      public void init(Object[] args) throws BuiltinException, InterruptedException
      Description copied from interface: Builtin
      initialize the builtin
      Specified by:
      init in interface Builtin
      Parameters:
      args - , the builtin arguments
      Throws:
      InterruptedException
      BuiltinException
    • evaluationFinished

      public void evaluationFinished() throws BuiltinException, InterruptedException
      Description copied from interface: Builtin
      call back function. Is called when the whole evaluation has been finished
      Specified by:
      evaluationFinished in interface Builtin
      Throws:
      BuiltinException
      InterruptedException
    • getWeight

      public long getWeight(BitSet grounds, BitSet variableInstantiations, Object[] args)
      Description copied from interface: Builtin
      the weight of the builtin. Determines when the builtin is executed in a rule
      Specified by:
      getWeight in interface Builtin
      Parameters:
      grounds - , ground arguments
      variableInstantiations - , instantiated variables
      args - , arguments of the builtin
      Returns:
      the weight of the builtin (influences the position in the rule)
    • objectGeneratingArguments

      public BitSet objectGeneratingArguments(BitSet grounds, BitSet variableInstantiations, Object[] args) throws BuiltinException
      Description copied from interface: Builtin
      In which argument position are new objects created
      Specified by:
      objectGeneratingArguments in interface Builtin
      Parameters:
      grounds - , ground argument positions
      variableInstantiations - , instantiated variables
      args - , arguments of the literal
      Returns:
      each bit indicates the argument position where new objects are created
      Throws:
      BuiltinException
    • getName

      public String getName()
      Description copied from interface: Builtin
      get the name of the builtin
      Specified by:
      getName in interface Builtin
      Returns:
      the name of the built-in
    • getArity

      public int getArity()
      Description copied from interface: Builtin
      get the arity of the builtin
      Specified by:
      getArity in interface Builtin
      Returns:
      the arity of the built-in
    • getType

      public BuiltinType getType()
      Description copied from interface: Builtin
      get the type of the builtin
      Specified by:
      getType in interface Builtin
      Returns:
      the type of the built-in
    • isInternal

      public boolean isInternal()
      Description copied from interface: Builtin
      is it a builtin for internal use only
      Specified by:
      isInternal in interface Builtin
      Returns:
    • getDescription

      public String getDescription()
      Description copied from interface: Builtin
      get a description for the builtin
      Specified by:
      getDescription in interface Builtin
      Returns:
      a description of the built-in
    • getArgumentDescriptions

      public String[] getArgumentDescriptions()
      Description copied from interface: Builtin
      get descriptions for the different arguments
      Specified by:
      getArgumentDescriptions in interface Builtin
      Returns:
      a description of the arguments of the built-in
    • readsSymbolTable

      public boolean readsSymbolTable()
      Description copied from interface: Builtin
      does the builtin read the symbol table
      Specified by:
      readsSymbolTable in interface Builtin
      Returns:
      true if it reads the symbol table
    • writesSymbolTable

      public boolean writesSymbolTable()
      Description copied from interface: Builtin
      does the builtin write into the symbol table
      Specified by:
      writesSymbolTable in interface Builtin
      Returns:
      true if it writes to the symbol table
    • cloneBuiltin

      public Builtin cloneBuiltin()
      Description copied from interface: Builtin
      clone the builtin
      Specified by:
      cloneBuiltin in interface Builtin
      Returns:
      the cloned built-in
    • clear

      public void clear()
      Description copied from interface: Builtin
      frees up allocated resources
      Specified by:
      clear in interface Builtin
    • setProperties

      public void setProperties(Properties arg0)
      Description copied from interface: Builtin
      set the sytem properties
      Specified by:
      setProperties in interface Builtin
      Parameters:
      arg0 - , properties
    • setSymbolTable

      public void setSymbolTable(SymbolTable symbols)
      Description copied from interface: Builtin
      set the symbol table
      Specified by:
      setSymbolTable in interface Builtin
      Parameters:
      symbols - , the symbol table