1. Home
  2. High-level language production rules

High-level language production rules

◷ Reading Time: 1 minute

Languages

There are two high-level languages are supported for inferencing:

  1. XML based
  2. SExpression

XML

<inference>
    <reference assembly="FlexRule.Samples.PersonAge.exe"/>
 
    <import type="FlexRule.Samples.Person" />
    <import type="FlexRule.Samples.Gender" />
    <import type="System.Console" />
 
 
    <defrule name="older and younger">
        <match type="Person" variable="older">
          <e>e.Sex == Gender.Female</e>
        </match>
        <match type="Person" variable="younger">
          <p>p.Age < older.Age</p>
          <o>o.Sex == Gender.Male</o>
        </match>
        <then/>
        <action context="ctx" name="Print result">
          <execute>Console.WriteLine("{0} ({1}) is older than {2} ({3})", older.Name, older.Age, younger.Name, younger.Age)</execute>
        </action>
    </defrule>
</inference>

SExpression

(inference
    (reference (@assembly "FlexRule.Samples.PersonAge.exe"))
 
    (import (@type FlexRule.Samples.Person))
    (import (@type FlexRule.Samples.Gender))
    (import (@type System.Console))
 
    (defrule (@name "older and younger")
        (match (@type Person) (@variable older)
          (e "e.Sex == Gender.Female")
        )
        (match (@type Person) (@variable younger)
          (p "p.Age < older.Age")
          (o "o.Sex == Gender.Male")
        )
        ->
        (action (@context ctx) (@name "Print result")
          (execute 'Console.WriteLine("{0} ({1}) is older than {2} ({3})", older.Name, older.Age, younger.Name, younger.Age)')
        )
    )
)
Updated on July 12, 2019

Was this article helpful?