⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fibonacci.python.drl

📁 drools 一个开放源码的规则引擎
💻 DRL
字号:
<?xml version="1.0"?>

<rule-set name="fibonacci"
          xmlns="http://drools.org/rules"
          xmlns:python="http://drools.org/semantics/python"
          xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
          xs:schemaLocation="http://drools.org/rules rules.xsd
                             http://drools.org/semantics/python python.xsd">

  <import>from org.drools.examples.fibonacci import Fibonacci</import>

  <rule name="Bootstrap 1"   salience="20">
    <parameter identifier="f">
      <class>Fibonacci</class>
    </parameter>
    <python:condition>f.getSequence() == 1</python:condition>
    <python:condition>f.getValue() == -1</python:condition>
    <python:consequence>
      f.setValue( 1 )
      print "%d == %d" % ( f.getSequence(), f.getValue() )
      drools.modifyObject( f )
    </python:consequence>
  </rule>

  <rule name="Bootstrap 2">
    <parameter identifier="f">
      <class>Fibonacci</class>
    </parameter>
    <python:condition>f.getSequence() == 2</python:condition>
    <python:condition>f.getValue() == -1</python:condition>
    <python:consequence>
      f.setValue( 1 )
      print "%d == %d" % ( f.getSequence(), f.getValue() )
      drools.modifyObject( f )
    </python:consequence>
  </rule>

  <rule name="Recurse" salience="10">
    <parameter identifier="f">
      <class>Fibonacci</class>
    </parameter>
    <python:condition>f.getValue() == -1</python:condition>
    <python:consequence>
      from org.drools.examples.fibonacci import Fibonacci
      print "recurse for %d" % f.getSequence()
      drools.assertObject( Fibonacci( f.getSequence() - 1 ) )
    </python:consequence>
  </rule>

  <rule name="Calculate">
    <parameter identifier="f1">
      <class>Fibonacci</class>
    </parameter>
    <parameter identifier="f2">
      <class>Fibonacci</class>
    </parameter>
    <parameter identifier="f3">
      <class>Fibonacci</class>
    </parameter>
    <python:condition>f2.getSequence() == (f1.getSequence() + 1)</python:condition>
    <python:condition>f3.getSequence() == (f2.getSequence() + 1)</python:condition>
    <python:condition>f1.getValue() != -1</python:condition>
    <python:condition>f2.getValue() != -1</python:condition>
    <python:condition>f3.getValue() == -1</python:condition>
    <python:consequence>
      f3.setValue( f1.getValue() + f2.getValue() )
      print "%d == %d" % ( f3.getSequence(), f3.getValue() )
      drools.modifyObject( f3 )
      drools.retractObject( f1 )
    </python:consequence>
  </rule>

</rule-set>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -