Monday, September 19, 2011

A new design to Frame2Relex Component of OpenCog

Input

Set of frames.

Onetime steps (should be done beforehand and serialize)
Step 1

Extract all unique frame templates from mapping rules (RelEx2Frame) file.

Eg: ^1_Arriving:Manner($Arriving,$var0)

Step 2 – Frame-Rule Bitmap

Create a bitmap for each frame template (of step 1 list) whose length is the number of rules (RelEx2Frame), where each bit corresponds to a unique rule i.e. if the ith frame template is present in the jth rule, the jth bit of the ith bitmap is set to 1.

Step 3 – Rule-Frame Bitmap

Create a bitmap for each rule (RelEx2Frame) whose length is the number of frame templates, where each bit corresponds to a unique frame template i.e. if the ith frame template is present in the jth rule, the ith bit of the jth bitmap is set to 1.

Step 4

Serialize all bitmaps.

Algorithm

Step 1

De-serialize all bitmaps.

Step 2

For each frame in the input: (eg: ^1_Entity:Entity(John,John) )

    Find the matching frame templates. (i.e. ^1_Entity:Entity($var0,$var0) )
  
Step 3

Perform 'OR' operation on Frame-Rule bitmaps of matching frame templates to obtain the Frame-Rule bitmap which corresponds to the possible rules that the input frames represent. Thus, we obtain a subset of rules using the positions that are true.

Step 4

All the rules obtained from step 3 are not necessarily the rules that are valid, since in some rules there are multiple frames as consequent. Thus, we perform a check on the subset of rules obtained from step 3, using the Rule-Frame bitmaps.

For each rule in the subset of rules:
    We check whether all its consequent frame templates are present in the frame templates correspond to input frames.

From this step we obtain a subset of rules (i.e. all necessary rules) of rules obtained at step 3.

Step 5

For each necessary rule:
    Using corresponding actual frames we map variables (eg: $var0, $Time) of this rule.
    We take its conditional part and remove all the 'NOT' true relations and 'OR' relations (ideally we should not remove 'OR' conditions, but handling this is tough/impossible?). Thus we take only the standalone 'TRUE' relations and 'TRUE' relations joined with an 'AND'. Note these are relation templates (eg: _subj($var0,$var1) ).
    We substitute values of variables in relation templates and obtain the actual relex relations.


That's it! :) Of course this will not provide all the relex relations that are needed to form a sentence, due to the limitations in existing RelEx2Frame rules.

Test case:

Input:

^1_Entity:Entity(John,John)

^1_Being_named:Entity(John)

^1_Transitive_action:Agent(throw,John)

^1_Cause_motion:Agent(throw,John)

^1_Cause_motion:Theme(throw,ball)

^1_Transitive_action:Patient(throw,ball)


Output:


noun(John)

_subj(throw,John)

_obj(throw,ball)

person(John)