configurationengine/doc/plugins/ruleml-plugin/ruleplugin.rst
changeset 0 2e8eeb919028
child 3 e7e0ae78773e
equal deleted inserted replaced
-1:000000000000 0:2e8eeb919028
       
     1 User guide for Rule Plugin usage in ConE
       
     2 ----------------------------------------
       
     3 
       
     4 Introduction
       
     5 '''''''''''''
       
     6 This page describes how to use ConE Rule plugin. With rule plugin one may set rule configuration 
       
     7 for the values in the confml. So for ex. one may have a case where is one confml value is been setted
       
     8 and one may create a rule configuration that if this value is for ex. 'foo' then some other value is
       
     9 'bar'. Value may be required or configures. 
       
    10 
       
    11 
       
    12 Creating a rule configuration file
       
    13 ''''''''''''''''''''''''''''''''''
       
    14 Create a new file a example.ruleml and set it's file encoding to UTF-8.
       
    15 Place the file in the impml folder in configuration project.
       
    16 The file is a XML base file. 
       
    17 First set the encoding tag 
       
    18 
       
    19 .. code-block:: xml
       
    20 
       
    21   <?xml version="1.0" encoding="UTF-8"?>* 
       
    22 
       
    23 and then create a root tag
       
    24 
       
    25 .. code-block:: xml
       
    26 
       
    27   <ruleml xmlns="http://www.s60.com/xml/ruleml/1">*
       
    28  
       
    29 give a set of rules for ex. 
       
    30  
       
    31 .. code-block:: xml
       
    32 
       
    33   <rule>mms.imagesize == 'large' configures pd.ref1 = True and pd.ref2 = True</rule>*
       
    34  
       
    35 and close the ruleml tag.
       
    36 
       
    37 One may say use several boolean operators for the configuration rule like for ex.
       
    38  
       
    39 .. code-block:: xml
       
    40 
       
    41   and, or, ==, !=* 
       
    42  
       
    43 Like for ex.
       
    44 
       
    45 .. code-block:: xml
       
    46 
       
    47   <rule>mms.imagesize == 'large' configures pd.ref1 = True and pd.ref2 = True</rule>*
       
    48  
       
    49 means that if reference link mms/imagesize  in some confml file is set to large then reference 
       
    50 link pd/ref1 value is true and pd/ref2 value is set to true also.
       
    51 
       
    52 **All in all one may create a dependency like project configuration with ruleml files.**  
       
    53 
       
    54 Ruleml version 2 adds support for calling `Python <http://www.python.org/doc/2.5/>`_ expressions from rules. Python expression are defined between ``{%`` and ``%}``:
       
    55 
       
    56 .. code-block:: xml
       
    57 
       
    58   <rule>feat1.setting2 == True configures feat2.setting2 = {% ${feat3.setting2} %}</rule>
       
    59 
       
    60 Expression return a result, that can be used in rule e.g. to set a value to some setting in configuration. These expression can be used to create more complex logic into rules that is not possible with standard rule expressions. Inside eval expressions features and feature's values can be accessed by following syntax:
       
    61 
       
    62 Accesses to the value::
       
    63 
       
    64   ${Feature.Setting}
       
    65 
       
    66 Accesses to the feature object::
       
    67 
       
    68   @{Feature.Setting}
       
    69 
       
    70 Python functions or constants that can be accessed inside expressions can be defined by ``<eval_globals>`` elements:
       
    71 
       
    72 .. code-block:: xml
       
    73 
       
    74   <eval_globals>
       
    75   def my_function1(attribute):
       
    76       return attribute + 1
       
    77   </eval_globals>
       
    78   
       
    79   <eval_globals>CONST_1 = "my constant"</eval_globals>
       
    80   
       
    81   <eval_globals file=".scripts/evals_in_file.py"/>
       
    82   
       
    83 Definitions can be inside <eval_globals> elements or definitions can be in separate file referenced with ``file`` attribute.
       
    84 The path specified in this attribute is relative to the RuleML implementation file. So, for example, if your implementation
       
    85 file's location is ``some/layer/implml/my_rules.ruleml``, the actual path specified in the above example would be
       
    86 ``some/layer/implml/.scripts/evals_in_file.py``. It is recommended to place the scripts under a directory beginning
       
    87 with a dot, so that the plug-in loader does not attempt to load the .py file as an implementation (files and directories beginning
       
    88 with a dot are ignored in the implementation loading phase).
       
    89 
       
    90 Running
       
    91 '''''''''''''''''''''
       
    92 
       
    93 ::
       
    94 
       
    95   cone generate -p someproject.cpf -o c:/temp/coneoutput -i rulemlfile.ruleml
       
    96 
       
    97 Generates files out of configuration file and takes the implementation rulemlfile.ruleml in concern,
       
    98 and the output is to been set to -o given folder 
       
    99 
       
   100 for more example see the cone documentation
       
   101 
       
   102 Examples
       
   103 '''''''''
       
   104 
       
   105 
       
   106 **Ruleml version 1 file example**
       
   107 
       
   108 .. code-block:: xml
       
   109 
       
   110   <?xml version="1.0" encoding="UTF-8"?>
       
   111   <ruleml xmlns="http://www.s60.com/xml/ruleml/1">
       
   112   <rule>imaker.imagetarget configures imakerapi.outputLocation = imaker.imagetarget</rule>
       
   113   <rule>mms.imagesize == 'large' configures pd.ref1 = True and pd.ref2 = True</rule>
       
   114   <rule>mms.imagesize == 'small' configures pd.ref1 = False and pd.ref2 = True</rule>
       
   115   <rule>mms.imagesize == 'extrasmall' configures pd.ref1 = False and pd.ref2 = False</rule>
       
   116   <rule>mms.imagesize == 'extralarge' configures pd.ref1 = True and pd.ref2 = False</rule>
       
   117   </ruleml>
       
   118 
       
   119 **What do the example ruleml file means**
       
   120 
       
   121 The example file set the values upon the image size. First it sets the iMaker output
       
   122 location target and then it starts to set the mms message image size settings. So if for ex.
       
   123 *mms/imagesize* refence link value in confml file is set to *extralarge* then the value of
       
   124 *pd/ref1* is set to *true* and the value *pd/ref2* is set to false.
       
   125 
       
   126 
       
   127 **Ruleml version 2 file example**
       
   128 
       
   129 .. code-block:: xml
       
   130 
       
   131   <?xml version="1.0" encoding="UTF-8"?>
       
   132   <ruleml xmlns="http://www.s60.com/xml/ruleml/2">
       
   133   <rule>feat1.setting1 == 'somevalue' configures feat2.setting1 = {% len( ${feat3.setting1} ) %}</rule>
       
   134   <rule>feat1.setting2 == True configures feat2.setting2 = {% my_function1( ${feat3.setting2} ) %}</rule>
       
   135   <rule>feat1.setting3 == True configures feat2.setting3 = {% CONST_1 %}</rule>
       
   136   <rule>{% my_function2( ${feat1.setting4} ) %} configures feat2.setting4 = False</rule>
       
   137   <rule>{% @{feat1.setting5}.get_type() %} == 'int' configures feat2.setting5 = 'integer'</rule>
       
   138   <rule>feat1.setting6 == True configures feat2.setting6 = {% '0x%08X' % ${feat2.setting6} %}</rule>
       
   139   <eval_globals>
       
   140   def my_function1(attribute):
       
   141       return attribute + 1
       
   142   def my_function2(attribute):
       
   143       if attribute == 'abc':
       
   144           return True
       
   145       else:
       
   146           return False
       
   147   </eval_globals>
       
   148   <eval_globals>
       
   149   CONST_1 = "my constant"
       
   150   </eval_globals>
       
   151   <eval_globals file=".scripts/evals_in_file.py"/>
       
   152   </ruleml>
       
   153 
       
   154 XSD
       
   155 '''''''''
       
   156 
       
   157 Ruleml version 1: :download:`ruleml.xsd </xsd/ruleml.xsd>`
       
   158 
       
   159 Ruleml version 2: :download:`ruleml2.xsd </xsd/ruleml2.xsd>`
       
   160 
       
   161 FAQ
       
   162 '''''''''
       
   163 This will be updated based on the questions.