Drools / JBoss RulesのLHSを書く際に1つのファクトを照合し、そのファクトを使用して別のファクトが存在するかどうかを判断する問題

StackOverflow https://stackoverflow.com/questions/415907

  •  03-07-2019
  •  | 
  •  

質問

いくつかのルールを表現するために(初めて)Droolsを使用していますが、これまでのところ非常にうまく機能しています。ただし、ルール言語で非常に明確に表現できないという新しい条件が与えられました。

本質的には、プレイヤーのアカウントに特定の金額の未払いの残高がある場合、先週に支払いを行っていない、および支払いをしていない場合、プレイヤーのアカウントでアクションを実行する必要があります毎週の控除以上の最後の4週間。他にもいくつかのルールがありますが、この質問のルールを簡素化するためにそれらを削除しました。それが問題を引き起こしている最後のルールです。

rule "The broken rule"
   salience 10
   no-loop
   when
      Player( $playerNumber : playerNumber )
      $a : Account( // balance between £5 and £100 and no arrangement
       playerNumber == $playerNumber &&
         accountBalanceInPence >= 500 &&
         accountBalanceInPence <= 10000
      )
      not ( // no payment in last week
         exists AccountTransaction(
            playerNumber == $playerNumber &&
            transactionDate >= oneWeekAgo &&
            transactionCode == "P" // payment
         )
      )
      /* It's this next bit that is broken */
      not ( // no payment > (weekly cost * 4) paid within last 4 weeks
         $deduction : AccountTransaction( // a recent transaction
            playerNumber == $playerNumber &&
            transactionDate >= fourWeeksAgo &&
            transactionCode == "D" // deduction
         )
         exists AccountTransaction( // the payment
            playerNumber == $playerNumber &&
            transactionDate >= fourWeeksAgo &&
            transactionCode == "P" // payment
            amountInPence >= ($deduction->amountInPence * 4)
         )
   )
   then
      // do some action to the account
end

問題は、機能しないことです。org.drools.rule.InvalidRulePackage例外がスローされ続けます。構文を推測しただけですが、私がやろうとしていることを示す例を見つけることができませんでした。可能ですか?


完全な元のエラーメッセージは次のとおりです。

"unknown:50:3 mismatched token: [@255,1690:1695='exists',<39>,50:3]; expecting type RIGHT_PAREN[54,4]: unknown:54:4 mismatched token: [@284,1840:1852='amountInPence',<7>,54:4]; expecting type RIGHT_PAREN[54,22]: unknown:54:22 Unexpected token '$payment'"

最初のコメントで提案を試みた後のエラーは次のとおりです。

"[50,3]: unknown:50:3 mismatched token: [@255,1690:1695='exists',<39>,50:3]; expecting type RIGHT_PAREN[54,4]: unknown:54:4 mismatched token: [@284,1840:1852='amountInPence',<7>,54:4]; expecting type RIGHT_PAREN[54,45]: unknown:54:45 mismatched token: [@293,1881:1881='*',<71>,54:45]; expecting type LEFT_PAREN[55,3]: unknown:55:3 mismatched token: [@298,1890:1890=')',<12>,55:3]; expecting type THEN"
役に立ちましたか?

解決

はい、あなたが推測したとおり、明示的な&quot; and&quot;を置く必要があります。 「ない」の内側それらを一緒に結合するパターン。

&quot; and&quot;が不要なのは、最上位にあります:

eg

when Foo() Bar()

&quot; and&quot;は不要です

ただし、これは暗黙的に同じです

when Foo() and Bar()

したがって、ソリューションは正しいようです。トップレベルの「および」の欠如ほとんどのルール言語では慣習のようです(CLIPSに戻ってください!)

他のヒント

次の点をさらにハッキングしても、実行時エラーは発生しません(まだ「正しい」かどうかはわかりませんが)。句を書き直して、両方のファクトの周囲に存在を配置し、中置詞を使用してグループ化しました。

  not ( // no payment > (weekly cost * 4) paid within last 4 weeks
     exists (
        AccountTransaction( // a recent transaction
           playerNumber == $playerNumber &&
           transactionDate >= fourWeeksAgo &&
           transactionCode == "D" // deduction
           $recentDeducation : amountInPence
        ) and
        AccountTransaction( // the payment
           playerNumber == $playerNumber &&
           transactionDate >= fourWeeksAgo &&
           transactionCode == "P" // payment
           amountInPence >= ($recentDeducation * 4)
        )
     )
  )

これまでのすべてのヘルプに感謝します。

($ deduction-&gt; amountInPence * 4)はどうですか? -&gt; である必要があります。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top