HeaRTDroid

HeaRTDroid is a rule-based inference engine both for Android mobile devices, and desktop solutions

User Tools

Site Tools


pub:software:heartdroid:tutorials:haquna

HaQuNa

HeaRTDroid Query Notation is a simple language that can be used in an interactive commandline shell to load, modify, run HMR+ models.

Source code can be downloaded from HeaRTDroid repository

Most recent release can be downloaded from here HaQuNa v. 1.0.7.

You should have at least Java 7 to run HaQuNa.

Interactive mode

To run HaQuNa in interactive mode go to the directory where you saved haquna.jar and type in console

java -cp haquna.jar:. haquna.HaqunaMain

Non-interactive mode

Running scripts

You can run a script, which is a set of commands in HQN notation in non-interactive mode. To run a script that will printout the result to standard output run:

java -cp haquna.jar:. haquna.HaqunaMain script.hqn 

If you wish to run a script, but after that open a console, run

java -cp haquna.jar:. haquna.HaqunaMain --console (or -c) script.hqn

Running inference mode

HaQuNa allows you to run inference for selected models from bash. The result of the reasoning will be printed to standard output. The command-line options of HaQuNa are presented below

java -cp haquna.jar:. haquna.HaqunaMain --model model.hmr \
  --tables ['Table1','Table2'] \                     # mandatory only for foi 
  --inference [ddi|gdi|foi] \                        # optional, default = ddi
  --initial-state [att-name=value, att-name=value] \ # optional
  --conflict-resolution  [all|last|first] \          # optional, default first
  --tokens [on|off] \                                # optional, default off
  --uncertainty [on|off]                             # optional, default on

Language specification

Loading model from file

myModel = new Model('model.hmr')

Loading model from URL

myModel = new Model('http://example.com/model.hmr')

Saving model to file

myModel.save('/path/to/file/')

Running inference

  • With WorkingMemory object that stores initial state passed as a parameter:
    myModel.run(wm, //optional parameters//)
  • Without WorkingMemory (initial state has to be loaded by attributes' callbacks):
    workinMemory = myModel.run(//optional parameters//)
  • Optional parameters may be arbitrary permutation of the following
    • Inference strategy:
      inference=gdi|ddi|foi   // default ddi
    • Token passing:
      tokens=on|off   // default on
    • Uncertainty handling with CF algebra:
      uncertainty=on|off   // default on
    • Conflict resolution strategy:
      conflict_resolution=first|last|all   // default first
    • List of tables to process:
      tables=['tableName1','tableName2', ...] // mandatory only for foi mode
  • Examples:
    • myModel.run(wm, inference=gdi, tables=['Table3'])
    • wm = myModel.run(inference=foi, tables=['Table1','Table2','Table3'])

Running scripts

For details on running scripts see Non-interactive mode

load('script.hqn')

Getters for model objects

  • List all the tables in XTT2 model:
     myModel.showTablesList() 
  • List all attributes names form XTT2 mdoel:
     myModel.showAttributesList() 
  • List all types from XTT2 model:
    myModel.showTypesList()
  • Getting XTT2 table from a model:
    myTab = myModel.getTableByName('name')
    myTab = myModel.getTableById('id')
  • Getting attribute from a model:
    myAttr = myModel.getAttributeByName('name')
    myAttr = myModel.getAttributeById('id')
  • Getting type from a model:
    myType = myModel.getTypeByName('name')
    myType = myModel.getTypeById('id')

Getters for particular elements of XTT2 model

  • For Attribute objects:
    •  myAttr.show()
    •  myType = myAttr.getType()
    •  myCallback = myAttr.getCallback()
  • For Type objects:
     myType.show()
  • For Table objects:
    myTab.show()
    myRule = myTab.getRuleByName('name')
    myRule = myTab.getRuleById('id')
  • For Rule objects:
    myRule.show()
  • For Callback objects:
     myCallback.show()

Creating components

  • Types:
    newType = new Type('hmrCode')
  • Attributes:
    newAttr = new Attribute('hmrCode')
  • Tables:
    newTab = new Table('hmrCode');
  • Rules:
    newRule= new Rule(<'hmrCode');

Modifying XTT2 model

Original model stays intact

  • Adding components:
    • Types:
      newModel = oldModel.add(myType)
    • Attributes:
      newModel = oldModel.add(myAttr)
    • Tables:
      newModel = oldModel.add(myTable)
    • Rules:
      newModel = oldModel.add(myRule)
  • Removing components:
    • Types:
      newModel = oldModel.remove('typeName')
    • Attribtues:
      newModel = oldModel.remove('attrName')
    • Tables:
      newModel = oldModel.remove('tabName')
    • Rules:
      newModel = oldModel.remove('ruleName')

State management via Working Memory object

  • Creating Working Memory object:
    wm = new WorkingMemory(myModel)
  • Getting all values of attributes stored by WM:
    wm.showValueOf('attrName')
  • Setting values of attributes stored in WM (the value after # represents a certainty factor assigned to the value):
    wm.setValueOf('attrName','attrValue')
    wm.setValueOf('attrName','attrValue#cf')
  • Getting attribute value from a given point in history:
    WM.showValueOf('attrName', -1h)
  • Printing current state (current values of all attributes):
    wm.showCurrentState()
pub/software/heartdroid/tutorials/haquna.txt · Last modified: 2019/04/10 06:54 (external edit)