문제를 쓴 문제가있는 Drools / Jboss 규칙을 한 가지 사실과 일치시킨 다음 다른 사실이 존재하는지 여부를 결정하기 위해 그 사실을 사용합니다.

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"
도움이 되었습니까?

해결책

그렇습니다. 당신이 추측했듯이, 당신은 그것들을 함께하기 위해 명시 적 "과" "패턴이 아닌"패턴을 넣어야합니다.

"및"가 필요하지 않은 유일한 시간은 최상위 수준입니다.

예를 들어

when Foo() Bar()

"and"가 필요하지 않습니다.

그러나 이것은 암시 적으로 동일합니다

when Foo() and Bar()

따라서 솔루션이 정확해 보입니다. 최상위 레벨의 부족 "과"대부분의 규칙 언어에서 컨벤션 인 것 같습니다 (클립으로 돌아가십시오!)

다른 팁

다음과 관련하여 해킹을 한 후에는 런타임 오류가 발생하지 않습니다 (아직 "올바른"상태인지 확실하지는 않지만). 나는 사실을 둘 다 주위에 존재하고 디픽스를 사용하여 그룹화하기 위해 절을 다시 작성했습니다.

  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->amountInPence * 4)? 제 생각에는 -> a . 대신에.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top